6 use File::Path 'rmtree';
7 use DBIx::Class::Schema::Loader 'make_schema_at';
11 use dbixcsl_common_tests ();
12 use dbixcsl_test_dir '$tdir';
14 use constant EXTRA_DUMP_DIR => "$tdir/informix_extra_dump";
16 # to support " quoted identifiers
17 BEGIN { $ENV{DELIMIDENT} = 'y' }
19 # This test doesn't run over a shared memory connection, because of the single connection limit.
21 my $dsn = $ENV{DBICTEST_INFORMIX_DSN} || '';
22 my $user = $ENV{DBICTEST_INFORMIX_USER} || '';
23 my $password = $ENV{DBICTEST_INFORMIX_PASS} || '';
25 my ($schema, $extra_schema); # for cleanup in END for extra tests
27 my $tester = dbixcsl_common_tests->new(
29 auto_inc_pk => 'serial primary key',
31 default_function => 'current year to fraction(5)',
32 default_function_def => 'datetime year to fraction(5) default current year to fraction(5)',
35 password => $password,
36 loader_options => { preserve_case => 1 },
39 # http://publib.boulder.ibm.com/infocenter/idshelp/v115/index.jsp?topic=/com.ibm.sqlr.doc/ids_sqr_094.htm
42 'int' => { data_type => 'integer' },
43 integer => { data_type => 'integer' },
44 int8 => { data_type => 'bigint' },
45 bigint => { data_type => 'bigint' },
46 serial => { data_type => 'integer', is_auto_increment => 1 },
47 bigserial => { data_type => 'bigint', is_auto_increment => 1 },
48 serial8 => { data_type => 'bigint', is_auto_increment => 1 },
49 smallint => { data_type => 'smallint' },
50 real => { data_type => 'real' },
51 smallfloat => { data_type => 'real' },
52 # just 'double' is a syntax error
53 'double precision' => { data_type => 'double precision' },
54 float => { data_type => 'double precision' },
55 'float(1)' => { data_type => 'double precision' },
56 'float(5)' => { data_type => 'double precision' },
57 'float(10)' => { data_type => 'double precision' },
58 'float(15)' => { data_type => 'double precision' },
59 'float(16)' => { data_type => 'double precision' },
60 numeric => { data_type => 'numeric' },
61 decimal => { data_type => 'numeric' },
62 dec => { data_type => 'numeric' },
63 'numeric(6,3)' => { data_type => 'numeric', size => [6,3] },
64 'decimal(6,3)' => { data_type => 'numeric', size => [6,3] },
65 'dec(6,3)' => { data_type => 'numeric', size => [6,3] },
68 # XXX this should map to 'boolean'
69 boolean => { data_type => 'smallint' },
72 money => { data_type => 'money' },
73 'money(3,3)' => { data_type => 'numeric', size => [3,3] },
76 byte => { data_type => 'bytea', original => { data_type => 'byte' } },
78 # Character String Types
79 char => { data_type => 'char', size => 1 },
80 'char(3)' => { data_type => 'char', size => 3 },
81 character => { data_type => 'char', size => 1 },
82 'character(3)' => { data_type => 'char', size => 3 },
83 'varchar(3)' => { data_type => 'varchar', size => 3 },
84 'character varying(3)'
85 => { data_type => 'varchar', size => 3 },
86 # XXX min size not supported, colmin from syscolumns is NULL
87 'varchar(3,2)' => { data_type => 'varchar', size => 3 },
88 'character varying(3,2)'
89 => { data_type => 'varchar', size => 3 },
90 nchar => { data_type => 'nchar', size => 1 },
91 'nchar(3)' => { data_type => 'nchar', size => 3 },
92 'nvarchar(3)' => { data_type => 'nvarchar', size => 3 },
93 'nvarchar(3,2)' => { data_type => 'nvarchar', size => 3 },
94 'lvarchar(3)' => { data_type => 'lvarchar', size => 3 },
95 'lvarchar(33)' => { data_type => 'lvarchar', size => 33 },
96 text => { data_type => 'text' },
99 date => { data_type => 'date' },
101 => { data_type => 'date', default_value => \'today' },
102 # XXX support all precisions
103 'datetime year to fraction(5)',
104 => { data_type => 'datetime year to fraction(5)' },
105 'datetime year to fraction(5) default current year to fraction(5)',
106 => { data_type => 'datetime year to fraction(5)', default_value => \'current year to fraction(5)' },
110 # XXX no way to distinguish opaque types boolean, blob and clob
111 blob => { data_type => 'blob' },
112 clob => { data_type => 'blob' },
114 # IDSSECURITYLABEL Type
116 # This requires the DBSECADM privilege and a security policy on the
117 # table, things I know nothing about.
118 # idssecuritylabel => { data_type => 'idssecuritylabel' },
121 # XXX need to introspect element type too
122 'list(varchar(20) not null)'
123 => { data_type => 'list' },
124 'multiset(varchar(20) not null)'
125 => { data_type => 'multiset' },
126 'set(varchar(20) not null)'
127 => { data_type => 'set' },
135 skip 'Set the DBICTEST_INFORMIX_EXTRADB_DSN, _USER and _PASS environment variables to run the multi-database tests', 24
136 unless $ENV{DBICTEST_INFORMIX_EXTRADB_DSN};
138 $extra_schema = $schema->clone;
139 $extra_schema->connection(@ENV{map "DBICTEST_INFORMIX_EXTRADB_$_",
143 my $dbh1 = $schema->storage->dbh;
144 my $dbh2 = $extra_schema->storage->dbh;
147 CREATE TABLE informix_loader_test4 (
148 id SERIAL PRIMARY KEY,
153 CREATE TABLE informix_loader_test5 (
154 id SERIAL PRIMARY KEY,
156 four_id INTEGER UNIQUE REFERENCES informix_loader_test4 (id)
160 CREATE TABLE informix_loader_test6 (
161 id SERIAL PRIMARY KEY,
166 CREATE TABLE informix_loader_test7 (
167 id SERIAL PRIMARY KEY,
169 six_id INTEGER UNIQUE REFERENCES informix_loader_test6 (id)
174 local $SIG{__WARN__} = sub {
175 push @warns, $_[0] unless $_[0] =~ /\bcollides\b/
176 || $_[0] =~ /unreferencable/;
180 'InformixMultiDatabase',
183 db_schema => { '%' => '%' },
184 dump_directory => EXTRA_DUMP_DIR,
187 [ $dsn, $user, $password ],
190 diag join "\n", @warns if @warns;
193 } 'dumped schema for all databases with no warnings';
198 ok $test_schema = InformixMultiDatabase->connect($dsn, $user, $password);
199 } 'connected test schema';
201 my ($rsrc, $rs, $row, $rel_info, %uniqs);
204 ok $rsrc = $test_schema->source('InformixLoaderTest4');
205 } 'got source for table in database one';
207 is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
208 'column in database one';
210 is try { $rsrc->column_info('value')->{data_type} }, 'varchar',
211 'column in database one';
213 is try { $rsrc->column_info('value')->{size} }, 100,
214 'column in database one';
217 ok $rs = $test_schema->resultset('InformixLoaderTest4');
218 } 'got resultset for table in database one';
221 ok $row = $rs->create({ value => 'foo' });
222 } 'executed SQL on table in database one';
224 $rel_info = try { $rsrc->relationship_info('informix_loader_test5') };
226 is_deeply $rel_info->{cond}, {
227 'foreign.four_id' => 'self.id'
228 }, 'relationship in database one';
230 is $rel_info->{attrs}{accessor}, 'single',
231 'relationship in database one';
233 is $rel_info->{attrs}{join_type}, 'LEFT',
234 'relationship in database one';
237 ok $rsrc = $test_schema->source('InformixLoaderTest5');
238 } 'got source for table in database one';
240 %uniqs = try { $rsrc->unique_constraints };
243 'got unique and primary constraint in database one';
246 ok $rsrc = $test_schema->source('InformixLoaderTest6');
247 } 'got source for table in database two';
249 is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
250 'column in database two introspected correctly';
252 is try { $rsrc->column_info('value')->{data_type} }, 'varchar',
253 'column in database two introspected correctly';
255 is try { $rsrc->column_info('value')->{size} }, 100,
256 'column in database two introspected correctly';
259 ok $rs = $test_schema->resultset('InformixLoaderTest6');
260 } 'got resultset for table in database two';
263 ok $row = $rs->create({ value => 'foo' });
264 } 'executed SQL on table in database two';
266 $rel_info = try { $rsrc->relationship_info('informix_loader_test7') };
268 is_deeply $rel_info->{cond}, {
269 'foreign.six_id' => 'self.id'
270 }, 'relationship in database two';
272 is $rel_info->{attrs}{accessor}, 'single',
273 'relationship in database two';
275 is $rel_info->{attrs}{join_type}, 'LEFT',
276 'relationship in database two';
279 ok $rsrc = $test_schema->source('InformixLoaderTest7');
280 } 'got source for table in database two';
282 %uniqs = try { $rsrc->unique_constraints };
285 'got unique and primary constraint in database two';
292 $tester->skip_tests('You need to set the DBICTEST_INFORMIX_DSN, _USER, and _PASS environment variables');
295 $tester->run_tests();
299 if (not $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP}) {
300 if (my $dbh2 = try { $extra_schema->storage->dbh }) {
301 my $dbh1 = $schema->storage->dbh;
304 $dbh2->do('DROP TABLE informix_loader_test7');
305 $dbh2->do('DROP TABLE informix_loader_test6');
306 $dbh1->do('DROP TABLE informix_loader_test5');
307 $dbh1->do('DROP TABLE informix_loader_test4');
310 die "Error dropping test tables: $_";
314 rmtree EXTRA_DUMP_DIR;
317 # vim:et sts=4 sw=4 tw=0: