5 use DBIx::Class::Schema::Loader::Optional::Dependencies;
6 use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/;
8 use dbixcsl_common_tests;
10 my %env2optdep = map { $_ => lc "test_rdbms_$_" } qw(FIREBIRD FIREBIRD_INTERBASE FIREBIRD_ODBC);
12 plan skip_all => 'requirements not satisfied: ' . (join ' OR ', map
13 { "[ @{[ DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for( $_ ) ]} ]" }
16 { DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for( $_ ) }
21 for my $type (keys %env2optdep) {
23 @conninfo{qw(dsn user password)} = map { $ENV{"DBICTEST_${type}_$_"} } qw(DSN USER PASS);
24 next unless $conninfo{dsn};
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);
32 $dsns{$type} = \%conninfo;
33 $dsns{$type}{connect_info_opts} = { on_connect_call => 'use_softcommit' }
34 if $type =~ /\AFIREBIRD(?:_INTERBASE)?\z/;
39 my $tester = dbixcsl_common_tests->new(
41 auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY',
43 my ($table, $col) = @_;
45 qq{ CREATE GENERATOR gen_${table}_${col} },
47 CREATE TRIGGER ${table}_bi FOR $table
48 ACTIVE BEFORE INSERT POSITION 0
51 IF (NEW.$col IS NULL) THEN
52 NEW.$col = GEN_ID(gen_${table}_${col},1);
57 auto_inc_drop_cb => sub {
58 my ($table, $col) = @_;
60 qq{ DROP TRIGGER ${table}_bi },
61 qq{ DROP GENERATOR gen_${table}_${col} },
65 preserve_case_mode_is_exclusive => 1,
67 connect_info => [ map { $dsns{$_} } sort keys %dsns ],
69 # based on the Interbase Data Definition Guide
70 # http://www.ibphoenix.com/downloads/60DataDef.zip
73 'smallint' => { data_type => 'smallint' },
74 'int' => { data_type => 'integer' },
75 'integer' => { data_type => 'integer' },
76 'bigint' => { data_type => 'bigint' },
77 'float' => { data_type => 'real' },
79 { data_type => 'double precision' },
80 'real' => { data_type => 'real' },
82 'float(2)' => { data_type => 'real' },
83 'float(7)' => { data_type => 'real' },
84 'float(8)' => { data_type => 'double precision' },
86 'decimal' => { data_type => 'decimal' },
87 'dec' => { data_type => 'decimal' },
88 'numeric' => { data_type => 'numeric' },
90 'decimal(3)' => { data_type => 'decimal', size => [3,0] },
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] },
96 'decimal(6,3)' => { data_type => 'decimal', size => [6,3] },
97 'numeric(6,3)' => { data_type => 'numeric', size => [6,3] },
99 'decimal(12,3)' => { data_type => 'decimal', size => [12,3] },
100 'numeric(12,3)' => { data_type => 'numeric', size => [12,3] },
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] },
106 # Date and Time Types
107 'date' => { data_type => 'date' },
108 'timestamp default current_timestamp'
109 => { data_type => 'timestamp', default_value => \'current_timestamp' },
110 'time' => { data_type => 'time' },
113 'char' => { data_type => 'char', size => 1 },
114 'char(11)' => { data_type => 'char', size => 11 },
115 'varchar(20)' => { data_type => 'varchar', size => 20 },
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 },
122 'blob' => { data_type => 'blob' },
124 => { data_type => 'blob sub_type text' },
125 'blob sub_type text character set unicode_fss'
126 => { data_type => 'blob sub_type text character set unicode_fss' },
132 CREATE TABLE "Firebird_Loader_Test1" (
133 "Id" INTEGER NOT NULL PRIMARY KEY,
134 "Foo" INTEGER DEFAULT 42
138 CREATE GENERATOR "Gen_Firebird_Loader_Test1_Id"
141 CREATE TRIGGER "Firebird_Loader_Test1_BI" for "Firebird_Loader_Test1"
142 ACTIVE BEFORE INSERT POSITION 0
145 IF (NEW."Id" IS NULL) THEN
146 NEW."Id" = GEN_ID("Gen_Firebird_Loader_Test1_Id",1);
150 CREATE VIEW firebird_loader_test2 AS SELECT * FROM "Firebird_Loader_Test1"
154 'DROP VIEW firebird_loader_test2',
155 'DROP TRIGGER "Firebird_Loader_Test1_BI"',
156 'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"',
157 'DROP TABLE "Firebird_Loader_Test1"',
161 my ($monikers, $classes, $self) = @_;
163 my $dbh = $schema->storage->dbh;
165 # create a mixed case table
169 local $schema->loader->{preserve_case} = 1;
170 $schema->loader->_setup;
172 $self->rescan_without_warnings($schema);
174 ok ((my $rsrc = eval { $schema->resultset('FirebirdLoaderTest1')->result_source }),
175 'got rsrc for mixed case table');
177 ok ((my $col_info = eval { $rsrc->column_info('Id') }),
178 'got column_info for column Id');
180 is $col_info->{accessor}, 'id', 'column Id has lowercase accessor "id"';
182 is $col_info->{is_auto_increment}, 1, 'is_auto_increment detected for mixed case trigger';
184 is $col_info->{sequence}, 'Gen_Firebird_Loader_Test1_Id', 'correct mixed case sequence name';
186 is eval { $rsrc->column_info('Foo')->{default_value} }, 42, 'default_value detected for mixed case column';
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';
193 like $view_source->view_definition,
194 qr/\A \s* select\b .* \bfrom \s+ (?-i:"Firebird_Loader_Test1") \s* \z/imsx,
197 # test the fixed up ->_dbh_type_info_type_name for the ODBC driver
198 if ($schema->storage->_dbi_connect_info->[0] =~ /:ODBC:/i) {
199 my %truncated_types = (
201 -9 => 'VARCHAR(x) CHARACTER SET UNICODE_FSS',
202 -10 => 'BLOB SUB_TYPE TEXT CHARACTER SET UNICODE_FSS',
205 for my $type_num (keys %truncated_types) {
206 is $schema->loader->_dbh_type_info_type_name($type_num),
207 $truncated_types{$type_num},
208 "ODBC ->_dbh_type_info_type_name correct for '$truncated_types{$type_num}'";
212 my $tb = Test::More->builder;
213 $tb->skip('not testing _dbh_type_info_type_name on DBD::InterBase') for 1..3;
220 # get rid of stupid warning from InterBase/GetInfo.pm
221 if ($dsns{FIREBIRD_INTERBASE}) {
222 local $SIG{__WARN__} = sigwarn_silencer(
223 qr{^(?:Use of uninitialized value|Argument "[0-9_]+" isn't numeric|Missing argument) in sprintf at \S+DBD/InterBase/GetInfo.pm line \d+\.$}
225 require DBD::InterBase;
226 require DBD::InterBase::GetInfo;
229 $tester->run_tests();
232 # vim:et sts=4 sw=4 tw=0: