New DB2 Automagic primary key collecting
Jess Robinson [Sun, 8 Jan 2006 16:45:46 +0000 (16:45 +0000)]
lib/DBIx/Class/PK/Auto/DB2.pm [new file with mode: 0644]

diff --git a/lib/DBIx/Class/PK/Auto/DB2.pm b/lib/DBIx/Class/PK/Auto/DB2.pm
new file mode 100644 (file)
index 0000000..5c0b213
--- /dev/null
@@ -0,0 +1,22 @@
+package DBIx::Class::PK::Auto::DB2;
+
+use strict;
+use warnings;
+
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/PK::Auto/);
+
+sub last_insert_id
+{
+    my ($self) = @_;
+
+    my $dbh = $self->storage->dbh;
+    my $sth = $dbh->prepare_cached("VALUES(IDENTITY_VAL_LOCAL())");
+    $sth->execute();
+
+    my @res = $sth->fetchrow_array();
+
+    return @res ? $res[0] : undef;
+                         
+}