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: =?iso-8859-1?Q?Pochet_Fr=E9d=E9ric?= <Frederic dot Pochet at cockerill-sambre dot com>
Subject: RE: SybPerl-DBlib question...
Date: Jan 27 1999 7:28AM

Try this:
	begin tran
	insert into table1 (fld2, fld3) values (value1, value2)
	if @@rowcount <> 1 ...	
	select @@identity
	...
	commit

	you will receive the value of the last insert  in a table with
an identity column.

	best regards

	F.Pochet

==========================================
Frederic Pochet
DBA DB Distribuees

Cockerill Sambre

*
Rue Vieille Fosse
B-4400 Flemalle
Belgium

*  +32 4 236 20 71
*   +32 4 236 21 00
*  frederic.pochet@cockerill-sambre.com
==========================================

> ----------
> From: 	Narasayya Immid[SMTP:narasan@yahoo.com]
> Reply To: 	SYBPERL-L@listproc.net
> Sent: 	mardi 26 janvier 1999 19:01
> To: 	SybPerl Discussion List
> Subject: 	SybPerl-DBlib question...
> 
> 
> 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
>