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' });
39 "SELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"],
40 'got correct SQL for count query with quoting'
43 my $order = 'year DESC';
44 $rs = $schema->resultset('CD')->search({},
45 { 'order_by' => $order });
47 like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)');
49 $rs = $schema->resultset('CD')->search({},
50 { 'order_by' => \$order });
52 like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
54 $schema->storage->sql_maker->quote_char([qw/[ ]/]);
55 $schema->storage->sql_maker->name_sep('.');
57 $rs = $schema->resultset('CD')->search(
58 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
59 { join => 'artist' });
63 "SELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )", ["'Caterwauler McCrae'", "'2001'"],
64 'got correct SQL for count query with bracket quoting'
72 $schema->storage->sql_maker->quote_char('`');
73 $schema->storage->sql_maker->name_sep('.');
75 is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');