8 use DBIC::SqlMakerTest;
11 eval "use DBD::SQLite";
13 ? ( skip_all => 'needs DBD::SQLite for testing' )
19 use_ok('DBIC::DebugObj');
20 my $schema = DBICTest->init_schema();
22 #diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/));
24 $schema->storage->sql_maker->quote_char('`');
25 $schema->storage->sql_maker->name_sep('.');
27 my ($sql, @bind) = ('');
28 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
29 $schema->storage->debug(1);
33 $rs = $schema->resultset('CD')->search(
34 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
35 { join => 'artist' });
40 "SELECT COUNT( * ) FROM (SELECT `me`.`cdid` FROM `cd` `me` JOIN `artist` `artist` ON `artist`.`artistid` = `me`.`artist` WHERE ( ( `artist`.`name` = ? AND `me`.`year` = ? ) ) GROUP BY `me`.`cdid`) `count_subq`",
41 ["'Caterwauler McCrae'", "'2001'"],
43 'got correct SQL for joined count query with quoting'
46 my $order = 'year DESC';
47 $rs = $schema->resultset('CD')->search({},
48 { 'order_by' => $order });
50 like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)');
52 $rs = $schema->resultset('CD')->search({},
53 { 'order_by' => \$order });
55 like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
57 $schema->storage->sql_maker->quote_char([qw/[ ]/]);
58 $schema->storage->sql_maker->name_sep('.');
60 $rs = $schema->resultset('CD')->search(
61 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
62 { join => 'artist' });
67 "SELECT COUNT( * ) FROM (SELECT [me].[cdid] FROM [cd] [me] JOIN [artist] [artist] ON [artist].[artistid] = [me].[artist] WHERE ( ( [artist].[name] = ? AND [me].[year] = ? ) ) GROUP BY [me].[cdid]) [count_subq]",
68 ["'Caterwauler McCrae'", "'2001'"],
69 'got correct SQL for count query with bracket quoting'
77 $schema->storage->sql_maker->quote_char('`');
78 $schema->storage->sql_maker->name_sep('.');
80 is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');