Hi all.
I'm looking for a *portable* way to detect auto-incrementing primary
keys. Is there one?
I'm using $dbh->primary_key_info to fetch details about column(s) that
are participating in primary keys, but this doesn't mention whether
they're auto-incrementing or not, and I must also know this.
I realise I can do $dbh->column_info to fetch info on columns, but:
a) Not all servers support this ( SQLite, which I have to support,
doesn't )
b) It's not very portable - each server seems to say something slightly
different.
Any ideas?
Thanks.
Dan
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
> I'm looking for a *portable* way to detect auto-incrementing primary
> keys. Is there one?
No - because there is no universal concept of an "auto-incrementing"
primary key. MySQL and SQLite have a specific column modifier
called AUTOINCREMENT. Postgres uses sequences and a default value.
Oracle uses sequences and a trigger. And so on. Perhaps if you explain
what exactly you are trying to do, another solution (such as
$dbh->last_insert_id() perhaps?) may present itself.
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200806300940
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
C.J. Adams-Collier - 30 Jun 2008 20:42 GMT
I expect he was looking for an abstraction around the concept of
auto-increment primary key / sequence, etc.
Dan,
As Greg mentioned, since 1.38, DBI has specified a C<last_insert_id>
method. The docs recommend caution when using this method, however,
since its operation may or may not be defined depending on which DBD
driver used.
http://search.cpan.org/~timb/DBI-1.605/DBI.pm#last_insert_id
Which driver(s) do you intend to use?
Cheers,
C.J.
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: RIPEMD160
[quoted text clipped - 19 lines]
> =DhL1
> -----END PGP SIGNATURE-----
Damned anti-spam server thinks I'm a spammer ...
... resending with my ISP's mail server.
See attached ...