Use sigwarn_silencer() everywhere appropriate
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_09firebird_common.t
CommitLineData
4cbddf8d 1use strict;
3a89a69f 2use warnings;
3use Test::More;
4use Scope::Guard ();
ff4b0152 5use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/;
4cbddf8d 6use lib qw(t/lib);
7use dbixcsl_common_tests;
8
c4a69b87 9my $dbd_firebird_dsn = $ENV{DBICTEST_FIREBIRD_DSN} || '';
10my $dbd_firebird_user = $ENV{DBICTEST_FIREBIRD_USER} || '';
11my $dbd_firebird_password = $ENV{DBICTEST_FIREBIRD_PASS} || '';
12
13my $dbd_interbase_dsn = $ENV{DBICTEST_FIREBIRD_INTERBASE_DSN} || '';
14my $dbd_interbase_user = $ENV{DBICTEST_FIREBIRD_INTERBASE_USER} || '';
15my $dbd_interbase_password = $ENV{DBICTEST_FIREBIRD_INTERBASE_PASS} || '';
3a89a69f 16
17my $odbc_dsn = $ENV{DBICTEST_FIREBIRD_ODBC_DSN} || '';
18my $odbc_user = $ENV{DBICTEST_FIREBIRD_ODBC_USER} || '';
19my $odbc_password = $ENV{DBICTEST_FIREBIRD_ODBC_PASS} || '';
20
21my $schema;
4cbddf8d 22
23my $tester = dbixcsl_common_tests->new(
24 vendor => 'Firebird',
25 auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY',
26 auto_inc_cb => sub {
27 my ($table, $col) = @_;
28 return (
29 qq{ CREATE GENERATOR gen_${table}_${col} },
30 qq{
31 CREATE TRIGGER ${table}_bi FOR $table
32 ACTIVE BEFORE INSERT POSITION 0
33 AS
34 BEGIN
35 IF (NEW.$col IS NULL) THEN
36 NEW.$col = GEN_ID(gen_${table}_${col},1);
37 END
38 }
39 );
40 },
41 auto_inc_drop_cb => sub {
42 my ($table, $col) = @_;
43 return (
44 qq{ DROP TRIGGER ${table}_bi },
45 qq{ DROP GENERATOR gen_${table}_${col} },
46 );
47 },
48 null => '',
b511f36e 49 preserve_case_mode_is_exclusive => 1,
50 quote_char => '"',
c4a69b87 51 connect_info => [
52 ($dbd_firebird_dsn ? {
53 dsn => $dbd_firebird_dsn,
54 user => $dbd_firebird_user,
55 password => $dbd_firebird_password,
56 connect_info_opts => { on_connect_call => 'use_softcommit' },
57 } : ()),
58 ($dbd_interbase_dsn ? {
3a89a69f 59 dsn => $dbd_interbase_dsn,
60 user => $dbd_interbase_user,
61 password => $dbd_interbase_password,
62 connect_info_opts => { on_connect_call => 'use_softcommit' },
63 } : ()),
64 ($odbc_dsn ? {
65 dsn => $odbc_dsn,
66 user => $odbc_user,
67 password => $odbc_password,
68 } : ()),
69 ],
cf0ba25b 70 data_types => {
71 # based on the Interbase Data Definition Guide
72 # http://www.ibphoenix.com/downloads/60DataDef.zip
73 #
74 # Numeric types
75 'smallint' => { data_type => 'smallint' },
76 'int' => { data_type => 'integer' },
77 'integer' => { data_type => 'integer' },
78 'bigint' => { data_type => 'bigint' },
8ec0dd69 79 'float' => { data_type => 'real' },
cf0ba25b 80 'double precision' =>
81 { data_type => 'double precision' },
8ec0dd69 82 'real' => { data_type => 'real' },
cf0ba25b 83
8ec0dd69 84 'float(2)' => { data_type => 'real' },
85 'float(7)' => { data_type => 'real' },
cf0ba25b 86 'float(8)' => { data_type => 'double precision' },
87
88 'decimal' => { data_type => 'decimal' },
89 'dec' => { data_type => 'decimal' },
90 'numeric' => { data_type => 'numeric' },
91
92 'decimal(3)' => { data_type => 'decimal', size => [3,0] },
93
94 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] },
95 'dec(3,3)' => { data_type => 'decimal', size => [3,3] },
96 'numeric(3,3)' => { data_type => 'numeric', size => [3,3] },
97
0ae64d34 98 'decimal(6,3)' => { data_type => 'decimal', size => [6,3] },
99 'numeric(6,3)' => { data_type => 'numeric', size => [6,3] },
100
101 'decimal(12,3)' => { data_type => 'decimal', size => [12,3] },
102 'numeric(12,3)' => { data_type => 'numeric', size => [12,3] },
103
cf0ba25b 104 'decimal(18,18)' => { data_type => 'decimal', size => [18,18] },
105 'dec(18,18)' => { data_type => 'decimal', size => [18,18] },
106 'numeric(18,18)' => { data_type => 'numeric', size => [18,18] },
107
108 # Date and Time Types
109 'date' => { data_type => 'date' },
6e566cc4 110 'timestamp default current_timestamp'
111 => { data_type => 'timestamp', default_value => \'current_timestamp' },
cf0ba25b 112 'time' => { data_type => 'time' },
113
114 # String Types
115 'char' => { data_type => 'char', size => 1 },
116 'char(11)' => { data_type => 'char', size => 11 },
117 'varchar(20)' => { data_type => 'varchar', size => 20 },
5111e5d0 118 'char(22) character set unicode_fss' =>
119 => { data_type => 'char(x) character set unicode_fss', size => 22 },
120 'varchar(33) character set unicode_fss' =>
121 => { data_type => 'varchar(x) character set unicode_fss', size => 33 },
122
cf0ba25b 123 # Blob types
124 'blob' => { data_type => 'blob' },
125 'blob sub_type text'
126 => { data_type => 'blob sub_type text' },
5111e5d0 127 'blob sub_type text character set unicode_fss'
128 => { data_type => 'blob sub_type text character set unicode_fss' },
cf0ba25b 129 },
3a89a69f 130 extra => {
5111e5d0 131 count => 9,
3a89a69f 132 run => sub {
133 $schema = shift;
1ad8e8c3 134 my ($monikers, $classes, $self) = @_;
3a89a69f 135
136 cleanup_extra();
137
138 my $dbh = $schema->storage->dbh;
139
140# create a mixed case table
141 $dbh->do($_) for (
142q{
143 CREATE TABLE "Firebird_Loader_Test1" (
144 "Id" INTEGER NOT NULL PRIMARY KEY,
145 "Foo" INTEGER DEFAULT 42
146 )
147},
148q{
149 CREATE GENERATOR "Gen_Firebird_Loader_Test1_Id"
150},
151q{
152 CREATE TRIGGER "Firebird_Loader_Test1_BI" for "Firebird_Loader_Test1"
153 ACTIVE BEFORE INSERT POSITION 0
154 AS
155 BEGIN
156 IF (NEW."Id" IS NULL) THEN
157 NEW."Id" = GEN_ID("Gen_Firebird_Loader_Test1_Id",1);
158 END
159},
160 );
161
162 my $guard = Scope::Guard->new(\&cleanup_extra);
163
c4a69b87 164 local $schema->loader->{preserve_case} = 1;
165 $schema->loader->_setup;
ec957051 166
1ad8e8c3 167 $self->rescan_without_warnings($schema);
3a89a69f 168
169 ok ((my $rsrc = eval { $schema->resultset('FirebirdLoaderTest1')->result_source }),
170 'got rsrc for mixed case table');
171
172 ok ((my $col_info = eval { $rsrc->column_info('Id') }),
173 'got column_info for column Id');
174
175 is $col_info->{accessor}, 'id', 'column Id has lowercase accessor "id"';
176
177 is $col_info->{is_auto_increment}, 1, 'is_auto_increment detected for mixed case trigger';
178
179 is $col_info->{sequence}, 'Gen_Firebird_Loader_Test1_Id', 'correct mixed case sequence name';
180
181 is eval { $rsrc->column_info('Foo')->{default_value} }, 42, 'default_value detected for mixed case column';
5111e5d0 182
183 # test the fixed up ->_dbh_type_info_type_name for the ODBC driver
184 if ($schema->storage->_dbi_connect_info->[0] =~ /:ODBC:/i) {
185 my %truncated_types = (
186 4 => 'INTEGER',
187 -9 => 'VARCHAR(x) CHARACTER SET UNICODE_FSS',
188 -10 => 'BLOB SUB_TYPE TEXT CHARACTER SET UNICODE_FSS',
189 );
190
191 for my $type_num (keys %truncated_types) {
c4a69b87 192 is $schema->loader->_dbh_type_info_type_name($type_num),
5111e5d0 193 $truncated_types{$type_num},
194 "ODBC ->_dbh_type_info_type_name correct for '$truncated_types{$type_num}'";
195 }
196 }
197 else {
198 my $tb = Test::More->builder;
199 $tb->skip('not testing _dbh_type_info_type_name on DBD::InterBase') for 1..3;
200 }
3a89a69f 201 },
202 },
4cbddf8d 203);
204
c4a69b87 205if (not ($dbd_firebird_dsn || $dbd_interbase_dsn || $odbc_dsn)) {
206 $tester->skip_tests('You need to set the DBICTEST_FIREBIRD_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_INTERBASE_DSN and/or the DBICTEST_FIREBIRD_ODBC_DSN environment variables');
4cbddf8d 207}
208else {
4145a6f3 209 # get rid of stupid warning from InterBase/GetInfo.pm
3a89a69f 210 if ($dbd_interbase_dsn) {
ff4b0152 211 local $SIG{__WARN__} = sigwarn_silencer(
212 qr{^Use of uninitialized value in sprintf at \S+DBD/InterBase/GetInfo\.pm line \d+\.$|^Missing argument in sprintf at \S+DBD/InterBase/GetInfo.pm line \d+\.$}
213 );
4145a6f3 214 require DBD::InterBase;
215 require DBD::InterBase::GetInfo;
216 }
c4a69b87 217
4cbddf8d 218 $tester->run_tests();
219}
3a89a69f 220
221sub cleanup_extra {
222 $schema->storage->disconnect;
223 my $dbh = $schema->storage->dbh;
224
225 foreach my $stmt (
226 'DROP TRIGGER "Firebird_Loader_Test1_BI"',
227 'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"',
228 'DROP TABLE "Firebird_Loader_Test1"',
229 ) {
230 eval { $dbh->do($stmt) };
231 }
232}
e32d24a5 233# vim:et sts=4 sw=4 tw=0: