From: Brian Cassidy Date: Tue, 9 Aug 2005 15:19:15 +0000 (+0000) Subject: Added PK::Auto::MSSQL + test X-Git-Tag: v0.03001~44 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b8566d6672a37412d86e07cdb545289e9285f904;p=dbsrgits%2FDBIx-Class.git Added PK::Auto::MSSQL + test --- diff --git a/lib/DBIx/Class/PK/Auto/MSSQL.pm b/lib/DBIx/Class/PK/Auto/MSSQL.pm new file mode 100644 index 0000000..59877f1 --- /dev/null +++ b/lib/DBIx/Class/PK/Auto/MSSQL.pm @@ -0,0 +1,35 @@ +package DBIx::Class::PK::Auto::MSSQL; + +use strict; +use warnings; + +use base qw/DBIx::Class/; + +__PACKAGE__->load_components(qw/PK::Auto/); + +sub last_insert_id { + my( $id ) = $_[0]->storage->dbh->selectrow_array( 'SELECT @@IDENTITY' ); + return $id; +} + +1; + +=head1 NAME + +DBIx::Class::PK::Auto::MSSQL - Automatic Primary Key class for MSSQL + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +This class implements autoincrements for MSSQL. + +=head1 AUTHORS + +Brian Cassidy + +=head1 LICENSE + +You may distribute this code under the same terms as Perl itself. + +=cut \ No newline at end of file diff --git a/t/14mssql.t b/t/14mssql.t new file mode 100644 index 0000000..bd8e3e3 --- /dev/null +++ b/t/14mssql.t @@ -0,0 +1,30 @@ +use lib qw(lib t/lib); +use DBICTest::Schema; + +use Test::More; + +my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/}; + +#warn "$dsn $user $pass"; + +plan skip_all, 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test' + unless ($dsn); + +plan tests => 1; + +DBICTest::Schema->compose_connection('MSSQLTest' => $dsn, $user, $pass); + +my $dbh = MSSQLTest::Artist->storage->dbh; + +$dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL + DROP TABLE artist"); + +$dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(255));"); + +MSSQLTest::Artist->load_components('PK::Auto::MSSQL'); + +my $new = MSSQLTest::Artist->create({ name => 'foo' }); + +ok($new->artistid, "Auto-PK worked"); + +1;