> >> > Is there any way to programmatically figure out
> >> > if a field is AUTO_INCREMENT? I can do something
> >> > like:
> >> >
> >> > for ($x=0; $x < $sth->numfields; $x++) {
> >> > $colname = $sth->name->[$x];
> >> > $size = $sth->length->[$x];
> >> > $maxlen = $sth->length->[$x];
> >> > $type = $sth->type->[$x];
> >> > }
> >> >
> >> > But from what I can tell, 'type' is a INT and
> >> > there is no way to tell if it is AUTO_INCREMENT
> >> > or not?
> >> >
> >> > Does anyone know of a way to figure out if a
> >> > field is AUTO_INCREMENT?
> >> >
> >>
> >> Take a look at mysqlshow.c
>
> Jim> I did, and it looks like I have to re-query
> Jim> the database to figure out if the field
> Jim> is AUTO_INCREMENT or not ('show fields from
> Jim> SOME_TABLE_NAME') and then parse the resulting
> Jim> data, but I was hoping to get the info back
> Jim> somewhere in the meta-data from the original
> Jim> query and not have to re-query.
>
> Jim> Any thoughts?
>
> Hi!
>
> In C, you can check if a column is an auto_increment field by doing:
I'm a hacking in perl, any tips, hints or
clues as to how to get this data out of
Mysql.pm (not using DBD/DBI)?
I'm working on an object-relation layer
interface to Mysql and I need to automagically
figure out if a field is AUTO_INCREMENT.
It works like this on a table defined:
T_SOME_TABLE.ID - auto_increment
T_SOME_TALBE.SOME_CHAR - char
my $obj = new T_SOME_TABLE();
$obj->setSomeChar(12);
$obj->store; # does update/insert
Then I can do:
print $obj->getSomeChar; # a '12' shows up
print $obj->getId; # here is where I need to get
# the value that was auto_incremented
The ID field is incremented by Mysql, but then
I need to turn around and get the value that was
incremented so I can stuff it into some hash
and the "->getId' method can pull the value.
Once I can figure out if it is AUTO_INC then
I can get call LAST_VALUE [sic].
I've had this code working for a while, but I
used my own 'lock, select, increment, update,
unlock' logic to simulate AUTO_INC fields.
This eventually became a bottleneck which
was solved with the AUTO_INC field....
Jim
>
> MYSQL_FIELD *field
> ....
>
> if (field->flags & AUTO_INCREMENT_FLAG)
> {
> ...
> }
>
> Regards,
> Monty
>
> ---------------------------------------------------------------------
> Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
> posting. To request this thread, e-mail mysql-thread15502@stripped
>
> To unsubscribe, send a message to the address shown in the
> List-Unsubscribe header of this message. If you cannot see it,
> e-mail mysql-unsubscribe@stripped instead.