8 eval "use DBD::SQLite";
10 ? ( skip_all => 'needs DBD::SQLite for testing' )
17 DBICTest->init_schema();
19 my $orig_debugcb = DBICTest->schema->storage->debugcb;
20 my $orig_debug = DBICTest->schema->storage->debug;
22 diag('Testing against ' . join(' ', map { DBICTest->schema->storage->dbh->get_info($_) } qw/17 18/));
24 my $dsn = DBICTest->schema->storage->connect_info->[0];
25 DBICTest->schema->connection($dsn, { quote_char => '`', name_sep => '.' });
28 DBICTest->schema->storage->debugcb(sub { $sql = $_[1] });
29 DBICTest->schema->storage->debug(1);
33 $rs = DBICTest::CD->search(
34 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
35 { join => 'artist' });
37 like($sql, qr/\QSELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )\E/, 'got correct SQL for count query with quoting');
39 my $order = 'year DESC';
40 $rs = DBICTest::CD->search({},
41 { 'order_by' => $order });
43 like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)');
45 $rs = DBICTest::CD->search({},
46 { 'order_by' => \$order });
48 like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
50 DBICTest->schema->connection($dsn, { quote_char => [qw/[ ]/], name_sep => '.' });
51 DBICTest->schema->storage->debugcb(sub { $sql = $_[1] });
52 DBICTest->schema->storage->debug(1);
54 $rs = DBICTest::CD->search(
55 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
56 { join => 'artist' });
58 like($sql, qr/\QSELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )\E/, 'got correct SQL for count query with bracket quoting');
65 DBICTest->schema->connection($dsn, { quote_char => '`', name_sep => '.' });
67 is(DBICTest->schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');
69 DBICTest->schema->storage->debugcb($orig_debugcb);
70 DBICTest->schema->storage->debug($orig_debug);