freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
Re: Equivalent of mysql_insertid using FreeTDS/DBD::Sybase?
- From: Bob Kline <bkline AT rksystems.com>
- To: TDS Development Group <freetds AT franklin.metalab.unc.edu>
- Subject: Re: Equivalent of mysql_insertid using FreeTDS/DBD::Sybase?
- Date: Mon, 30 Sep 2002 19:23:22 -0400 (EDT)
On Mon, 30 Sep 2002, Richard Wolfe wrote:
> I am using FreeTDS/DBD::Sybase to let my CGI Perl script on a webserver make
> inserts into a MS SQL Server db running on a remote machine. Everything is
> up and running hunky-dory, no small thanks to the good folks of this forum
> for helping me install/configure everything. One issue though...
>
> One of the tables I'm inserting into has an auto-incrementing integer field
> that is its primary key. In the past (when accessing a MySQL db, my only
> real database experience), I'm used to doing something like this to get the
> value of that generated field when I make the insert:
>
> $SQL = "INSERT INTO mytable (name, address) VALUES('joe blow', '1234 main
> street')";
> $sth = $dbh->prepare($SQL);
> $rc = $sth->execute;
> $newid = $sth->{mysql_insertid};
> $sth->finish;
>
> ...where $newid returns the value of the auto-incrementing field.
> Is there an equivalent function in DBD::Sybase? The pod file says
> something about @@IDENTITY, but I can't get this to work. Am I on
> the right track?
Not really a freetds question.
Try this.
my $sql = "CREATE TABLE tident(id INTEGER IDENTITY, name VARCHAR(32))";
my $sth = $dbh->prepare($sql);
$sth->execute;
foreach $name ("Mary", "Joe", "Sally") {
$sth = $dbh->prepare("INSERT INTO tident(name) VALUES('$name')");
$sth->execute;
}
$sth = $dbh->prepare('SELECT @@IDENTITY');
$sth->execute;
my @results = $sth->fetchrow;
print $results[0] . "\n";
$sth = $dbh->prepare("DROP TABLE tident");
$sth->execute;
--
Bob Kline
mailto:bkline AT rksystems.com
http://www.rksystems.com
-
Equivalent of mysql_insertid using FreeTDS/DBD::Sybase?,
Richard Wolfe, 09/30/2002
- <Possible follow-up(s)>
- Re: Equivalent of mysql_insertid using FreeTDS/DBD::Sybase?, Bob Kline, 09/30/2002
Archive powered by MHonArc 2.6.24.