multi-dsn support for common tests
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 18firebird_common.t
CommitLineData
4cbddf8d 1use strict;
3a89a69f 2use warnings;
3use Test::More;
4use Scope::Guard ();
4cbddf8d 5use lib qw(t/lib);
6use dbixcsl_common_tests;
7
3a89a69f 8my $dbd_interbase_dsn = $ENV{DBICTEST_FIREBIRD_DSN} || '';
9my $dbd_interbase_user = $ENV{DBICTEST_FIREBIRD_USER} || '';
10my $dbd_interbase_password = $ENV{DBICTEST_FIREBIRD_PASS} || '';
11
12my $odbc_dsn = $ENV{DBICTEST_FIREBIRD_ODBC_DSN} || '';
13my $odbc_user = $ENV{DBICTEST_FIREBIRD_ODBC_USER} || '';
14my $odbc_password = $ENV{DBICTEST_FIREBIRD_ODBC_PASS} || '';
15
16my $schema;
4cbddf8d 17
18my $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 => '',
18e84656 44 loader_options => { unquoted_ddl => 1 },
3a89a69f 45 connect_info => [ ($dbd_interbase_dsn ? {
46 dsn => $dbd_interbase_dsn,
47 user => $dbd_interbase_user,
48 password => $dbd_interbase_password,
49 connect_info_opts => { on_connect_call => 'use_softcommit' },
50 } : ()),
51 ($odbc_dsn ? {
52 dsn => $odbc_dsn,
53 user => $odbc_user,
54 password => $odbc_password,
55 } : ()),
56 ],
57 extra => {
58 count => 6,
59 run => sub {
60 $schema = shift;
61
62 cleanup_extra();
63
64 my $dbh = $schema->storage->dbh;
65
66# create a mixed case table
67 $dbh->do($_) for (
68q{
69 CREATE TABLE "Firebird_Loader_Test1" (
70 "Id" INTEGER NOT NULL PRIMARY KEY,
71 "Foo" INTEGER DEFAULT 42
72 )
73},
74q{
75 CREATE GENERATOR "Gen_Firebird_Loader_Test1_Id"
76},
77q{
78 CREATE TRIGGER "Firebird_Loader_Test1_BI" for "Firebird_Loader_Test1"
79 ACTIVE BEFORE INSERT POSITION 0
80 AS
81 BEGIN
82 IF (NEW."Id" IS NULL) THEN
83 NEW."Id" = GEN_ID("Gen_Firebird_Loader_Test1_Id",1);
84 END
85},
86 );
87
88 my $guard = Scope::Guard->new(\&cleanup_extra);
89
90 $schema->_loader->{unquoted_ddl} = 0;
91 $schema->_loader->_setup;
92 {
93 local $SIG{__WARN__} = sub {};
94 $schema->rescan;
95 }
96
97 ok ((my $rsrc = eval { $schema->resultset('FirebirdLoaderTest1')->result_source }),
98 'got rsrc for mixed case table');
99
100 ok ((my $col_info = eval { $rsrc->column_info('Id') }),
101 'got column_info for column Id');
102
103 is $col_info->{accessor}, 'id', 'column Id has lowercase accessor "id"';
104
105 is $col_info->{is_auto_increment}, 1, 'is_auto_increment detected for mixed case trigger';
106
107 is $col_info->{sequence}, 'Gen_Firebird_Loader_Test1_Id', 'correct mixed case sequence name';
108
109 is eval { $rsrc->column_info('Foo')->{default_value} }, 42, 'default_value detected for mixed case column';
110 },
111 },
4cbddf8d 112);
113
3a89a69f 114if (not ($dbd_interbase_dsn || $odbc_dsn)) {
115 $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 116}
117else {
4145a6f3 118 # get rid of stupid warning from InterBase/GetInfo.pm
3a89a69f 119 if ($dbd_interbase_dsn) {
4145a6f3 120 local $SIG{__WARN__} = sub {};
121 require DBD::InterBase;
122 require DBD::InterBase::GetInfo;
123 }
4cbddf8d 124 $tester->run_tests();
125}
3a89a69f 126
127sub cleanup_extra {
128 $schema->storage->disconnect;
129 my $dbh = $schema->storage->dbh;
130
131 foreach my $stmt (
132 'DROP TRIGGER "Firebird_Loader_Test1_BI"',
133 'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"',
134 'DROP TABLE "Firebird_Loader_Test1"',
135 ) {
136 eval { $dbh->do($stmt) };
137 }
138}