Michael:

WOW!  NEAT!  THANKS!!  That solved the problem.

Sincerely,
Andrew Powell

aap

Michael Peppler wrote:

> Andrew Powell writes:
>  > It appears that selecting @@IDENTITY returns only the first IDENTITY
>  > result for the database connection.  This is with SyBase 11.0.3.3, DBI
>  > 1.13 and DBD:Sybase 0.91.
>  >
>  > For example, I created a test table as such:
>  > create table test (id numeric(10,0) identity, blah char(10) null)
>  >
>  > And then ran a Perl script:
>  >
>  > ...
>  >   # connect to the database
>  >   $db = DBI->connect("dbi:Sybase:", $dbuser, $dbpass);
>  >
>  >   # test the first insertion
>  >   $qd = $db->prepare("insert into test (blah) values ('one')");
>  >   $qd->execute;
>
> Because you don't call fetch() the statement handle is left as
> "active". When you call prepare below DBD::Sybase opens a new
> connection for you (it can't tell that there are no rows to be fetched
> [well, maybe it could, but right now it doesn't]).
>
>  >   $qd = $db->prepare('select @@identity');
>  >   $qd->execute;
>  >   $row = $qd->fetchrow_arrayref;
>  >   print "Identity: $row->[0]\n";
>
> So what happens is that you are querying @@identity on different
> connections, which will always be 1.
>
> Try this:
>
> $qd = $db->prepare("insert into test (blah) values ('one')\nselect
>                      \@\@identity");
> $qd->execute;
> do {
>     while($d = $qd->fetch) {
>         print "Identity: $d->[0]\n";
>     }
> } while($qd->{syb_more_results});
>
> Michael
> --
> Michael Peppler - Data Migrations Inc. - [EMAIL PROTECTED]
> http://www.mbay.net/~mpeppler - [EMAIL PROTECTED]
> International Sybase User Group - http://www.isug.com
> Sybase on Linux mailing list: [EMAIL PROTECTED]

Reply via email to