1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
use 5.008;
use strict;
use warnings;
use Test::More;
use DBI;
my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
|| die "Cannot create handle: $DBI::errstr\n";
$dbh->{mock_start_insert_id} = ['Foo', 123];
$dbh->{mock_start_insert_id} = ['Baz', 345];
{
my $sth = $dbh->prepare('INSERT INTO Foo (foo, bar) values (?, ?)');
$sth->execute(15, 17);
is($dbh->{mock_last_insert_id}, 123, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 123, "... got the right insert id from the database's last_insert_id");
SKIP: {
skip "Version of DBI::st doesn't support last_insert_id", 1 unless $sth->can('last_insert_id');
is($sth->last_insert_id((undef)x4), 123, "... got the right insert id from the statement handle's last_insert_id");
}
$sth->execute(16, 18);
is($dbh->{mock_last_insert_id}, 124, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 124, "... got the right insert id from the database handle's last_insert_id");
SKIP: {
skip "Version of DBI::st doesn't support last_insert_id", 1 unless $sth->can('last_insert_id');
is($sth->last_insert_id((undef)x4), 124, "... got the right insert id from the statement handle's last_insert_id");
}
$sth->execute(19, 34);
is($dbh->{mock_last_insert_id}, 125, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 125, "... got the right insert id from the database handle's last_insert_id");
SKIP: {
skip "Version of DBI::st doesn't support last_insert_id", 1 unless $sth->can('last_insert_id');
is($sth->last_insert_id((undef)x4), 125, "... got the right insert id from the statement handle's last_insert_id");
}
}
{
my $sth = $dbh->prepare('INSERT IGNORE INTO Baz (foo, bar) values (?, ?)');
$sth->execute(90, 41);
is($dbh->{mock_last_insert_id}, 345, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 345, "... got the right insert id from the database handle's last_insert_id");
SKIP: {
skip "Version of DBI::st doesn't support last_insert_id", 1 unless $sth->can('last_insert_id');
is($sth->last_insert_id((undef)x4), 345, "... got the right insert id from the statement handle's last_insert_id");
}
$sth->execute(32, 71);
is($dbh->{mock_last_insert_id}, 346, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 346, "... got the right insert id from the database handle's last_insert_id");
SKIP: {
skip "Version of DBI::st doesn't support last_insert_id", 1 unless $sth->can('last_insert_id');
is($sth->last_insert_id((undef)x4), 346, "... got the right insert id from the statement handle's last_insert_id");
}
$sth->execute(77, 42);
is($dbh->{mock_last_insert_id}, 347, '... got the right insert id');
is($dbh->last_insert_id((undef)x4), 347, "... got the right insert id from the database handle's last_insert_id");
SKIP: {
skip "Version of DBI::st doesn't support last_insert_id", 1 unless $sth->can('last_insert_id');
is($sth->last_insert_id((undef)x4), 347, "... got the right insert id from the statement handle's last_insert_id");
}
}
done_testing();
|