1 package dbixcsl_firebird_tests;
10 use base 'dbixcsl_common_tests';
13 my ($class, %opts) = @_;
15 return $class->next::method(
18 auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY',
20 my ($table, $col) = @_;
22 qq{ CREATE GENERATOR gen_${table}_${col} },
24 CREATE TRIGGER ${table}_bi FOR $table
25 ACTIVE BEFORE INSERT POSITION 0
28 IF (NEW.$col IS NULL) THEN
29 NEW.$col = GEN_ID(gen_${table}_${col},1);
34 auto_inc_drop_cb => sub {
35 my ($table, $col) = @_;
37 qq{ DROP TRIGGER ${table}_bi },
38 qq{ DROP GENERATOR gen_${table}_${col} },
42 preserve_case_mode_is_exclusive => 1,
45 # based on the Interbase Data Definition Guide
46 # http://www.ibphoenix.com/downloads/60DataDef.zip
49 'smallint' => { data_type => 'smallint' },
50 'int' => { data_type => 'integer' },
51 'integer' => { data_type => 'integer' },
52 'bigint' => { data_type => 'bigint' },
53 'float' => { data_type => 'real' },
56 data_type => 'double precision' },
57 'real' => { data_type => 'real' },
59 'float(2)' => { data_type => 'real' },
60 'float(7)' => { data_type => 'real' },
61 'float(8)' => { data_type => 'double precision' },
63 'decimal' => { data_type => 'decimal' },
64 'dec' => { data_type => 'decimal' },
65 'numeric' => { data_type => 'numeric' },
67 'decimal(3)' => { data_type => 'decimal', size => [3,0] },
69 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] },
70 'dec(3,3)' => { data_type => 'decimal', size => [3,3] },
71 'numeric(3,3)' => { data_type => 'numeric', size => [3,3] },
73 'decimal(6,3)' => { data_type => 'decimal', size => [6,3] },
74 'numeric(6,3)' => { data_type => 'numeric', size => [6,3] },
76 'decimal(12,3)' => { data_type => 'decimal', size => [12,3] },
77 'numeric(12,3)' => { data_type => 'numeric', size => [12,3] },
79 'decimal(18,18)' => { data_type => 'decimal', size => [18,18] },
80 'dec(18,18)' => { data_type => 'decimal', size => [18,18] },
81 'numeric(18,18)' => { data_type => 'numeric', size => [18,18] },
84 'date' => { data_type => 'date' },
85 'timestamp default current_timestamp'
86 => { data_type => 'timestamp', default_value => \'current_timestamp' },
87 'time' => { data_type => 'time' },
90 'char' => { data_type => 'char', size => 1 },
91 'char(11)' => { data_type => 'char', size => 11 },
92 'varchar(20)' => { data_type => 'varchar', size => 20 },
93 'char(22) character set unicode_fss' =>
94 => { data_type => 'char(x) character set unicode_fss', size => 22 },
95 'varchar(33) character set unicode_fss' =>
96 => { data_type => 'varchar(x) character set unicode_fss', size => 33 },
99 'blob' => { data_type => 'blob' },
101 => { data_type => 'blob sub_type text' },
102 'blob sub_type text character set unicode_fss'
103 => { data_type => 'blob sub_type text character set unicode_fss' },
109 CREATE TABLE "Firebird_Loader_Test1" (
110 "Id" INTEGER NOT NULL PRIMARY KEY,
111 "Foo" INTEGER DEFAULT 42
115 CREATE GENERATOR "Gen_Firebird_Loader_Test1_Id"
118 CREATE TRIGGER "Firebird_Loader_Test1_BI" for "Firebird_Loader_Test1"
119 ACTIVE BEFORE INSERT POSITION 0
122 IF (NEW."Id" IS NULL) THEN
123 NEW."Id" = GEN_ID("Gen_Firebird_Loader_Test1_Id",1);
127 CREATE VIEW firebird_loader_test2 AS SELECT * FROM "Firebird_Loader_Test1"
131 'DROP VIEW firebird_loader_test2',
132 'DROP TRIGGER "Firebird_Loader_Test1_BI"',
133 'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"',
134 'DROP TABLE "Firebird_Loader_Test1"',
137 my ($schema, $monikers, $classes, $self) = @_;
139 my $dbh = $schema->storage->dbh;
141 # create a mixed case table
145 local $schema->loader->{preserve_case} = 1;
146 $schema->loader->_setup;
148 $self->rescan_without_warnings($schema);
150 ok ((my $rsrc = eval { $schema->resultset('FirebirdLoaderTest1')->result_source }),
151 'got rsrc for mixed case table');
153 ok ((my $col_info = eval { $rsrc->column_info('Id') }),
154 'got column_info for column Id');
156 is $col_info->{accessor}, 'id', 'column Id has lowercase accessor "id"';
158 is $col_info->{is_auto_increment}, 1, 'is_auto_increment detected for mixed case trigger';
160 is $col_info->{sequence}, 'Gen_Firebird_Loader_Test1_Id', 'correct mixed case sequence name';
162 is eval { $rsrc->column_info('Foo')->{default_value} }, 42, 'default_value detected for mixed case column';
164 # test that views are marked as such
165 my $view_source = $schema->resultset($monikers->{firebird_loader_test2})->result_source;
166 isa_ok $view_source, 'DBIx::Class::ResultSource::View',
167 'view result source';
169 like $view_source->view_definition,
170 qr/\A \s* select\b .* \bfrom \s+ (?-i:"Firebird_Loader_Test1") \s* \z/imsx,
173 # test the fixed up ->_dbh_type_info_type_name for the ODBC driver
175 skip '_dbh_type_info_type_name test is only for DBD::ODBC', 3
176 unless $schema->storage->_dbi_connect_info->[0] =~ /:ODBC:/i;
178 my %truncated_types = (
180 -9 => 'VARCHAR(x) CHARACTER SET UNICODE_FSS',
181 -10 => 'BLOB SUB_TYPE TEXT CHARACTER SET UNICODE_FSS',
184 for my $type_num (keys %truncated_types) {
185 is $schema->loader->_dbh_type_info_type_name($type_num),
186 $truncated_types{$type_num},
187 "ODBC ->_dbh_type_info_type_name correct for '$truncated_types{$type_num}'";
197 # vim:et sts=4 sw=4 tw=0: