1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
8 use DBIx::Class::_Util 'dump_value';
9 $Data::Dumper::Indent = 0;
12 'DBIx::Class::Storage::DBI' =>
13 # no default quote_char
16 'DBIx::Class::Storage::DBI::MSSQL' =>
17 { quote_char => [ '[', ']' ], name_sep => '.' },
19 'DBIx::Class::Storage::DBI::DB2' =>
20 { quote_char => '"', name_sep => '.' },
22 'DBIx::Class::Storage::DBI::Informix' =>
23 { quote_char => '"', name_sep => '.' },
25 'DBIx::Class::Storage::DBI::InterBase' =>
26 { quote_char => '"', name_sep => '.' },
28 'DBIx::Class::Storage::DBI::mysql' =>
29 { quote_char => '`', name_sep => '.' },
31 'DBIx::Class::Storage::DBI::Pg' =>
32 { quote_char => '"', name_sep => '.' },
34 'DBIx::Class::Storage::DBI::ODBC::ACCESS' =>
35 { quote_char => [ '[', ']' ], name_sep => '.' },
37 # Not testing this one, it's a pain.
38 # 'DBIx::Class::Storage::DBI::ODBC::DB2_400_SQL' =>
39 # { quote_char => '"', name_sep => qr/must be connected/ },
41 'DBIx::Class::Storage::DBI::Oracle::Generic' =>
42 { quote_char => '"', name_sep => '.' },
44 'DBIx::Class::Storage::DBI::SQLAnywhere' =>
45 { quote_char => '"', name_sep => '.' },
47 'DBIx::Class::Storage::DBI::SQLite' =>
48 { quote_char => '"', name_sep => '.' },
50 'DBIx::Class::Storage::DBI::Sybase::ASE' =>
51 { quote_char => [ '[', ']' ], name_sep => '.' },
54 for my $class (keys %expected) { SKIP: {
56 eval "require ${class}" or do {
57 note "Failed load of $class:\n\n$@\n\n";
58 skip "Skipping test of quotes for $class due to missing compile-time dependencies", 1;
61 my $mapping = $expected{$class};
62 my ($quote_char, $name_sep) = @$mapping{qw/quote_char name_sep/};
63 my $instance = $class->new;
65 my $quote_char_text = dump_value $quote_char;
67 if (exists $mapping->{quote_char}) {
68 is_deeply $instance->sql_quote_char, $quote_char,
69 "sql_quote_char for $class is $quote_char_text";
72 is $instance->sql_name_sep, $name_sep,
73 "sql_name_sep for $class is '$name_sep'";
76 # Try quote_names with available DBs.
78 # Env var to base class mapping, these are the DBs I actually have.
79 # the SQLITE is a fake memory dsn
80 local $ENV{DBICTEST_SQLITE_DSN} = 'dbi:SQLite::memory:';
82 SQLITE => 'DBIx::Class::Storage::DBI::SQLite',
83 ORA => 'DBIx::Class::Storage::DBI::Oracle::Generic',
84 PG => 'DBIx::Class::Storage::DBI::Pg',
85 MYSQL => 'DBIx::Class::Storage::DBI::mysql',
86 DB2 => 'DBIx::Class::Storage::DBI::DB2',
87 SYBASE => 'DBIx::Class::Storage::DBI::Sybase::ASE',
88 SQLANYWHERE => 'DBIx::Class::Storage::DBI::SQLAnywhere',
89 SQLANYWHERE_ODBC => 'DBIx::Class::Storage::DBI::SQLAnywhere',
90 FIREBIRD => 'DBIx::Class::Storage::DBI::InterBase',
91 FIREBIRD_ODBC => 'DBIx::Class::Storage::DBI::InterBase',
92 INFORMIX => 'DBIx::Class::Storage::DBI::Informix',
93 MSSQL_ODBC => 'DBIx::Class::Storage::DBI::MSSQL',
96 # lie that we already locked stuff - the tests below do not touch anything
97 # unless we are under travis, where the OOM killers reign and things are rough
98 $ENV{DBICTEST_LOCK_HOLDER} = -1
99 unless DBICTest::RunMode->is_ci;
101 # Make sure oracle is tried last - some clients (e.g. 10.2) have symbol
102 # clashes with libssl, and will segfault everything coming after them
108 my ($dsn, $user, $pass) = map $ENV{"DBICTEST_${db}_$_"}, qw/DSN USER PASS/;
114 my $sql_maker = eval {
115 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
118 $schema->storage->ensure_connected;
119 $schema->storage->sql_maker;
122 my ($exp_quote_char, $exp_name_sep) =
123 @{$expected{$dbs{$db}}}{qw/quote_char name_sep/};
125 my ($quote_char_text, $name_sep_text) = map { dump_value $_ }
126 ($exp_quote_char, $exp_name_sep);
128 is_deeply $sql_maker->quote_char,
130 "$db quote_char with quote_names => 1 is $quote_char_text";
133 is $sql_maker->name_sep,
135 "$db name_sep with quote_names => 1 is $name_sep_text";
137 # if something was produced - it better be quoted
139 # the SQLT producer has no idea what quotes are :/
140 ! grep { $db eq $_ } qw( SYBASE DB2 )
142 my $ddl = eval { $schema->deployment_statements }
144 my $quoted_artist = $sql_maker->_quote('artist');
146 like ($ddl, qr/^CREATE\s+TABLE\s+\Q$quoted_artist/msi, "$db DDL contains expected quoted table name");