Commit | Line | Data |
4cbddf8d |
1 | use strict; |
3a89a69f |
2 | use warnings; |
3 | use Test::More; |
4 | use Scope::Guard (); |
ffd4ce36 |
5 | use DBIx::Class::Schema::Loader::Optional::Dependencies; |
ff4b0152 |
6 | use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/; |
4cbddf8d |
7 | use lib qw(t/lib); |
8 | use dbixcsl_common_tests; |
9 | |
ffd4ce36 |
10 | my %env2optdep = map { $_ => lc "test_rdbms_$_" } qw(FIREBIRD FIREBIRD_INTERBASE FIREBIRD_ODBC); |
11 | |
12 | plan skip_all => 'requirements not satisfied: ' . (join ' OR ', map |
13 | { "[ @{[ DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for( $_ ) ]} ]" } |
14 | values %env2optdep |
15 | ) unless scalar grep |
16 | { DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for( $_ ) } |
17 | values %env2optdep |
18 | ; |
19 | |
4fb2971c |
20 | my %dsns; |
ffd4ce36 |
21 | for my $type (keys %env2optdep) { |
22 | my %conninfo; |
23 | @conninfo{qw(dsn user password)} = map { $ENV{"DBICTEST_${type}_$_"} } qw(DSN USER PASS); |
24 | next unless $conninfo{dsn}; |
c4a69b87 |
25 | |
ffd4ce36 |
26 | my $dep_group = $env2optdep{$type}; |
27 | if (!DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for($dep_group)) { |
28 | diag "Testing with DBICTEST_${type}_DSN needs " . DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for($dep_group); |
4fb2971c |
29 | next; |
30 | } |
31 | |
ffd4ce36 |
32 | $dsns{$type} = \%conninfo; |
33 | $dsns{$type}{connect_info_opts} = { on_connect_call => 'use_softcommit' } |
34 | if $type =~ /\AFIREBIRD(?:_INTERBASE)?\z/; |
4fb2971c |
35 | }; |
3a89a69f |
36 | |
3a89a69f |
37 | my $schema; |
4cbddf8d |
38 | |
39 | my $tester = dbixcsl_common_tests->new( |
40 | vendor => 'Firebird', |
41 | auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY', |
42 | auto_inc_cb => sub { |
43 | my ($table, $col) = @_; |
44 | return ( |
45 | qq{ CREATE GENERATOR gen_${table}_${col} }, |
46 | qq{ |
47 | CREATE TRIGGER ${table}_bi FOR $table |
48 | ACTIVE BEFORE INSERT POSITION 0 |
49 | AS |
50 | BEGIN |
51 | IF (NEW.$col IS NULL) THEN |
52 | NEW.$col = GEN_ID(gen_${table}_${col},1); |
53 | END |
54 | } |
55 | ); |
56 | }, |
57 | auto_inc_drop_cb => sub { |
58 | my ($table, $col) = @_; |
59 | return ( |
60 | qq{ DROP TRIGGER ${table}_bi }, |
61 | qq{ DROP GENERATOR gen_${table}_${col} }, |
62 | ); |
63 | }, |
64 | null => '', |
b511f36e |
65 | preserve_case_mode_is_exclusive => 1, |
66 | quote_char => '"', |
7336f5dc |
67 | connect_info => [ map { $dsns{$_} } sort keys %dsns ], |
cf0ba25b |
68 | data_types => { |
69 | # based on the Interbase Data Definition Guide |
70 | # http://www.ibphoenix.com/downloads/60DataDef.zip |
71 | # |
72 | # Numeric types |
73 | 'smallint' => { data_type => 'smallint' }, |
74 | 'int' => { data_type => 'integer' }, |
75 | 'integer' => { data_type => 'integer' }, |
76 | 'bigint' => { data_type => 'bigint' }, |
8ec0dd69 |
77 | 'float' => { data_type => 'real' }, |
cf0ba25b |
78 | 'double precision' => |
79 | { data_type => 'double precision' }, |
8ec0dd69 |
80 | 'real' => { data_type => 'real' }, |
cf0ba25b |
81 | |
8ec0dd69 |
82 | 'float(2)' => { data_type => 'real' }, |
83 | 'float(7)' => { data_type => 'real' }, |
cf0ba25b |
84 | 'float(8)' => { data_type => 'double precision' }, |
85 | |
86 | 'decimal' => { data_type => 'decimal' }, |
87 | 'dec' => { data_type => 'decimal' }, |
88 | 'numeric' => { data_type => 'numeric' }, |
89 | |
90 | 'decimal(3)' => { data_type => 'decimal', size => [3,0] }, |
91 | |
92 | 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] }, |
93 | 'dec(3,3)' => { data_type => 'decimal', size => [3,3] }, |
94 | 'numeric(3,3)' => { data_type => 'numeric', size => [3,3] }, |
95 | |
0ae64d34 |
96 | 'decimal(6,3)' => { data_type => 'decimal', size => [6,3] }, |
97 | 'numeric(6,3)' => { data_type => 'numeric', size => [6,3] }, |
98 | |
99 | 'decimal(12,3)' => { data_type => 'decimal', size => [12,3] }, |
100 | 'numeric(12,3)' => { data_type => 'numeric', size => [12,3] }, |
101 | |
cf0ba25b |
102 | 'decimal(18,18)' => { data_type => 'decimal', size => [18,18] }, |
103 | 'dec(18,18)' => { data_type => 'decimal', size => [18,18] }, |
104 | 'numeric(18,18)' => { data_type => 'numeric', size => [18,18] }, |
105 | |
106 | # Date and Time Types |
107 | 'date' => { data_type => 'date' }, |
6e566cc4 |
108 | 'timestamp default current_timestamp' |
109 | => { data_type => 'timestamp', default_value => \'current_timestamp' }, |
cf0ba25b |
110 | 'time' => { data_type => 'time' }, |
111 | |
112 | # String Types |
113 | 'char' => { data_type => 'char', size => 1 }, |
114 | 'char(11)' => { data_type => 'char', size => 11 }, |
115 | 'varchar(20)' => { data_type => 'varchar', size => 20 }, |
5111e5d0 |
116 | 'char(22) character set unicode_fss' => |
117 | => { data_type => 'char(x) character set unicode_fss', size => 22 }, |
118 | 'varchar(33) character set unicode_fss' => |
119 | => { data_type => 'varchar(x) character set unicode_fss', size => 33 }, |
120 | |
cf0ba25b |
121 | # Blob types |
122 | 'blob' => { data_type => 'blob' }, |
123 | 'blob sub_type text' |
124 | => { data_type => 'blob sub_type text' }, |
5111e5d0 |
125 | 'blob sub_type text character set unicode_fss' |
126 | => { data_type => 'blob sub_type text character set unicode_fss' }, |
cf0ba25b |
127 | }, |
3a89a69f |
128 | extra => { |
d7e0e0e8 |
129 | count => 11, |
f7c4e9ae |
130 | create => [ |
131 | q{ |
132 | CREATE TABLE "Firebird_Loader_Test1" ( |
133 | "Id" INTEGER NOT NULL PRIMARY KEY, |
134 | "Foo" INTEGER DEFAULT 42 |
135 | ) |
136 | }, |
137 | q{ |
138 | CREATE GENERATOR "Gen_Firebird_Loader_Test1_Id" |
139 | }, |
140 | q{ |
141 | CREATE TRIGGER "Firebird_Loader_Test1_BI" for "Firebird_Loader_Test1" |
142 | ACTIVE BEFORE INSERT POSITION 0 |
143 | AS |
144 | BEGIN |
145 | IF (NEW."Id" IS NULL) THEN |
146 | NEW."Id" = GEN_ID("Gen_Firebird_Loader_Test1_Id",1); |
147 | END |
148 | }, |
d7e0e0e8 |
149 | q{ |
150 | CREATE VIEW firebird_loader_test2 AS SELECT * FROM "Firebird_Loader_Test1" |
151 | }, |
f7c4e9ae |
152 | ], |
153 | pre_drop_ddl => [ |
d7e0e0e8 |
154 | 'DROP VIEW firebird_loader_test2', |
f7c4e9ae |
155 | 'DROP TRIGGER "Firebird_Loader_Test1_BI"', |
156 | 'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"', |
157 | 'DROP TABLE "Firebird_Loader_Test1"', |
158 | ], |
3a89a69f |
159 | run => sub { |
160 | $schema = shift; |
1ad8e8c3 |
161 | my ($monikers, $classes, $self) = @_; |
3a89a69f |
162 | |
3a89a69f |
163 | my $dbh = $schema->storage->dbh; |
164 | |
165 | # create a mixed case table |
166 | $dbh->do($_) for ( |
3a89a69f |
167 | ); |
168 | |
c4a69b87 |
169 | local $schema->loader->{preserve_case} = 1; |
170 | $schema->loader->_setup; |
ec957051 |
171 | |
1ad8e8c3 |
172 | $self->rescan_without_warnings($schema); |
3a89a69f |
173 | |
174 | ok ((my $rsrc = eval { $schema->resultset('FirebirdLoaderTest1')->result_source }), |
175 | 'got rsrc for mixed case table'); |
176 | |
177 | ok ((my $col_info = eval { $rsrc->column_info('Id') }), |
178 | 'got column_info for column Id'); |
179 | |
180 | is $col_info->{accessor}, 'id', 'column Id has lowercase accessor "id"'; |
181 | |
182 | is $col_info->{is_auto_increment}, 1, 'is_auto_increment detected for mixed case trigger'; |
183 | |
184 | is $col_info->{sequence}, 'Gen_Firebird_Loader_Test1_Id', 'correct mixed case sequence name'; |
185 | |
186 | is eval { $rsrc->column_info('Foo')->{default_value} }, 42, 'default_value detected for mixed case column'; |
5111e5d0 |
187 | |
d7e0e0e8 |
188 | # test that views are marked as such |
189 | my $view_source = $schema->resultset($monikers->{firebird_loader_test2})->result_source; |
190 | isa_ok $view_source, 'DBIx::Class::ResultSource::View', |
191 | 'view result source'; |
192 | |
193 | like $view_source->view_definition, |
194 | qr/\A \s* select\b .* \bfrom \s+ (?-i:"Firebird_Loader_Test1") \s* \z/imsx, |
195 | 'view definition'; |
196 | |
5111e5d0 |
197 | # test the fixed up ->_dbh_type_info_type_name for the ODBC driver |
c76ebcc7 |
198 | SKIP: { |
199 | skip '_dbh_type_info_type_name test is only for DBD::ODBC', 3 |
200 | unless $schema->storage->_dbi_connect_info->[0] =~ /:ODBC:/i; |
201 | |
5111e5d0 |
202 | my %truncated_types = ( |
203 | 4 => 'INTEGER', |
204 | -9 => 'VARCHAR(x) CHARACTER SET UNICODE_FSS', |
205 | -10 => 'BLOB SUB_TYPE TEXT CHARACTER SET UNICODE_FSS', |
206 | ); |
207 | |
208 | for my $type_num (keys %truncated_types) { |
c4a69b87 |
209 | is $schema->loader->_dbh_type_info_type_name($type_num), |
5111e5d0 |
210 | $truncated_types{$type_num}, |
211 | "ODBC ->_dbh_type_info_type_name correct for '$truncated_types{$type_num}'"; |
212 | } |
213 | } |
3a89a69f |
214 | }, |
215 | }, |
4cbddf8d |
216 | ); |
217 | |
4fb2971c |
218 | { |
4145a6f3 |
219 | # get rid of stupid warning from InterBase/GetInfo.pm |
4fb2971c |
220 | if ($dsns{FIREBIRD_INTERBASE}) { |
ff4b0152 |
221 | local $SIG{__WARN__} = sigwarn_silencer( |
071c2f8d |
222 | qr{^(?:Use of uninitialized value|Argument "[0-9_]+" isn't numeric|Missing argument) in sprintf at \S+DBD/InterBase/GetInfo.pm line \d+\.$} |
ff4b0152 |
223 | ); |
4145a6f3 |
224 | require DBD::InterBase; |
225 | require DBD::InterBase::GetInfo; |
226 | } |
c4a69b87 |
227 | |
4cbddf8d |
228 | $tester->run_tests(); |
229 | } |
3a89a69f |
230 | |
e32d24a5 |
231 | # vim:et sts=4 sw=4 tw=0: |