5 use DBIx::Class::Optional::Dependencies;
6 use DBIx::Class::Schema::Loader::Utils qw/warnings_exist_silent sigwarn_silencer/;
8 use File::Path 'rmtree';
9 use DBIx::Class::Schema::Loader 'make_schema_at';
12 # use this if you keep a copy of DBD::Sybase linked to FreeTDS somewhere else
14 if (my $lib_dirs = $ENV{DBICTEST_MSSQL_PERL5LIB}) {
15 unshift @INC, $_ for split /:/, $lib_dirs;
21 use dbixcsl_common_tests ();
22 use dbixcsl_test_dir '$tdir';
24 use constant EXTRA_DUMP_DIR => "$tdir/mssql_extra_dump";
26 # for extra tests cleanup
29 my (%dsns, $common_version);
31 for (qw/MSSQL MSSQL_ODBC MSSQL_ADO/) {
32 next unless $ENV{"DBICTEST_${_}_DSN"};
34 (my $dep_group = lc "rdbms_$_") =~ s/mssql$/mssql_sybase/;
35 if (!DBIx::Class::Optional::Dependencies->req_ok_for($dep_group)) {
36 diag 'You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for($dep_group)
41 $dsns{$_}{dsn} = $ENV{"DBICTEST_${_}_DSN"};
42 $dsns{$_}{user} = $ENV{"DBICTEST_${_}_USER"};
43 $dsns{$_}{password} = $ENV{"DBICTEST_${_}_PASS"};
46 my $dbh = DBI->connect (@{$dsns{$_}}{qw/dsn user password/}, { RaiseError => 1, PrintError => 0} );
50 $dbh->selectrow_hashref('master.dbo.xp_msver ProductVersion')->{Character_Value}
53 my ($maj_srv_ver) = $srv_ver =~ /^(\d+)/;
55 if (! defined $common_version or $common_version > $maj_srv_ver ) {
56 $common_version = $maj_srv_ver;
60 plan skip_all => 'You need to set the DBICTEST_MSSQL_DSN, _USER and _PASS and/or the DBICTEST_MSSQL_ODBC_DSN, _USER and _PASS environment variables'
63 my $mssql_2008_new_data_types = {
64 date => { data_type => 'date' },
65 time => { data_type => 'time' },
66 'time(0)'=> { data_type => 'time', size => 0 },
67 'time(1)'=> { data_type => 'time', size => 1 },
68 'time(2)'=> { data_type => 'time', size => 2 },
69 'time(3)'=> { data_type => 'time', size => 3 },
70 'time(4)'=> { data_type => 'time', size => 4 },
71 'time(5)'=> { data_type => 'time', size => 5 },
72 'time(6)'=> { data_type => 'time', size => 6 },
73 'time(7)'=> { data_type => 'time' },
74 datetimeoffset => { data_type => 'datetimeoffset' },
75 'datetimeoffset(0)' => { data_type => 'datetimeoffset', size => 0 },
76 'datetimeoffset(1)' => { data_type => 'datetimeoffset', size => 1 },
77 'datetimeoffset(2)' => { data_type => 'datetimeoffset', size => 2 },
78 'datetimeoffset(3)' => { data_type => 'datetimeoffset', size => 3 },
79 'datetimeoffset(4)' => { data_type => 'datetimeoffset', size => 4 },
80 'datetimeoffset(5)' => { data_type => 'datetimeoffset', size => 5 },
81 'datetimeoffset(6)' => { data_type => 'datetimeoffset', size => 6 },
82 'datetimeoffset(7)' => { data_type => 'datetimeoffset' },
83 datetime2 => { data_type => 'datetime2' },
84 'datetime2(0)' => { data_type => 'datetime2', size => 0 },
85 'datetime2(1)' => { data_type => 'datetime2', size => 1 },
86 'datetime2(2)' => { data_type => 'datetime2', size => 2 },
87 'datetime2(3)' => { data_type => 'datetime2', size => 3 },
88 'datetime2(4)' => { data_type => 'datetime2', size => 4 },
89 'datetime2(5)' => { data_type => 'datetime2', size => 5 },
90 'datetime2(6)' => { data_type => 'datetime2', size => 6 },
91 'datetime2(7)' => { data_type => 'datetime2' },
93 hierarchyid => { data_type => 'hierarchyid' },
96 my $tester = dbixcsl_common_tests->new(
98 auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY',
99 default_function_def => 'DATETIME DEFAULT getdate()',
100 connect_info => [ map { $dsns{$_} } sort keys %dsns ],
101 preserve_case_mode_is_exclusive => 1,
102 quote_char => [ qw/[ ]/ ],
103 basic_date_datatype => ($common_version >= 10) ? 'DATE' : 'SMALLDATETIME',
104 default_on_clause => 'NO ACTION',
106 # http://msdn.microsoft.com/en-us/library/ms187752.aspx
109 'int identity' => { data_type => 'integer', is_auto_increment => 1 },
110 bigint => { data_type => 'bigint' },
111 int => { data_type => 'integer' },
112 integer => { data_type => 'integer' },
113 smallint => { data_type => 'smallint' },
114 tinyint => { data_type => 'tinyint' },
115 money => { data_type => 'money' },
116 smallmoney => { data_type => 'smallmoney' },
117 bit => { data_type => 'bit' },
118 real => { data_type => 'real' },
119 'float(14)' => { data_type => 'real' },
120 'float(24)' => { data_type => 'real' },
121 'float(25)' => { data_type => 'double precision' },
122 'float(53)' => { data_type => 'double precision' },
123 float => { data_type => 'double precision' },
125 => { data_type => 'double precision' },
126 'numeric(6)' => { data_type => 'numeric', size => [6,0] },
127 'numeric(6,3)' => { data_type => 'numeric', size => [6,3] },
128 'decimal(6)' => { data_type => 'decimal', size => [6,0] },
129 'decimal(6,3)' => { data_type => 'decimal', size => [6,3] },
130 'dec(6,3)' => { data_type => 'decimal', size => [6,3] },
131 numeric => { data_type => 'numeric' },
132 decimal => { data_type => 'decimal' },
133 dec => { data_type => 'decimal' },
136 datetime => { data_type => 'datetime' },
137 # test rewriting getdate() to current_timestamp
138 'datetime default getdate()'
139 => { data_type => 'datetime', default_value => \'current_timestamp',
140 original => { default_value => \'getdate()' } },
141 smalldatetime => { data_type => 'smalldatetime' },
143 ($common_version >= 10) ? %$mssql_2008_new_data_types : (),
146 char => { data_type => 'char', size => 1 },
147 'char(2)' => { data_type => 'char', size => 2 },
148 character => { data_type => 'char', size => 1 },
149 'character(2)' => { data_type => 'char', size => 2 },
150 'varchar(2)' => { data_type => 'varchar', size => 2 },
152 nchar => { data_type => 'nchar', size => 1 },
153 'nchar(2)' => { data_type => 'nchar', size => 2 },
154 'nvarchar(2)' => { data_type => 'nvarchar', size => 2 },
157 'binary' => { data_type => 'binary', size => 1 },
158 'binary(2)' => { data_type => 'binary', size => 2 },
159 'varbinary(2)' => { data_type => 'varbinary', size => 2 },
162 'varchar(max)' => { data_type => 'text' },
163 text => { data_type => 'text' },
165 'nvarchar(max)' => { data_type => 'ntext' },
166 ntext => { data_type => 'ntext' },
168 'varbinary(max)' => { data_type => 'image' },
169 image => { data_type => 'image' },
172 timestamp => { data_type => 'timestamp', inflate_datetime => 0 },
173 rowversion => { data_type => 'rowversion' },
174 uniqueidentifier => { data_type => 'uniqueidentifier' },
175 sql_variant => { data_type => 'sql_variant' },
176 xml => { data_type => 'xml' },
181 CREATE TABLE [mssql_loader_test1.dot] (
182 id INT IDENTITY NOT NULL PRIMARY KEY,
187 CREATE TABLE mssql_loader_test3 (
188 id INT IDENTITY NOT NULL PRIMARY KEY
192 CREATE VIEW mssql_loader_test4 AS
193 SELECT * FROM mssql_loader_test3
195 # test capitalization of cols in unique constraints and rels
196 q{ SET QUOTED_IDENTIFIER ON },
197 q{ SET ANSI_NULLS ON },
199 CREATE TABLE [MSSQL_Loader_Test5] (
200 [Id] INT IDENTITY NOT NULL PRIMARY KEY,
201 [FooCol] INT NOT NULL,
202 [BarCol] INT NOT NULL,
203 UNIQUE ([FooCol], [BarCol])
207 CREATE TABLE [MSSQL_Loader_Test6] (
208 [Five_Id] INT REFERENCES [MSSQL_Loader_Test5] ([Id])
211 # 8 through 12 are used for the multi-schema tests and 13 through 16 are used for multi-db tests
213 create table mssql_loader_test17 (
214 id int identity primary key
218 create table mssql_loader_test18 (
219 id int identity primary key,
221 foreign key (seventeen_id) references mssql_loader_test17(id)
222 on delete set default on update set null
227 'CREATE TABLE mssql_loader_test3 (id INT IDENTITY NOT NULL PRIMARY KEY)',
228 'DROP VIEW mssql_loader_test4',
231 '[mssql_loader_test1.dot]',
232 'mssql_loader_test3',
233 'MSSQL_Loader_Test6',
234 'MSSQL_Loader_Test5',
235 'mssql_loader_test17',
236 'mssql_loader_test18',
238 count => 14 + 30 * 2 + 26 * 2, # extra + multi-schema + mutli-db
240 my ($monikers, $classes, $self);
241 ($schema, $monikers, $classes, $self) = @_;
243 my $connect_info = [@$self{qw/dsn user password/}];
245 # Test that the table above (with '.' in name) gets loaded correctly.
247 $schema->resultset('MssqlLoaderTest1Dot') }),
248 'got a resultset for table with dot in name');
250 ok((my $from = eval { $rs->result_source->from }),
251 'got an $rsrc->from for table with dot in name');
253 is ref($from), 'SCALAR', '->table with dot in name is a scalar ref';
255 is eval { $$from }, "[mssql_loader_test1.dot]",
256 '->table with dot in name has correct name';
258 # Test capitalization of columns and unique constraints
259 ok ((my $rsrc = $schema->resultset($monikers->{mssql_loader_test5})->result_source),
260 'got result_source');
262 if ($schema->loader->preserve_case) {
263 is_deeply [ $rsrc->columns ], [qw/Id FooCol BarCol/],
264 'column name case is preserved with case-sensitive collation';
266 my %uniqs = $rsrc->unique_constraints;
267 delete $uniqs{primary};
269 is_deeply ((values %uniqs)[0], [qw/FooCol BarCol/],
270 'column name case is preserved in unique constraint with case-sensitive collation');
273 is_deeply [ $rsrc->columns ], [qw/id foocol barcol/],
274 'column names are lowercased for case-insensitive collation';
276 my %uniqs = $rsrc->unique_constraints;
277 delete $uniqs{primary};
279 is_deeply ((values %uniqs)[0], [qw/foocol barcol/],
280 'columns in unique constraint lowercased for case-insensitive collation');
284 my $five_row = $schema->resultset($monikers->{mssql_loader_test5})->new_result({});
286 if ($schema->loader->preserve_case) {
287 $five_row->foo_col(1);
288 $five_row->bar_col(2);
291 $five_row->foocol(1);
292 $five_row->barcol(2);
296 my $six_row = $five_row->create_related('mssql_loader_test6s', {});
298 is $six_row->five->id, 1;
299 } 'relationships for mixed-case tables/columns detected';
301 # Test that a bad view (where underlying table is gone) is ignored.
302 my $dbh = $schema->storage->dbh;
303 $dbh->do("DROP TABLE mssql_loader_test3");
305 warnings_exist_silent { $schema->rescan }
306 qr/^Bad table or view 'mssql_loader_test4'/, 'bad view ignored';
309 $schema->resultset($monikers->{mssql_loader_test4})
310 } qr/Can't find source/,
311 'no source registered for bad view';
313 # test on delete/update fk clause introspection
314 ok ((my $rel_info = $schema->source('MssqlLoaderTest18')->relationship_info('seventeen')),
317 is $rel_info->{attrs}{on_delete}, 'SET DEFAULT',
318 'ON DELETE clause introspected correctly';
320 is $rel_info->{attrs}{on_update}, 'SET NULL',
321 'ON UPDATE clause introspected correctly';
323 is $rel_info->{attrs}{is_deferrable}, 1,
324 'is_deferrable defaults to 1';
327 my $dbh = $schema->storage->dbh;
330 $dbh->do('CREATE SCHEMA [dbicsl-test]');
333 skip "no CREATE SCHEMA privileges", 30 * 2;
337 CREATE TABLE [dbicsl-test].mssql_loader_test8 (
338 id INT IDENTITY PRIMARY KEY,
343 CREATE TABLE [dbicsl-test].mssql_loader_test9 (
344 id INT IDENTITY PRIMARY KEY,
346 eight_id INTEGER NOT NULL,
347 CONSTRAINT loader_test9_uniq UNIQUE (eight_id),
348 FOREIGN KEY (eight_id) REFERENCES [dbicsl-test].mssql_loader_test8 (id)
351 $dbh->do('CREATE SCHEMA [dbicsl.test]');
353 CREATE TABLE [dbicsl.test].mssql_loader_test9 (
354 pk INT IDENTITY PRIMARY KEY,
356 eight_id INTEGER NOT NULL,
357 CONSTRAINT loader_test9_uniq UNIQUE (eight_id),
358 FOREIGN KEY (eight_id) REFERENCES [dbicsl-test].mssql_loader_test8 (id)
362 CREATE TABLE [dbicsl.test].mssql_loader_test10 (
363 id INT IDENTITY PRIMARY KEY,
365 mssql_loader_test8_id INTEGER,
366 FOREIGN KEY (mssql_loader_test8_id) REFERENCES [dbicsl-test].mssql_loader_test8 (id)
370 CREATE TABLE [dbicsl.test].mssql_loader_test11 (
371 id INT IDENTITY PRIMARY KEY,
373 ten_id INTEGER NOT NULL UNIQUE,
374 FOREIGN KEY (ten_id) REFERENCES [dbicsl.test].mssql_loader_test10 (id)
378 CREATE TABLE [dbicsl-test].mssql_loader_test12 (
379 id INT IDENTITY PRIMARY KEY,
381 mssql_loader_test11_id INTEGER,
382 FOREIGN KEY (mssql_loader_test11_id) REFERENCES [dbicsl.test].mssql_loader_test11 (id)
386 my $guard = Scope::Guard->new(\&cleanup_schemas);
388 foreach my $db_schema (['dbicsl-test', 'dbicsl.test'], '%') {
390 rmtree EXTRA_DUMP_DIR;
393 local $SIG{__WARN__} = sub {
394 push @warns, $_[0] unless $_[0] =~ /\bcollides\b/;
401 db_schema => $db_schema,
402 dump_directory => EXTRA_DUMP_DIR,
408 diag join "\n", @warns if @warns;
411 } 'dumped schema for "dbicsl-test" and "dbicsl.test" schemas with no warnings';
413 my ($test_schema, $rsrc, $rs, $row, %uniqs, $rel_info);
416 ok $test_schema = MSSQLMultiSchema->connect(@$connect_info);
417 } 'connected test schema';
420 ok $rsrc = $test_schema->source('MssqlLoaderTest8');
421 } 'got source for table in schema name with dash';
423 is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
424 'column in schema name with dash';
426 is try { $rsrc->column_info('value')->{data_type} }, 'varchar',
427 'column in schema name with dash';
429 is try { $rsrc->column_info('value')->{size} }, 100,
430 'column in schema name with dash';
433 ok $rs = $test_schema->resultset('MssqlLoaderTest8');
434 } 'got resultset for table in schema name with dash';
437 ok $row = $rs->create({ value => 'foo' });
438 } 'executed SQL on table in schema name with dash';
440 $rel_info = try { $rsrc->relationship_info('dbicsl_dash_test_mssql_loader_test9') };
442 is_deeply $rel_info->{cond}, {
443 'foreign.eight_id' => 'self.id'
444 }, 'relationship in schema name with dash';
446 is $rel_info->{attrs}{accessor}, 'single',
447 'relationship in schema name with dash';
449 is $rel_info->{attrs}{join_type}, 'LEFT',
450 'relationship in schema name with dash';
453 ok $rsrc = $test_schema->source('DbicslDashTestMssqlLoaderTest9');
454 } 'got source for table in schema name with dash';
456 %uniqs = try { $rsrc->unique_constraints };
459 'got unique and primary constraint in schema name with dash';
461 delete $uniqs{primary};
463 is_deeply ((values %uniqs)[0], ['eight_id'],
464 'correct unique constraint in schema name with dash');
467 ok $rsrc = $test_schema->source('MssqlLoaderTest10');
468 } 'got source for table in schema name with dot';
470 is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
471 'column in schema name with dot introspected correctly';
473 is try { $rsrc->column_info('value')->{data_type} }, 'varchar',
474 'column in schema name with dot introspected correctly';
476 is try { $rsrc->column_info('value')->{size} }, 100,
477 'column in schema name with dot introspected correctly';
480 ok $rs = $test_schema->resultset('MssqlLoaderTest10');
481 } 'got resultset for table in schema name with dot';
484 ok $row = $rs->create({ value => 'foo' });
485 } 'executed SQL on table in schema name with dot';
487 $rel_info = try { $rsrc->relationship_info('mssql_loader_test11') };
489 is_deeply $rel_info->{cond}, {
490 'foreign.ten_id' => 'self.id'
491 }, 'relationship in schema name with dot';
493 is $rel_info->{attrs}{accessor}, 'single',
494 'relationship in schema name with dot';
496 is $rel_info->{attrs}{join_type}, 'LEFT',
497 'relationship in schema name with dot';
500 ok $rsrc = $test_schema->source('MssqlLoaderTest11');
501 } 'got source for table in schema name with dot';
503 %uniqs = try { $rsrc->unique_constraints };
506 'got unique and primary constraint in schema name with dot';
508 delete $uniqs{primary};
510 is_deeply ((values %uniqs)[0], ['ten_id'],
511 'correct unique constraint in schema name with dot');
514 ok $test_schema->source('MssqlLoaderTest10')
515 ->has_relationship('mssql_loader_test8');
516 } 'cross-schema relationship in multi-db_schema';
519 ok $test_schema->source('MssqlLoaderTest8')
520 ->has_relationship('mssql_loader_test10s');
521 } 'cross-schema relationship in multi-db_schema';
524 ok $test_schema->source('MssqlLoaderTest12')
525 ->has_relationship('mssql_loader_test11');
526 } 'cross-schema relationship in multi-db_schema';
529 ok $test_schema->source('MssqlLoaderTest11')
530 ->has_relationship('mssql_loader_test12s');
531 } 'cross-schema relationship in multi-db_schema';
537 local $SIG{__WARN__} = sigwarn_silencer(
538 qr/Changed database context/
541 my $dbh = $schema->storage->dbh;
544 $dbh->do('USE master');
545 $dbh->do('CREATE DATABASE dbicsl_test1');
548 diag "no CREATE DATABASE privileges: '$_'";
549 skip "no CREATE DATABASE privileges", 26 * 2;
552 $dbh->do('CREATE DATABASE dbicsl_test2');
554 $dbh->do('USE dbicsl_test1');
557 CREATE TABLE mssql_loader_test13 (
558 id INT IDENTITY PRIMARY KEY,
563 CREATE TABLE mssql_loader_test14 (
564 id INT IDENTITY PRIMARY KEY,
566 thirteen_id INTEGER REFERENCES mssql_loader_test13 (id),
567 CONSTRAINT loader_test14_uniq UNIQUE (thirteen_id)
571 $dbh->do('USE dbicsl_test2');
574 CREATE TABLE mssql_loader_test14 (
575 pk INT IDENTITY PRIMARY KEY,
578 CONSTRAINT loader_test14_uniq UNIQUE (thirteen_id)
583 CREATE TABLE mssql_loader_test15 (
584 id INT IDENTITY PRIMARY KEY,
589 CREATE TABLE mssql_loader_test16 (
590 id INT IDENTITY PRIMARY KEY,
592 fifteen_id INTEGER UNIQUE REFERENCES mssql_loader_test15 (id)
596 my $guard = Scope::Guard->new(\&cleanup_databases);
598 foreach my $db_schema ({ dbicsl_test1 => '%', dbicsl_test2 => '%' }, { '%' => '%' }) {
601 local $SIG{__WARN__} = sub {
602 push @warns, $_[0] unless $_[0] =~ /\bcollides\b/;
606 'MSSQLMultiDatabase',
609 db_schema => $db_schema,
610 dump_directory => EXTRA_DUMP_DIR,
616 diag join "\n", @warns if @warns;
619 } "dumped schema for databases 'dbicsl_test1' and 'dbicsl_test2' with no warnings";
624 ok $test_schema = MSSQLMultiDatabase->connect(@$connect_info);
625 } 'connected test schema';
627 my ($rsrc, $rs, $row, $rel_info, %uniqs);
630 ok $rsrc = $test_schema->source('MssqlLoaderTest13');
631 } 'got source for table in database one';
633 is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
634 'column in database one';
636 is try { $rsrc->column_info('value')->{data_type} }, 'varchar',
637 'column in database one';
639 is try { $rsrc->column_info('value')->{size} }, 100,
640 'column in database one';
643 ok $rs = $test_schema->resultset('MssqlLoaderTest13');
644 } 'got resultset for table in database one';
647 ok $row = $rs->create({ value => 'foo' });
648 } 'executed SQL on table in database one';
650 $rel_info = try { $rsrc->relationship_info('mssql_loader_test14') };
652 is_deeply $rel_info->{cond}, {
653 'foreign.thirteen_id' => 'self.id'
654 }, 'relationship in database one';
656 is $rel_info->{attrs}{accessor}, 'single',
657 'relationship in database one';
659 is $rel_info->{attrs}{join_type}, 'LEFT',
660 'relationship in database one';
663 ok $rsrc = $test_schema->source('DbicslTest1MssqlLoaderTest14');
664 } 'got source for table in database one';
666 %uniqs = try { $rsrc->unique_constraints };
669 'got unique and primary constraint in database one';
671 delete $uniqs{primary};
673 is_deeply ((values %uniqs)[0], ['thirteen_id'],
674 'correct unique constraint in database one');
677 ok $rsrc = $test_schema->source('MssqlLoaderTest15');
678 } 'got source for table in database two';
680 is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
681 'column in database two introspected correctly';
683 is try { $rsrc->column_info('value')->{data_type} }, 'varchar',
684 'column in database two introspected correctly';
686 is try { $rsrc->column_info('value')->{size} }, 100,
687 'column in database two introspected correctly';
690 ok $rs = $test_schema->resultset('MssqlLoaderTest15');
691 } 'got resultset for table in database two';
694 ok $row = $rs->create({ value => 'foo' });
695 } 'executed SQL on table in database two';
697 $rel_info = try { $rsrc->relationship_info('mssql_loader_test16') };
699 is_deeply $rel_info->{cond}, {
700 'foreign.fifteen_id' => 'self.id'
701 }, 'relationship in database two';
703 is $rel_info->{attrs}{accessor}, 'single',
704 'relationship in database two';
706 is $rel_info->{attrs}{join_type}, 'LEFT',
707 'relationship in database two';
710 ok $rsrc = $test_schema->source('MssqlLoaderTest16');
711 } 'got source for table in database two';
713 %uniqs = try { $rsrc->unique_constraints };
716 'got unique and primary constraint in database two';
718 delete $uniqs{primary};
720 is_deeply ((values %uniqs)[0], ['fifteen_id'],
721 'correct unique constraint in database two');
728 $tester->run_tests();
730 sub cleanup_schemas {
731 return if $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP};
733 # switch back to default database
734 $schema->storage->disconnect;
735 my $dbh = $schema->storage->dbh;
737 foreach my $table ('[dbicsl-test].mssql_loader_test12',
738 '[dbicsl.test].mssql_loader_test11',
739 '[dbicsl.test].mssql_loader_test10',
740 '[dbicsl.test].mssql_loader_test9',
741 '[dbicsl-test].mssql_loader_test9',
742 '[dbicsl-test].mssql_loader_test8') {
744 $dbh->do("DROP TABLE $table");
747 diag "Error dropping table: $_";
751 foreach my $db_schema (qw/dbicsl-test dbicsl.test/) {
753 $dbh->do(qq{DROP SCHEMA [$db_schema]});
756 diag "Error dropping test schema $db_schema: $_";
760 rmtree EXTRA_DUMP_DIR;
763 sub cleanup_databases {
764 return if $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP};
767 local $SIG{__WARN__} = sigwarn_silencer(
768 qr/Changed database context/
771 my $dbh = $schema->storage->dbh;
773 $dbh->do('USE dbicsl_test1');
775 foreach my $table ('mssql_loader_test14',
776 'mssql_loader_test13') {
778 $dbh->do("DROP TABLE $table");
781 diag "Error dropping table: $_";
785 $dbh->do('USE dbicsl_test2');
787 foreach my $table ('mssql_loader_test16',
788 'mssql_loader_test15',
789 'mssql_loader_test14') {
791 $dbh->do("DROP TABLE $table");
794 diag "Error dropping table: $_";
798 $dbh->do('USE master');
800 foreach my $database (qw/dbicsl_test1 dbicsl_test2/) {
802 $dbh->do(qq{DROP DATABASE $database});
805 diag "Error dropping test database '$database': $_";
809 rmtree EXTRA_DUMP_DIR;
811 # vim:et sts=4 sw=4 tw=0: