From: Rafael Kitover Date: Sun, 23 Aug 2009 07:37:54 +0000 (+0000) Subject: put extra mssql tests in the proper format X-Git-Tag: 0.04999_08~2^2~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b1e43108db28b5a04a41dc5d2565ca2feb1a5e16;p=dbsrgits%2FDBIx-Class-Schema-Loader.git put extra mssql tests in the proper format --- diff --git a/Makefile.PL b/Makefile.PL index f061211..71460bc 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -22,7 +22,7 @@ requires 'Class::C3' => '0.18'; requires 'Class::C3::Componentised' => '1.0005'; requires 'Carp::Clan' => 0; requires 'Class::Inspector' => 0; -requires 'DBIx::Class' => '0.07006'; +requires 'DBIx::Class' => '0.08109'; requires 'Class::Unload' => 0; install_script 'script/dbicdump'; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm b/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm index 7b3ec3d..abf2b59 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm @@ -46,7 +46,8 @@ sub _rebless { my $dbh = $self->schema->storage->dbh; my $DBMS_VERSION = @{$dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2]; if ($DBMS_VERSION =~ /^Microsoft /i) { - my $subclass = 'DBIx::Class::Schema::Loader::DBI::MSSQL'; + $DBMS_VERSION =~ s/\s/_/g; + my $subclass = "DBIx::Class::Schema::Loader::DBI::Sybase::$DBMS_VERSION"; if ($self->load_optional_class($subclass) && !$self->isa($subclass)) { bless $self, $subclass; $self->_rebless; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Microsoft_SQL_Server.pm new file mode 100644 index 0000000..40803af --- /dev/null +++ b/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Microsoft_SQL_Server.pm @@ -0,0 +1,49 @@ +package DBIx::Class::Schema::Loader::DBI::Sybase::Microsoft_SQL_Server; + +use strict; +use warnings; +use base 'DBIx::Class::Schema::Loader::DBI::MSSQL'; +use Carp::Clan qw/^DBIx::Class/; +use Class::C3; + +our $VERSION = '0.04999_06'; + +=head1 NAME + +DBIx::Class::Schema::Loader::DBI::Sybase::Microsoft_SQL_Server - Subclass for +using MSSQL through DBD::Sybase + +=head1 DESCRIPTION + +See L. + +Subclasses L. + +=cut + +# Returns an array of table names +sub _tables_list { + my $self = shift; + + my ($table, $type) = @_ ? @_ : ('%', '%'); + + my $dbh = $self->schema->storage->dbh; + my @tables = $dbh->tables(undef, $self->db_schema, $table, $type); + + return @tables; +} + +=head1 SEE ALSO + +L, +L, +L +L, L, + +=head1 AUTHOR + +Rafael Kitover + +=cut + +1; diff --git a/t/16mssql_common.t b/t/16mssql_common.t index 9cafbe5..2b59b07 100644 --- a/t/16mssql_common.t +++ b/t/16mssql_common.t @@ -10,17 +10,19 @@ BEGIN { use lib qw(t/lib); use dbixcsl_common_tests; +use dbixcsl_mssql_extra_tests; my $dsn = $ENV{DBICTEST_MSSQL_DSN} || ''; my $user = $ENV{DBICTEST_MSSQL_USER} || ''; my $password = $ENV{DBICTEST_MSSQL_PASS} || ''; my $tester = dbixcsl_common_tests->new( - vendor => 'Microsoft', + vendor => 'mssql', auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY', dsn => $dsn, user => $user, password => $password, + extra => dbixcsl_mssql_extra_tests->extra, ); if( !$dsn || !$user ) { diff --git a/t/16mssql_odbc_common.t b/t/16mssql_odbc_common.t index fdf1888..0e2e44c 100644 --- a/t/16mssql_odbc_common.t +++ b/t/16mssql_odbc_common.t @@ -1,17 +1,19 @@ use strict; use lib qw(t/lib); use dbixcsl_common_tests; +use dbixcsl_mssql_extra_tests; my $dsn = $ENV{DBICTEST_MSSQL_ODBC_DSN} || ''; my $user = $ENV{DBICTEST_MSSQL_ODBC_USER} || ''; my $password = $ENV{DBICTEST_MSSQL_ODBC_PASS} || ''; my $tester = dbixcsl_common_tests->new( - vendor => 'Microsoft', + vendor => 'mssql', auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY', dsn => $dsn, user => $user, password => $password, + extra => dbixcsl_mssql_extra_tests->extra, ); if( !$dsn || !$user ) { diff --git a/t/17mssql_dot_in_table_name.t b/t/17mssql_dot_in_table_name.t deleted file mode 100644 index ab9f435..0000000 --- a/t/17mssql_dot_in_table_name.t +++ /dev/null @@ -1,86 +0,0 @@ -use strict; -use lib qw(t/lib); -use Test::More; -use DBI; - -my $DUMP_DIR; -BEGIN { - $DUMP_DIR = './t/_common_dump'; -} - -use lib $DUMP_DIR; -use DBIx::Class::Schema::Loader 'make_schema_at', "dump_to_dir:$DUMP_DIR"; -use File::Path; - -my $dsn = $ENV{DBICTEST_MSSQL_ODBC_DSN} || - $ENV{DBICTEST_MSSQL_DSN} || ''; - -my $user = $ENV{DBICTEST_MSSQL_ODBC_USER} || - $ENV{DBICTEST_MSSQL_USER} || ''; - -my $password = $ENV{DBICTEST_MSSQL_ODBC_PASS} || - $ENV{DBICTEST_MSSQL_PASS} || ''; - -if( !$dsn || !$user ) { - plan skip_all => -'You need to set the DBICTEST_MSSQL_ODBC_DSN (or DBICTEST_MSSQL_DSN), _USER,' . -' and _PASS environment variables'; - exit; -} - -plan tests => 3; - -my $dbh = DBI->connect($dsn, $user, $password, { - RaiseError => 1, PrintError => 0 -}); - -eval { $dbh->do('DROP TABLE [loadertest.dot]') }; -$dbh->do(q{ - CREATE TABLE [loadertest.dot] ( - id INT IDENTITY NOT NULL PRIMARY KEY, - dat VARCHAR(8) - ) -}); - -rmtree $DUMP_DIR; - -eval { - make_schema_at( - 'TestSL::Schema', - { - use_namespaces => 1, - constraint => qr/^loadertest\.dot\z/ - }, - [ $dsn, $user, $password, ] - ); -}; - -ok !$@, 'table name with . parsed correctly'; -diag $@ if $@; - -#system qq{$^X -pi -e 's/"test\.dot"/\\\\"[loadertest.dot]"/' t/_common_dump/TestSL/Schema/Result/TestDot.pm}; -#diag do { local ($/, @ARGV) = (undef, "t/_common_dump/TestSL/Schema/Result/TestDot.pm"); <> }; -#do "t/_common_dump/TestSL/Schema/Result/TestDot.pm"; - -eval 'use TestSL::Schema'; -ok !$@, 'loaded schema'; -diag $@ if $@; - -TODO: { - local $TODO = q{this is really a DBIC test to check if the table is usable, -and it doesn't work in the released version yet}; - - eval { - my $rs = TestSL::Schema->resultset('LoadertestDot'); - my $row = $rs->create({ dat => 'foo' }); - $row->update({ dat => 'bar' }); - $row = $rs->find($row->id); - $row->delete; - }; - ok !$@, 'used table from DBIC succeessfully'; - diag $@ if $@; -} - -rmtree $DUMP_DIR; - -$dbh->do('DROP TABLE [loadertest.dot]'); diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 00ced93..159d4e5 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -75,7 +75,8 @@ sub setup_schema { my $debug = ($self->{verbose} > 1) ? 1 : 0; my %loader_opts = ( - constraint => qr/^(?:\S+\.)?(?:$self->{vendor}_)?loader_test[0-9]+s?$/i, + constraint => + qr/^(?:\S+\.)?(?:$self->{vendor}_)?loader_test[0-9]+(?!.*_)/i, relationships => 1, additional_classes => 'TestAdditional', additional_base_classes => 'TestAdditionalBase', diff --git a/t/lib/dbixcsl_mssql_extra_tests.pm b/t/lib/dbixcsl_mssql_extra_tests.pm new file mode 100644 index 0000000..587d77d --- /dev/null +++ b/t/lib/dbixcsl_mssql_extra_tests.pm @@ -0,0 +1,32 @@ +package dbixcsl_mssql_extra_tests; + +use Test::More; + +sub extra { +{ + create => [ + qq{ + CREATE TABLE [mssql_loader_test1.dot] ( + id INT IDENTITY NOT NULL PRIMARY KEY, + dat VARCHAR(8) + ) + }, + ], + drop => [ qw/ [mssql_loader_test1.dot] / ], + count => 4, + run => sub { + my ($schema, $monikers, $classes) = @_; + + ok((my $rs = eval { $schema->resultset('MssqlLoaderTest1Dot') }), + 'got a resultset'); + + ok((my $from = eval { $rs->result_source->from }), + 'got an $rsrc->from'); + + is ref($from), 'SCALAR', '->table is a scalar ref'; + + is eval { $$from }, '[mssql_loader_test1.dot]', + '->table name is correct'; + }, +}} + +1;