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 my $dsn = $schema->storage->connect_info->[0];
30 { quote_char => '`', name_sep => '.' },
34 $schema->storage->debugcb(sub { $sql = $_[1] });
35 $schema->storage->debug(1);
39 $rs = $schema->resultset('CD')->search(
40 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
41 { join => 'artist' });
43 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');
45 my $order = 'year DESC';
46 $rs = $schema->resultset('CD')->search({},
47 { 'order_by' => $order });
49 like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)');
51 $rs = $schema->resultset('CD')->search({},
52 { 'order_by' => \$order });
54 like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
60 { AutoCommit => 1, quote_char => [qw/[ ]/], name_sep => '.' }
62 $schema->storage->debugcb(sub { $sql = $_[1] });
63 $schema->storage->debug(1);
65 $rs = $schema->resultset('CD')->search(
66 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
67 { join => 'artist' });
69 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');
80 { AutoCommit => 1, quote_char => '`', name_sep => '.' }
83 is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');
85 $schema->storage->debugcb($orig_debugcb);
86 $schema->storage->debug($orig_debug);