summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Cooper <J.L.Cooper@lboro.ac.uk>2020-09-16 08:45:12 +0100
committerJason Cooper <J.L.Cooper@lboro.ac.uk>2020-09-16 08:45:12 +0100
commitea3e7426d986f7d43206e8c2989e74910b444783 (patch)
treec4d6aa66551dd099c93cb14f688cd94e173503c5
parent93ba7fb65af9f8a9b5840715fa1096b86610722b (diff)
Added support for the `last_insert_id` method to DBD::st.
-rw-r--r--Changes1
-rw-r--r--lib/DBD/Mock/st.pm5
-rw-r--r--t/025_mock_last_insert_id.t43
3 files changed, 43 insertions, 6 deletions
diff --git a/Changes b/Changes
index a1b1809..7d71d3a 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
Revision history for Perl extension DBD::Mock.
{{$NEXT}}
+ - The DBD::st module now supports the last_insert_id method
1.55 2019-12-30T14:20:00Z
- Fixed bug rt131264 t/033_table_info.t fails (with older DBI)
diff --git a/lib/DBD/Mock/st.pm b/lib/DBD/Mock/st.pm
index 66d5468..bb2b20a 100644
--- a/lib/DBD/Mock/st.pm
+++ b/lib/DBD/Mock/st.pm
@@ -298,6 +298,11 @@ sub fetchall_hashref {
return $rethash;
}
+sub last_insert_id {
+ my ( $sth, @params ) = @_;
+ return $sth->{Database}->last_insert_id( @params );
+}
+
sub finish {
my ($sth) = @_;
$sth->FETCH('mock_my_history')->is_finished('yes');
diff --git a/t/025_mock_last_insert_id.t b/t/025_mock_last_insert_id.t
index 264bab6..10b398c 100644
--- a/t/025_mock_last_insert_id.t
+++ b/t/025_mock_last_insert_id.t
@@ -18,15 +18,31 @@ $dbh->{mock_start_insert_id} = ['Baz', 345];
$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 last_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" 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 last_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" 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 last_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" 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");
+ }
}
{
@@ -34,15 +50,30 @@ $dbh->{mock_start_insert_id} = ['Baz', 345];
$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 last_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" 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 last_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" 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 last_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" 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();