[help] select @@IDENTITY after INSERT
From: Xtrack (xtrack_at_myrealbox.com)
Date: 05/23/04
- Previous message: Eilon Uzi: "Dbi - problem in the installation on Solaris"
- Next in thread: Xtrack: "Re: RE: [help] select @@IDENTITY after INSERT"
- Maybe reply: Xtrack: "Re: RE: [help] select @@IDENTITY after INSERT"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 23 May 2004 14:08:19 +0200 To: dbi-users@perl.org
Hi to the list,
I am trying (as perl newbie) to fetch the returned value of a SELECT
@@IDENTITY; the database used is MSSSQL on Win2k Server.
The problem is that after the INSERT query i cannot get the returned
value correcly Any suggestion is welcome and appreciate.
thanks in advance.
----[ perl code follow
# perl started with #!/usr/bin/perl -w
# use DBI;
# use scrict;
# use other misc...
# dbh and other still created
# [...]
$query = $dbh->prepare("begin
INSERT INTO MAIL (DATEI, DATEM, SUB, OBJ, INV)
VALUES ('$today', '$date', $qsubject, $qbody, '$inv_ric');
SELECT \@\@IDENTITY; end ") or
die "Can't prepare the SQL statement: $DBI::errstr";
$query->execute() or die "Can't execute the SQL statement: $DBI::errstr";
my $row = $query->fetchrow_arrayref();
my $inserted_id = $row->[0];
print ("IDENTITY: $inserted_id\n");
my $list = $query->dump_results();
print $list;
----[ sample output follow
query = begin INSERT INTO MAIL (DATEI, DATEM, SUB, OBJ,
INV) VALUES ('4/23/104 13:58:43', '05/11/2004 11:56:51',
'test1
', 'ARRAY(0x84eb058)', '1'); SELECT @@IDENTITY; end
IDENTITY:
0 rows
0
-----[ sample SQL client transcript
SQL> INSERT INTO MAIL (DATEI, DATEM, SUB, OBJ, INV)
VALUES ('4/23/104 13:58:43', '05/11/2004 11:56:51', 'test1',
'ARRAY(0x84eb058)', '1'); SELECT @@IDENTITY;
query = INSERT INTO MAIL (DATEI, DATEM, SUB, OBJ,
INV) VALUES ('4/23/104 13:58:43', '05/11/2004 11:56:51',
'test1', 'ARRAY(0x84eb058)', '1'); SELECT @@IDENTITY;
+-----------+
| |
+-----------+
| 327 |
+-----------+
1 rows affected
SQL>
PS which is the appropriate function to fetch data from $qbody and
insert into query the data insted of ARRAY(0x....) ?
- Previous message: Eilon Uzi: "Dbi - problem in the installation on Solaris"
- Next in thread: Xtrack: "Re: RE: [help] select @@IDENTITY after INSERT"
- Maybe reply: Xtrack: "Re: RE: [help] select @@IDENTITY after INSERT"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|