Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Perl / DBI Library / July 2008



Tip: Looking for answers? Try searching our database.

Detecting auto-incrementing primary keys

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel Kasak - 30 Jun 2008 09:25 GMT
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
Greg Sabino Mullane - 30 Jun 2008 14:42 GMT
-----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-----
Daniel Kasak - 06 Jul 2008 03:09 GMT
Damned anti-spam server thinks I'm a spammer ...
... resending with my ISP's mail server.

See attached ...
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.