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: Narasayya Immid <narasan at yahoo dot com>
Subject: SybPerl-DBlib question...
Date: Jan 26 1999 6:01PM

I am using SybPerl-DBlib. I was trying to insert a record into a table
and get the latest generated key from the database. Any help is
greatly appreciated.

- Thanks in advance.
-----------------------------------------------------
In this scenario, I was trying to insert a record into "table1" and
"fld1" is the identity column for this table.
Table table1 structure:
create table1
( fld1 int identity,
  fld2 varchar(10),
  fld3 varchar(10)
)

   
$dbh= Sybase::DBlib->dblogin("user","pwd","SYBSERVER");
 $dbh->dbuse("dbname");
 $dbh->dbcmd("begin tran \n
              insert into table1(fld2,fld3)
              values ('xx','yy') \n
              if(\@\@rowcount != 1)
              begin
                 rollback transaction
              end \n
              commit tran \n
              select fld1 = max(fld1) from table1 \n
              ");
   $dbh->dbsqlexec;
   $dbh->dbresults;
   $ret_status = $dbh->DBCOUNT ;
   print "ret status: $ret_status \n";
   while(%dbdata=$dbh->dbnextrow(1))
   {
      print "fld1: $dbdata{fld1} \n";
   }
   $dbh->dbclose();

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com