Last_Insert_ID

------=_NextPart_000_000A_01C451FE.F6806850
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

Dear All,

I am working with an older version 3.23.54 of MySQL. I have a subroutine
like this:

sub c_new
{
my ($dbh, $params) = [at] _;
my $query = qq{INSERT INTO t_masts (f_site, f_name) VALUES
('$params->{f_site}', '$params->{f_name}')};
my $sth = $dbh->prepare(qq{$query});
$sth->execute();
$query = qq{SELECT LAST_INSERT_ID() from t_masts};
$sth = $dbh->prepare(qq{$query});
my $last_id = $sth->execute();
$sth->finish();
return $last_id;
}

Which returns the ID of the last record inserted into t_masts. Except that
after deleting record(s) from t_masts the subroutine returns the number of
records in t_masts (which is less than the ID of the record inserted and
it's that ID I want). My reading of the DuBois's book is that this should
work in version 3.23 upward.

Can anyone point out what I have missed?

Regards,
Scott


------=_NextPart_000_000A_01C451FE.F6806850--
Scott Simpson [ Mo, 14 Juni 2004 12:01 ] [ ID #44125 ]

Re: Last_Insert_ID

Any threads in use? Besides, what version of the driver are you using?


On Mo, 2004-06-14 at 12:01, Scott Simpson wrote:
> Dear All,
>
> I am working with an older version 3.23.54 of MySQL. I have a subroutine
> like this:
>
> sub c_new
> {
> my ($dbh, $params) = [at] _;
> my $query = qq{INSERT INTO t_masts (f_site, f_name) VALUES
> ('$params->{f_site}', '$params->{f_name}')};
> my $sth = $dbh->prepare(qq{$query});
> $sth->execute();
> $query = qq{SELECT LAST_INSERT_ID() from t_masts};
> $sth = $dbh->prepare(qq{$query});
> my $last_id = $sth->execute();
> $sth->finish();
> return $last_id;
> }
>
> Which returns the ID of the last record inserted into t_masts. Except that
> after deleting record(s) from t_masts the subroutine returns the number of
> records in t_masts (which is less than the ID of the record inserted and
> it's that ID I want). My reading of the DuBois's book is that this should
> work in version 3.23 upward.
>
> Can anyone point out what I have missed?
>
> Regards,
> Scott
>

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules [at] m .gmane.org
Jochen Wiedmann [ Mo, 14 Juni 2004 12:28 ] [ ID #44126 ]

Re: Last_Insert_ID

Any threads in use? Besides, what version of the driver are you using?


On Mo, 2004-06-14 at 12:01, Scott Simpson wrote:
> Dear All,
>
> I am working with an older version 3.23.54 of MySQL. I have a subroutine
> like this:
>
> sub c_new
> {
> my ($dbh, $params) = [at] _;
> my $query = qq{INSERT INTO t_masts (f_site, f_name) VALUES
> ('$params->{f_site}', '$params->{f_name}')};
> my $sth = $dbh->prepare(qq{$query});
> $sth->execute();
> $query = qq{SELECT LAST_INSERT_ID() from t_masts};
> $sth = $dbh->prepare(qq{$query});
> my $last_id = $sth->execute();
> $sth->finish();
> return $last_id;
> }
>
> Which returns the ID of the last record inserted into t_masts. Except that
> after deleting record(s) from t_masts the subroutine returns the number of
> records in t_masts (which is less than the ID of the record inserted and
> it's that ID I want). My reading of the DuBois's book is that this should
> work in version 3.23 upward.
>
> Can anyone point out what I have missed?
>
> Regards,
> Scott
>

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules [at] m .gmane.org
Jochen Wiedmann [ Mo, 14 Juni 2004 12:28 ] [ ID #180676 ]
Datenbanken » gmane.comp.db.mysql.perl » Last_Insert_ID

Vorheriges Thema: Subtracting times
Nächstes Thema: Last_Insert_ID