Skip to Content.
Sympa Menu

freetds - Re: Getting @@IDENTITY back from MSSQL

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Michael Peppler <mpeppler AT peppler.org>
  • To: "TDS Development Group" <freetds AT franklin.oit.unc.edu>
  • Subject: Re: Getting @@IDENTITY back from MSSQL
  • Date: Fri, 9 Nov 2001 10:21:10 -0800


Brian Bruns writes:
> Hi,
>
> I thought we had squished all the truncation bugs, can you try 0.53pre1
> (or CVS) and let me know if it shows up there as well?

I just tried the CVS version, and it works correctly against a Sybase
db (i.e. with TDS 5.0).

BTW - DBD::Sybase 0.93_x builds, but fails the tests because
ct_send_data() isn't defined... I thought I'd downloaded the latest
CVS version, though...

Michael


> > Hello,
> >
> > I am writing Perl (5.6.1) on a linux box (RH 7.1) with FreeTDS (0.51) and
> > DBI (1.19) to talk to a MSSQL server on a win2000 box. I want to get
> > @@IDENTITY from the last insert I made (@@IDENTITY contains that value of
> > the last autoincrement on a primary key).
> >
> > Here is test code I created:
> >
> > #!/usr/local/bin/perl -w
> > use DBI;
> > use strict;
> >
> > $ENV{'SYBASE'} = '/usr/local/freetds';
> > $ENV{'TDSVER'} = 70;
> >
> > my $server = "server";
> > my $db = "db";
> > my $user = "sqluser";
> > my $passwd = "sqluserpasswd";
> >
> > my $dbh =
> > DBI->connect("dbi:Sybase:server=$server;database=$db",$user,$passwd)
> > or die "--$!--\n";
> >
> > my $sth = $dbh->prepare(' insert into sctemp (scratch) values (42)
> > select @@IDENTITY as foo');
> > $sth->execute;
> >
> > my $data = $sth->fetchrow_hashref;
> > my $seqid= $$data{foo};
> > my $err = $sth->errstr;
> > print "$seqid, $err\n";
> >
> > The problem I have is that $seqid seems to be getting truncated, ie, the
> > value of @@IDENTITY is about 20, but the value of $seqid that gets
> > printed
> > out is 2. The query works fine as written in the Query Analyzer on
> > Windows. At this point, it feels like a problem with FreeTDS. In
> > addition to fetchrow_hashref, I tried fetch and fetchrow_array. Any
> > ideas?
> >
> > Thanks,
> > Scott
>
> ---
> You are currently subscribed to freetds as: [mpeppler AT peppler.org]
> To unsubscribe, forward this message to $subst('Email.Unsub')

--
Michael Peppler - Data Migrations Inc. - http://www.mbay.net/~mpeppler
mpeppler AT peppler.org - mpeppler AT mbay.net
International Sybase User Group - http://www.isug.com




Archive powered by MHonArc 2.6.24.

Top of Page