Gossamer Forum
Home : Products : Gossamer Links : Discussions :

How to get back the value of an auto_increment field

Quote Reply
How to get back the value of an auto_increment field
I added a global which inserts some data in a new table Transaktion

Code:
sub {
my $tags = shift;
my $db = $DB->table ('Transaktion');
my $sth = $db->insert ( {
TR_CustomerNo => $tags->{Kundennummer},
TR_CustomerRef => $tags->{BestNo},
TR_LinkID => $tags->{ID},
TR_Preis => $tags->{Preis} });
return "transaktion_insert: $sth ";
}
Now I want, that I get back the auto_incremet field in my table called TRNR. I thought like something with
Code:

$db->select ( LAST_INSERT_ID() );
but GLinks does not support that.
Thanks a lot for your help,
Christian

Quote Reply
Re: [cwschroeder] How to get back the value of an auto_increment field In reply to
Hi,

It depends on what your field name is. If its ID, it would be:

Code:
$db->select ( ['MAX(ID)'] )->fetchrow;

If its something else, it would be something like:

Code:
$db->select ( ['MAX(Field_Name)'] )->fetchrow;

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How to get back the value of an auto_increment field In reply to
Thanks a lot, thats it.

Christian
Quote Reply
Re: [cwschroeder] How to get back the value of an auto_increment field In reply to
Or just use the statement handle passed back from insert and use $sth->insert_id

Adrian

Last edited by:

brewt: Jan 13, 2008, 10:06 AM
Quote Reply
Re: [brewt] How to get back the value of an auto_increment field In reply to
Seems shorter, but it runs my query twice?