6 # use this if you keep a copy of DBD::Sybase linked to FreeTDS somewhere else
8 if (my $lib_dirs = $ENV{DBICTEST_MSSQL_PERL5LIB}) {
9 unshift @INC, $_ for split /:/, $lib_dirs;
14 use dbixcsl_common_tests;
16 my $dbd_sybase_dsn = $ENV{DBICTEST_MSSQL_DSN} || '';
17 my $dbd_sybase_user = $ENV{DBICTEST_MSSQL_USER} || '';
18 my $dbd_sybase_password = $ENV{DBICTEST_MSSQL_PASS} || '';
20 my $odbc_dsn = $ENV{DBICTEST_MSSQL_ODBC_DSN} || '';
21 my $odbc_user = $ENV{DBICTEST_MSSQL_ODBC_USER} || '';
22 my $odbc_password = $ENV{DBICTEST_MSSQL_ODBC_PASS} || '';
24 my $tester = dbixcsl_common_tests->new(
26 auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY',
27 default_function => 'getdate()',
28 default_function_def => 'DATETIME DEFAULT getdate()',
29 connect_info => [ ($dbd_sybase_dsn ? {
30 dsn => $dbd_sybase_dsn,
31 user => $dbd_sybase_user,
32 password => $dbd_sybase_password,
37 password => $odbc_password,
41 'int identity' => { data_type => 'int', is_auto_increment => 1 },
46 CREATE TABLE [mssql_loader_test1.dot] (
47 id INT IDENTITY NOT NULL PRIMARY KEY,
52 CREATE TABLE mssql_loader_test3 (
53 id INT IDENTITY NOT NULL PRIMARY KEY
57 CREATE VIEW mssql_loader_test4 AS
58 SELECT * FROM mssql_loader_test3
60 # test capitalization of cols in unique constraints and rels
61 q{ SET QUOTED_IDENTIFIER ON },
62 q{ SET ANSI_NULLS ON },
64 CREATE TABLE [MSSQL_Loader_Test5] (
65 [Id] INT IDENTITY NOT NULL PRIMARY KEY,
66 [FooCol] INT NOT NULL,
67 [BarCol] INT NOT NULL,
68 UNIQUE ([FooCol], [BarCol])
72 CREATE TABLE [MSSQL_Loader_Test6] (
73 [Five_Id] INT REFERENCES [MSSQL_Loader_Test5] ([Id])
78 'CREATE TABLE mssql_loader_test3 (id INT IDENTITY NOT NULL PRIMARY KEY)',
79 'DROP VIEW mssql_loader_test4',
82 '[mssql_loader_test1.dot]',
89 my ($schema, $monikers, $classes) = @_;
91 # Test that the table above (with '.' in name) gets loaded correctly.
93 $schema->resultset($monikers->{'[mssql_loader_test1.dot]'}) }),
94 'got a resultset for table with dot in name');
96 ok((my $from = eval { $rs->result_source->from }),
97 'got an $rsrc->from for table with dot in name');
99 is ref($from), 'SCALAR', '->table with dot in name is a scalar ref';
101 is eval { $$from }, "[mssql_loader_test1.dot]",
102 '->table with dot in name has correct name';
104 # Test capitalization of columns and unique constraints
105 ok ((my $rsrc = $schema->resultset($monikers->{mssql_loader_test5})->result_source),
106 'got result_source');
109 # is $rsrc->name, 'mssql_loader_test5',
110 # 'table name is lowercased';
112 is_deeply [ $rsrc->columns ], [qw/id foocol barcol/],
113 'column names are lowercased';
115 my %uniqs = $rsrc->unique_constraints;
116 delete $uniqs{primary};
118 is_deeply ((values %uniqs)[0], [qw/foocol barcol/],
119 'columns in unique constraint lowercased');
122 my $five_row = $schema->resultset($monikers->{mssql_loader_test5})->create({ foocol => 1, barcol => 2 });
123 my $six_row = $five_row->create_related('mssql_loader_test6s', {});
125 is $six_row->five->id, 1;
126 } 'relationships for mixed-case tables/columns detected';
128 # Test that a bad view (where underlying table is gone) is ignored.
129 my $dbh = $schema->storage->dbh;
130 $dbh->do("DROP TABLE mssql_loader_test3");
134 local $SIG{__WARN__} = sub { push @warnings, $_[0] };
137 ok ((grep /^Bad table or view 'mssql_loader_test4'/, @warnings),
141 $schema->resultset($monikers->{mssql_loader_test4})
142 } qr/Can't find source/,
143 'no source registered for bad view';
148 if(not ($dbd_sybase_dsn || $odbc_dsn)) {
149 $tester->skip_tests('You need to set the DBICTEST_MSSQL_DSN, _USER and _PASS and/or the DBICTEST_MSSQL_ODBC_DSN, _USER and _PASS environment variables');
152 $tester->run_tests();