Added PK::Auto::MSSQL + test
Brian Cassidy [Tue, 9 Aug 2005 15:19:15 +0000 (15:19 +0000)]
lib/DBIx/Class/PK/Auto/MSSQL.pm [new file with mode: 0644]
t/14mssql.t [new file with mode: 0644]

diff --git a/lib/DBIx/Class/PK/Auto/MSSQL.pm b/lib/DBIx/Class/PK/Auto/MSSQL.pm
new file mode 100644 (file)
index 0000000..59877f1
--- /dev/null
@@ -0,0 +1,35 @@
+package DBIx::Class::PK::Auto::MSSQL;\r
+\r
+use strict;\r
+use warnings;\r
+\r
+use base qw/DBIx::Class/;\r
+\r
+__PACKAGE__->load_components(qw/PK::Auto/);\r
+\r
+sub last_insert_id {\r
+  my( $id ) = $_[0]->storage->dbh->selectrow_array( 'SELECT @@IDENTITY' );\r
+  return $id;\r
+}\r
+\r
+1;\r
+\r
+=head1 NAME \r
+\r
+DBIx::Class::PK::Auto::MSSQL - Automatic Primary Key class for MSSQL\r
+\r
+=head1 SYNOPSIS\r
+\r
+=head1 DESCRIPTION\r
+\r
+This class implements autoincrements for MSSQL.\r
+\r
+=head1 AUTHORS\r
+\r
+Brian Cassidy <bricas@cpan.org>\r
+\r
+=head1 LICENSE\r
+\r
+You may distribute this code under the same terms as Perl itself.\r
+\r
+=cut
\ No newline at end of file
diff --git a/t/14mssql.t b/t/14mssql.t
new file mode 100644 (file)
index 0000000..bd8e3e3
--- /dev/null
@@ -0,0 +1,30 @@
+use lib qw(lib t/lib);\r
+use DBICTest::Schema;\r
+\r
+use Test::More;\r
+\r
+my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/};\r
+\r
+#warn "$dsn $user $pass";\r
+\r
+plan skip_all, 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test'\r
+  unless ($dsn);\r
+\r
+plan tests => 1;\r
+\r
+DBICTest::Schema->compose_connection('MSSQLTest' => $dsn, $user, $pass);\r
+\r
+my $dbh = MSSQLTest::Artist->storage->dbh;\r
+\r
+$dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL\r
+    DROP TABLE artist");\r
+\r
+$dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(255));");\r
+\r
+MSSQLTest::Artist->load_components('PK::Auto::MSSQL');\r
+\r
+my $new = MSSQLTest::Artist->create({ name => 'foo' });\r
+\r
+ok($new->artistid, "Auto-PK worked");\r
+\r
+1;\r