8 use DBIC::SqlMakerTest;
11 eval "use DBD::SQLite";
13 ? ( skip_all => 'needs DBD::SQLite for testing' )
18 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 my $dsn = $schema->storage->_dbi_connect_info->[0];
30 { quote_char => '`', name_sep => '.' },
33 my ($sql, @bind) = ('');
34 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)),
35 $schema->storage->debug(1);
39 $rs = $schema->resultset('CD')->search(
40 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
41 { join => 'artist' });
46 "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`",
47 ["'Caterwauler McCrae'", "'2001'"],
48 'got correct SQL for count query with quoting'
51 my $order = 'year DESC';
52 $rs = $schema->resultset('CD')->search({},
53 { 'order_by' => $order });
55 like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)');
57 $rs = $schema->resultset('CD')->search({},
58 { 'order_by' => \$order });
60 like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
66 { AutoCommit => 1, quote_char => [qw/[ ]/], name_sep => '.' }
69 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)),
70 $schema->storage->debug(1);
72 $rs = $schema->resultset('CD')->search(
73 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
74 { join => 'artist' });
79 "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]",
80 ["'Caterwauler McCrae'", "'2001'"],
81 'got correct SQL for count query with bracket quoting'
93 { AutoCommit => 1, quote_char => '`', name_sep => '.' }
96 is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');