1 package dbixcsl_mssql_extra_tests;
19 CREATE TABLE [${vendor}_loader_test1.dot] (
20 id INT IDENTITY NOT NULL PRIMARY KEY,
25 CREATE TABLE ${vendor}_loader_test2 (
26 id INT IDENTITY NOT NULL PRIMARY KEY,
27 dat VARCHAR(100) DEFAULT 'foo',
28 num NUMERIC DEFAULT 10.89,
30 ts DATETIME DEFAULT getdate()
34 CREATE TABLE ${vendor}_loader_test3 (
35 id INT IDENTITY NOT NULL PRIMARY KEY
39 CREATE VIEW ${vendor}_loader_test4 AS
40 SELECT * FROM ${vendor}_loader_test3
44 "[${vendor}_loader_test1.dot]",
45 "${vendor}_loader_test2",
46 "${vendor}_loader_test3"
50 my ($schema, $monikers, $classes) = @_;
52 # Test that the table above (with '.' in name) gets loaded correctly.
53 my $vendor_titlecased = "\u\L$vendor";
56 $schema->resultset("${vendor_titlecased}LoaderTest1Dot") }),
57 'got a resultset for table with dot in name');
59 ok((my $from = eval { $rs->result_source->from }),
60 'got an $rsrc->from for table with dot in name');
62 is ref($from), 'SCALAR', '->table with dot in name is a scalar ref';
64 is eval { $$from }, "[${vendor}_loader_test1.dot]",
65 '->table with dot in name has correct name';
67 # Test that column defaults are set correctly
69 $schema->resultset("${vendor_titlecased}LoaderTest2") }),
70 'got a resultset for table with column with default value');
72 my $rsrc = $rs->result_source;
74 is eval { $rsrc->column_info('dat')->{default_value} }, 'foo',
75 'correct default_value for column with literal string default';
77 is eval { $rsrc->column_info('anint')->{default_value} }, 6,
78 'correct default_value for column with literal integer default';
80 cmp_ok eval { $rsrc->column_info('num')->{default_value} },
82 'correct default_value for column with literal numeric default';
84 ok((my $function_default =
85 eval { $rsrc->column_info('ts')->{default_value} }),
86 'got default_value for column with function default');
88 is ref($function_default), 'SCALAR',
89 'default_value for function default is a SCALAR ref';
91 is eval { $$function_default }, 'getdate()',
92 'default_value for function default is correct';
94 # Test that identity columns do not have 'identity' in the data_type, and do
95 # have is_auto_increment.
96 my $identity_col_info = $schema->resultset('LoaderTest10')
97 ->result_source->column_info('id10');
99 is $identity_col_info->{data_type}, 'int',
100 q{'INT IDENTITY' column has data_type => 'int'};
102 is $identity_col_info->{is_auto_increment}, 1,
103 q{'INT IDENTITY' column has is_auto_increment => 1};
105 # Test that a bad view (where underlying table is gone) is ignored.
106 $saved_dbh = $schema->storage->dbh;
107 $saved_dbh->do("DROP TABLE ${vendor}_loader_test3");
111 local $SIG{__WARN__} = sub { push @warnings, $_[0] };
114 ok ((grep /^Bad table or view '${vendor}_loader_test4'/, @warnings),
118 $schema->resultset("${vendor_titlecased}LoaderTest4")
119 } qr/Can't find source/,
120 'no source registered for bad view';
124 # Clean up the bad view, table will be cleaned up in drops
128 $saved_dbh->do($_) for (
129 "CREATE TABLE ${vendor}_loader_test3 (id INT IDENTITY NOT NULL PRIMARY KEY)",
130 "DROP VIEW ${vendor}_loader_test4"