PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Robert_Gorrebeeck at concentra dot com
Subject: Retrieving Identity Value of newly inserted row
Date: Jan 13 2006 4:47PM

All

I am having a hard time trying to retrieve my identity value from an 
insert statement.  I keep getting a 0 returned.  Here is an example of my 
code:

#insert a record into the note table
$sth=$dbh->prepare(qq{INSERT INTO note(note_typ, usr_id, note_hdln, 
crt_dt, urgnt_ind) VALUES (?, ?, ?, ?, ?)});

$sth->execute( "note example, "example", "Note", $date, $urgent_ind);
#check to make sure that there was not an error with the sql statement
if($sth->errstr())
{
           $logger->warn("ERROR -- ", $sth->errstr());
           die;
}

sth = $dbh->prepare( 'SELECT @@IDENTITY' );
$sth->execute;
my $row = $sth->fetchrow_arrayref;
my $inserted_id = $row->[0];

Is it a problem with the  '?' as placeholders - Is there a way to retrieve 
the identity value of a newly inserted row?  Any help would be 
appreciated.
Thanks

Robert Gorrebeeck
Concentra Online Services
972.725.6956
Robert_Gorrebeeck@concentra.com
****** CONFIDENTIALITY NOTICE ******
NOTICE: This e-mail message and all attachments transmitted with it may contain legally privileged and confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message from your system. Thank you.