in reply to last_insert_id issue

The answer is in the documentation for the DBD::ODBC module.

last_insert_id

DBD::ODBC does not support DBI's last_insert_id. There is no ODBC defined way of obtaining this information. Generally the mechanism (and it differs vastly between databases and ODBC drivers) it to issue a select of some form (e.g., select @@identity or select sequence.currval from dual, etc).

There are literally dozens of databases and ODBC drivers supported by DBD::ODBC and I cannot have them all. If you know how to retrieve the information for last_insert_id and you mail me the ODBC Driver name/version and database name/version with a small working example I will collect examples and document them here.

Replies are listed 'Best First'.
Re^2: last_insert_id issue
by sowais (Sexton) on Aug 27, 2014 at 17:20 UTC

    Thanks, fishmonger! any suggestions of what else (funtion, etc) can be used to obtain the last ID? I am using the SELECT statement with the filename and temp_date scalars to obtain the ID but i am sure there must be a better way of getting that ID. Thanks!

      I have never used SQL Server so far, but after a bit of googling I found the related query.

      From stackoverflow.com:

      SELECT SCOPE_IDENTITY();

      From ASP docs:

      SELECT CAST(scope_identity() AS int)

      Hope this helps.

      Update:

      am using the SELECT statement with the filename and temp_date

      I would suggest you use something more unique, like big random int or long string composed of random chars. temp_date might not be precise enough in a higher traffic environment.