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 => [ map { $dsns{$_} } sort keys %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 CREATE TABLE "Firebird_Loader_Test1" (
127 "Id" INTEGER NOT NULL PRIMARY KEY,
128 "Foo" INTEGER DEFAULT 42
132 CREATE GENERATOR "Gen_Firebird_Loader_Test1_Id"
135 CREATE TRIGGER "Firebird_Loader_Test1_BI" for "Firebird_Loader_Test1"
136 ACTIVE BEFORE INSERT POSITION 0
139 IF (NEW."Id" IS NULL) THEN
140 NEW."Id" = GEN_ID("Gen_Firebird_Loader_Test1_Id",1);
145 'DROP TRIGGER "Firebird_Loader_Test1_BI"',
146 'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"',
147 'DROP TABLE "Firebird_Loader_Test1"',
151 my ($monikers, $classes, $self) = @_;
153 my $dbh = $schema->storage->dbh;
155 # create a mixed case table
159 local $schema->loader->{preserve_case} = 1;
160 $schema->loader->_setup;
162 $self->rescan_without_warnings($schema);
164 ok ((my $rsrc = eval { $schema->resultset('FirebirdLoaderTest1')->result_source }),
165 'got rsrc for mixed case table');
167 ok ((my $col_info = eval { $rsrc->column_info('Id') }),
168 'got column_info for column Id');
170 is $col_info->{accessor}, 'id', 'column Id has lowercase accessor "id"';
172 is $col_info->{is_auto_increment}, 1, 'is_auto_increment detected for mixed case trigger';
174 is $col_info->{sequence}, 'Gen_Firebird_Loader_Test1_Id', 'correct mixed case sequence name';
176 is eval { $rsrc->column_info('Foo')->{default_value} }, 42, 'default_value detected for mixed case column';
178 # test the fixed up ->_dbh_type_info_type_name for the ODBC driver
179 if ($schema->storage->_dbi_connect_info->[0] =~ /:ODBC:/i) {
180 my %truncated_types = (
182 -9 => 'VARCHAR(x) CHARACTER SET UNICODE_FSS',
183 -10 => 'BLOB SUB_TYPE TEXT CHARACTER SET UNICODE_FSS',
186 for my $type_num (keys %truncated_types) {
187 is $schema->loader->_dbh_type_info_type_name($type_num),
188 $truncated_types{$type_num},
189 "ODBC ->_dbh_type_info_type_name correct for '$truncated_types{$type_num}'";
193 my $tb = Test::More->builder;
194 $tb->skip('not testing _dbh_type_info_type_name on DBD::InterBase') for 1..3;
201 # get rid of stupid warning from InterBase/GetInfo.pm
202 if ($dsns{FIREBIRD_INTERBASE}) {
203 local $SIG{__WARN__} = sigwarn_silencer(
204 qr{^(?:Use of uninitialized value|Argument "[0-9_]+" isn't numeric|Missing argument) in sprintf at \S+DBD/InterBase/GetInfo.pm line \d+\.$}
206 require DBD::InterBase;
207 require DBD::InterBase::GetInfo;
210 $tester->run_tests();
213 # vim:et sts=4 sw=4 tw=0: