5 use DBIx::Class::Optional::Dependencies;
6 use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/;
8 use dbixcsl_common_tests;
11 for (qw(FIREBIRD FIREBIRD_ODBC FIREBIRD_INTERBASE)) {
12 next unless $ENV{"DBICTEST_${_}_DSN"};
14 my $dep_group = lc "rdbms_$_";
15 if (!DBIx::Class::Optional::Dependencies->req_ok_for($dep_group)) {
16 diag 'You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for($dep_group)
21 $dsns{$_}{dsn} = $ENV{"DBICTEST_${_}_DSN"};
22 $dsns{$_}{user} = $ENV{"DBICTEST_${_}_USER"};
23 $dsns{$_}{password} = $ENV{"DBICTEST_${_}_PASS"};
24 $dsns{$_}{connect_info_opts} = { on_connect_call => 'use_softcommit' }
25 if /\AFIREBIRD(?:_INTERBASE)\z/;
28 plan skip_all => 'You need to set the DBICTEST_FIREBIRD_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_ODBC_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_INTERBASE_DSN, _USER and _PASS environment variables'
33 my $tester = dbixcsl_common_tests->new(
35 auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY',
37 my ($table, $col) = @_;
39 qq{ CREATE GENERATOR gen_${table}_${col} },
41 CREATE TRIGGER ${table}_bi FOR $table
42 ACTIVE BEFORE INSERT POSITION 0
45 IF (NEW.$col IS NULL) THEN
46 NEW.$col = GEN_ID(gen_${table}_${col},1);
51 auto_inc_drop_cb => sub {
52 my ($table, $col) = @_;
54 qq{ DROP TRIGGER ${table}_bi },
55 qq{ DROP GENERATOR gen_${table}_${col} },
59 preserve_case_mode_is_exclusive => 1,
61 connect_info => [ values %dsns ],
63 # based on the Interbase Data Definition Guide
64 # http://www.ibphoenix.com/downloads/60DataDef.zip
67 'smallint' => { data_type => 'smallint' },
68 'int' => { data_type => 'integer' },
69 'integer' => { data_type => 'integer' },
70 'bigint' => { data_type => 'bigint' },
71 'float' => { data_type => 'real' },
73 { data_type => 'double precision' },
74 'real' => { data_type => 'real' },
76 'float(2)' => { data_type => 'real' },
77 'float(7)' => { data_type => 'real' },
78 'float(8)' => { data_type => 'double precision' },
80 'decimal' => { data_type => 'decimal' },
81 'dec' => { data_type => 'decimal' },
82 'numeric' => { data_type => 'numeric' },
84 'decimal(3)' => { data_type => 'decimal', size => [3,0] },
86 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] },
87 'dec(3,3)' => { data_type => 'decimal', size => [3,3] },
88 'numeric(3,3)' => { data_type => 'numeric', size => [3,3] },
90 'decimal(6,3)' => { data_type => 'decimal', size => [6,3] },
91 'numeric(6,3)' => { data_type => 'numeric', size => [6,3] },
93 'decimal(12,3)' => { data_type => 'decimal', size => [12,3] },
94 'numeric(12,3)' => { data_type => 'numeric', size => [12,3] },
96 'decimal(18,18)' => { data_type => 'decimal', size => [18,18] },
97 'dec(18,18)' => { data_type => 'decimal', size => [18,18] },
98 'numeric(18,18)' => { data_type => 'numeric', size => [18,18] },
100 # Date and Time Types
101 'date' => { data_type => 'date' },
102 'timestamp default current_timestamp'
103 => { data_type => 'timestamp', default_value => \'current_timestamp' },
104 'time' => { data_type => 'time' },
107 'char' => { data_type => 'char', size => 1 },
108 'char(11)' => { data_type => 'char', size => 11 },
109 'varchar(20)' => { data_type => 'varchar', size => 20 },
110 'char(22) character set unicode_fss' =>
111 => { data_type => 'char(x) character set unicode_fss', size => 22 },
112 'varchar(33) character set unicode_fss' =>
113 => { data_type => 'varchar(x) character set unicode_fss', size => 33 },
116 'blob' => { data_type => 'blob' },
118 => { data_type => 'blob sub_type text' },
119 'blob sub_type text character set unicode_fss'
120 => { data_type => 'blob sub_type text character set unicode_fss' },
126 my ($monikers, $classes, $self) = @_;
130 my $dbh = $schema->storage->dbh;
132 # create a mixed case table
135 CREATE TABLE "Firebird_Loader_Test1" (
136 "Id" INTEGER NOT NULL PRIMARY KEY,
137 "Foo" INTEGER DEFAULT 42
141 CREATE GENERATOR "Gen_Firebird_Loader_Test1_Id"
144 CREATE TRIGGER "Firebird_Loader_Test1_BI" for "Firebird_Loader_Test1"
145 ACTIVE BEFORE INSERT POSITION 0
148 IF (NEW."Id" IS NULL) THEN
149 NEW."Id" = GEN_ID("Gen_Firebird_Loader_Test1_Id",1);
154 my $guard = Scope::Guard->new(\&cleanup_extra);
156 local $schema->loader->{preserve_case} = 1;
157 $schema->loader->_setup;
159 $self->rescan_without_warnings($schema);
161 ok ((my $rsrc = eval { $schema->resultset('FirebirdLoaderTest1')->result_source }),
162 'got rsrc for mixed case table');
164 ok ((my $col_info = eval { $rsrc->column_info('Id') }),
165 'got column_info for column Id');
167 is $col_info->{accessor}, 'id', 'column Id has lowercase accessor "id"';
169 is $col_info->{is_auto_increment}, 1, 'is_auto_increment detected for mixed case trigger';
171 is $col_info->{sequence}, 'Gen_Firebird_Loader_Test1_Id', 'correct mixed case sequence name';
173 is eval { $rsrc->column_info('Foo')->{default_value} }, 42, 'default_value detected for mixed case column';
175 # test the fixed up ->_dbh_type_info_type_name for the ODBC driver
176 if ($schema->storage->_dbi_connect_info->[0] =~ /:ODBC:/i) {
177 my %truncated_types = (
179 -9 => 'VARCHAR(x) CHARACTER SET UNICODE_FSS',
180 -10 => 'BLOB SUB_TYPE TEXT CHARACTER SET UNICODE_FSS',
183 for my $type_num (keys %truncated_types) {
184 is $schema->loader->_dbh_type_info_type_name($type_num),
185 $truncated_types{$type_num},
186 "ODBC ->_dbh_type_info_type_name correct for '$truncated_types{$type_num}'";
190 my $tb = Test::More->builder;
191 $tb->skip('not testing _dbh_type_info_type_name on DBD::InterBase') for 1..3;
198 # get rid of stupid warning from InterBase/GetInfo.pm
199 if ($dsns{FIREBIRD_INTERBASE}) {
200 local $SIG{__WARN__} = sigwarn_silencer(
201 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+\.$}
203 require DBD::InterBase;
204 require DBD::InterBase::GetInfo;
207 $tester->run_tests();
211 $schema->storage->disconnect;
212 my $dbh = $schema->storage->dbh;
215 'DROP TRIGGER "Firebird_Loader_Test1_BI"',
216 'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"',
217 'DROP TABLE "Firebird_Loader_Test1"',
219 eval { $dbh->do($stmt) };
222 # vim:et sts=4 sw=4 tw=0: