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' });
45 "SELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"],
46 'got correct SQL for count query with quoting'
49 my $order = 'year DESC';
50 $rs = $schema->resultset('CD')->search({},
51 { 'order_by' => $order });
53 like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)');
55 $rs = $schema->resultset('CD')->search({},
56 { 'order_by' => \$order });
58 like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
64 { AutoCommit => 1, quote_char => [qw/[ ]/], name_sep => '.' }
67 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)),
68 $schema->storage->debug(1);
70 $rs = $schema->resultset('CD')->search(
71 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
72 { join => 'artist' });
76 "SELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )", ["'Caterwauler McCrae'", "'2001'"],
77 'got correct SQL for count query with bracket quoting'
89 { AutoCommit => 1, quote_char => '`', name_sep => '.' }
92 is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');