Commit 81a05023 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

mysql and sqlite driver last insert id

parent b28d4c5e
......@@ -130,6 +130,28 @@ sub _new_request {
}
sub last_insert_id {
my $driver = $CONNECTOR->dbh->{Driver}->{Name};
if ( $driver =~ /sqlite/i ) {
return _last_insert_id_sqlite(@_);
} elsif ( $driver =~ /mysql/i ) {
return _last_insert_id_mysql(@_);
} else {
confess "I don't know how to get last_insert_id for $driver";
}
}
sub _last_insert_id_mysql {
my $self = shift;
my $sth = $CONNECTOR->dbh->prepare("SELECT last_insert_id()");
$sth->execute;
my ($id) = $sth->fetchrow;
$sth->finish;
return $id;
}
sub _last_insert_id_sqlite {
my $self = shift;
my $sth = $CONNECTOR->dbh->prepare("SELECT last_insert_rowid()");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment