Commit | Line | Data |
4cbddf8d |
1 | use strict; |
3a89a69f |
2 | use warnings; |
3 | use Test::More; |
4 | use Scope::Guard (); |
4cbddf8d |
5 | use lib qw(t/lib); |
6 | use dbixcsl_common_tests; |
7 | |
3a89a69f |
8 | my $dbd_interbase_dsn = $ENV{DBICTEST_FIREBIRD_DSN} || ''; |
9 | my $dbd_interbase_user = $ENV{DBICTEST_FIREBIRD_USER} || ''; |
10 | my $dbd_interbase_password = $ENV{DBICTEST_FIREBIRD_PASS} || ''; |
11 | |
12 | my $odbc_dsn = $ENV{DBICTEST_FIREBIRD_ODBC_DSN} || ''; |
13 | my $odbc_user = $ENV{DBICTEST_FIREBIRD_ODBC_USER} || ''; |
14 | my $odbc_password = $ENV{DBICTEST_FIREBIRD_ODBC_PASS} || ''; |
15 | |
16 | my $schema; |
4cbddf8d |
17 | |
18 | my $tester = dbixcsl_common_tests->new( |
19 | vendor => 'Firebird', |
20 | auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY', |
21 | auto_inc_cb => sub { |
22 | my ($table, $col) = @_; |
23 | return ( |
24 | qq{ CREATE GENERATOR gen_${table}_${col} }, |
25 | qq{ |
26 | CREATE TRIGGER ${table}_bi FOR $table |
27 | ACTIVE BEFORE INSERT POSITION 0 |
28 | AS |
29 | BEGIN |
30 | IF (NEW.$col IS NULL) THEN |
31 | NEW.$col = GEN_ID(gen_${table}_${col},1); |
32 | END |
33 | } |
34 | ); |
35 | }, |
36 | auto_inc_drop_cb => sub { |
37 | my ($table, $col) = @_; |
38 | return ( |
39 | qq{ DROP TRIGGER ${table}_bi }, |
40 | qq{ DROP GENERATOR gen_${table}_${col} }, |
41 | ); |
42 | }, |
43 | null => '', |
b511f36e |
44 | preserve_case_mode_is_exclusive => 1, |
45 | quote_char => '"', |
46 | warnings => [ qr/'preserve_case' option/ ], |
3a89a69f |
47 | connect_info => [ ($dbd_interbase_dsn ? { |
48 | dsn => $dbd_interbase_dsn, |
49 | user => $dbd_interbase_user, |
50 | password => $dbd_interbase_password, |
51 | connect_info_opts => { on_connect_call => 'use_softcommit' }, |
52 | } : ()), |
53 | ($odbc_dsn ? { |
54 | dsn => $odbc_dsn, |
55 | user => $odbc_user, |
56 | password => $odbc_password, |
57 | } : ()), |
58 | ], |
cf0ba25b |
59 | data_types => { |
60 | # based on the Interbase Data Definition Guide |
61 | # http://www.ibphoenix.com/downloads/60DataDef.zip |
62 | # |
63 | # Numeric types |
64 | 'smallint' => { data_type => 'smallint' }, |
65 | 'int' => { data_type => 'integer' }, |
66 | 'integer' => { data_type => 'integer' }, |
67 | 'bigint' => { data_type => 'bigint' }, |
8ec0dd69 |
68 | 'float' => { data_type => 'real' }, |
cf0ba25b |
69 | 'double precision' => |
70 | { data_type => 'double precision' }, |
8ec0dd69 |
71 | 'real' => { data_type => 'real' }, |
cf0ba25b |
72 | |
8ec0dd69 |
73 | 'float(2)' => { data_type => 'real' }, |
74 | 'float(7)' => { data_type => 'real' }, |
cf0ba25b |
75 | 'float(8)' => { data_type => 'double precision' }, |
76 | |
77 | 'decimal' => { data_type => 'decimal' }, |
78 | 'dec' => { data_type => 'decimal' }, |
79 | 'numeric' => { data_type => 'numeric' }, |
80 | |
81 | 'decimal(3)' => { data_type => 'decimal', size => [3,0] }, |
82 | |
83 | 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] }, |
84 | 'dec(3,3)' => { data_type => 'decimal', size => [3,3] }, |
85 | 'numeric(3,3)' => { data_type => 'numeric', size => [3,3] }, |
86 | |
0ae64d34 |
87 | 'decimal(6,3)' => { data_type => 'decimal', size => [6,3] }, |
88 | 'numeric(6,3)' => { data_type => 'numeric', size => [6,3] }, |
89 | |
90 | 'decimal(12,3)' => { data_type => 'decimal', size => [12,3] }, |
91 | 'numeric(12,3)' => { data_type => 'numeric', size => [12,3] }, |
92 | |
cf0ba25b |
93 | 'decimal(18,18)' => { data_type => 'decimal', size => [18,18] }, |
94 | 'dec(18,18)' => { data_type => 'decimal', size => [18,18] }, |
95 | 'numeric(18,18)' => { data_type => 'numeric', size => [18,18] }, |
96 | |
97 | # Date and Time Types |
98 | 'date' => { data_type => 'date' }, |
6e566cc4 |
99 | 'timestamp default current_timestamp' |
100 | => { data_type => 'timestamp', default_value => \'current_timestamp' }, |
cf0ba25b |
101 | 'time' => { data_type => 'time' }, |
102 | |
103 | # String Types |
104 | 'char' => { data_type => 'char', size => 1 }, |
105 | 'char(11)' => { data_type => 'char', size => 11 }, |
106 | 'varchar(20)' => { data_type => 'varchar', size => 20 }, |
107 | |
108 | # Blob types |
109 | 'blob' => { data_type => 'blob' }, |
110 | 'blob sub_type text' |
111 | => { data_type => 'blob sub_type text' }, |
112 | }, |
3a89a69f |
113 | extra => { |
b511f36e |
114 | count => 6, |
3a89a69f |
115 | run => sub { |
116 | $schema = shift; |
117 | |
118 | cleanup_extra(); |
119 | |
120 | my $dbh = $schema->storage->dbh; |
121 | |
122 | # create a mixed case table |
123 | $dbh->do($_) for ( |
124 | q{ |
125 | CREATE TABLE "Firebird_Loader_Test1" ( |
126 | "Id" INTEGER NOT NULL PRIMARY KEY, |
127 | "Foo" INTEGER DEFAULT 42 |
128 | ) |
129 | }, |
130 | q{ |
131 | CREATE GENERATOR "Gen_Firebird_Loader_Test1_Id" |
132 | }, |
133 | q{ |
134 | CREATE TRIGGER "Firebird_Loader_Test1_BI" for "Firebird_Loader_Test1" |
135 | ACTIVE BEFORE INSERT POSITION 0 |
136 | AS |
137 | BEGIN |
138 | IF (NEW."Id" IS NULL) THEN |
139 | NEW."Id" = GEN_ID("Gen_Firebird_Loader_Test1_Id",1); |
140 | END |
141 | }, |
142 | ); |
143 | |
144 | my $guard = Scope::Guard->new(\&cleanup_extra); |
145 | |
b511f36e |
146 | local $schema->_loader->{preserve_case} = 1; |
147 | $schema->_loader->_setup; |
ec957051 |
148 | |
3a89a69f |
149 | { |
150 | local $SIG{__WARN__} = sub {}; |
151 | $schema->rescan; |
152 | } |
153 | |
154 | ok ((my $rsrc = eval { $schema->resultset('FirebirdLoaderTest1')->result_source }), |
155 | 'got rsrc for mixed case table'); |
156 | |
157 | ok ((my $col_info = eval { $rsrc->column_info('Id') }), |
158 | 'got column_info for column Id'); |
159 | |
160 | is $col_info->{accessor}, 'id', 'column Id has lowercase accessor "id"'; |
161 | |
162 | is $col_info->{is_auto_increment}, 1, 'is_auto_increment detected for mixed case trigger'; |
163 | |
164 | is $col_info->{sequence}, 'Gen_Firebird_Loader_Test1_Id', 'correct mixed case sequence name'; |
165 | |
166 | is eval { $rsrc->column_info('Foo')->{default_value} }, 42, 'default_value detected for mixed case column'; |
167 | }, |
168 | }, |
4cbddf8d |
169 | ); |
170 | |
3a89a69f |
171 | if (not ($dbd_interbase_dsn || $odbc_dsn)) { |
172 | $tester->skip_tests('You need to set the DBICTEST_FIREBIRD_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_ODBC_DSN, _USER and _PASS environment variables'); |
4cbddf8d |
173 | } |
174 | else { |
4145a6f3 |
175 | # get rid of stupid warning from InterBase/GetInfo.pm |
3a89a69f |
176 | if ($dbd_interbase_dsn) { |
4145a6f3 |
177 | local $SIG{__WARN__} = sub {}; |
178 | require DBD::InterBase; |
179 | require DBD::InterBase::GetInfo; |
180 | } |
4cbddf8d |
181 | $tester->run_tests(); |
182 | } |
3a89a69f |
183 | |
184 | sub cleanup_extra { |
185 | $schema->storage->disconnect; |
186 | my $dbh = $schema->storage->dbh; |
187 | |
188 | foreach my $stmt ( |
189 | 'DROP TRIGGER "Firebird_Loader_Test1_BI"', |
190 | 'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"', |
191 | 'DROP TABLE "Firebird_Loader_Test1"', |
192 | ) { |
193 | eval { $dbh->do($stmt) }; |
194 | } |
195 | } |