8 eval "use DBD::SQLite";
10 ? ( skip_all => 'needs DBD::SQLite for testing' )
17 my $schema = DBICTest->init_schema();
19 my $orig_debugcb = $schema->storage->debugcb;
20 my $orig_debug = $schema->storage->debug;
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('.');
29 $schema->storage->debugcb(sub { $sql = $_[1] });
30 $schema->storage->debug(1);
34 $rs = $schema->resultset('CD')->search(
35 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
36 { join => 'artist' });
38 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');
40 my $order = 'year DESC';
41 $rs = $schema->resultset('CD')->search({},
42 { 'order_by' => $order });
44 like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)');
46 $rs = $schema->resultset('CD')->search({},
47 { 'order_by' => \$order });
49 like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
51 $schema->storage->sql_maker->quote_char([qw/[ ]/]);
52 $schema->storage->sql_maker->name_sep('.');
54 $rs = $schema->resultset('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 $schema->storage->sql_maker->quote_char('`');
66 $schema->storage->sql_maker->name_sep('.');
68 is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');
70 $schema->storage->debugcb($orig_debugcb);
71 $schema->storage->debug($orig_debug);