Commit | Line | Data |
2a816814 |
1 | use strict; |
58d387fe |
2 | use warnings; |
3 | |
2a816814 |
4 | use Test::More; |
c61a0748 |
5 | |
6 | use lib qw(t/lib); |
5e724964 |
7 | use DBICTest; |
949172b0 |
8 | use DBIC::SqlMakerTest; |
5e724964 |
9 | use DBIC::DebugObj; |
2a816814 |
10 | |
c216324a |
11 | my $schema = DBICTest->init_schema(); |
22b15c96 |
12 | |
02a2db55 |
13 | $schema->connection( |
14 | @{ $schema->storage->_dbi_connect_info }, |
15 | { AutoCommit => 1, quote_char => [qw/[ ]/] } |
16 | ); |
2a816814 |
17 | |
af6aac2d |
18 | my ($sql, @bind); |
67e1ac6d |
19 | $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)); |
c216324a |
20 | $schema->storage->debug(1); |
5a1f2d73 |
21 | |
02a2db55 |
22 | my $rs = $schema->resultset('CD')->search( |
54540863 |
23 | { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, |
2a816814 |
24 | { join => 'artist' }); |
02a2db55 |
25 | my $expected_bind = ["'Caterwauler McCrae'", "'2001'"]; |
26 | eval { $rs->count }; |
27 | is_same_sql_bind( |
28 | $sql, \@bind, |
29 | "SELECT COUNT( * ) FROM cd [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )", |
30 | $expected_bind, |
31 | 'got correct SQL for count query with bracket quoting' |
32 | ); |
33 | |
34 | $schema->storage->sql_maker->quote_char('`'); |
35 | $schema->storage->sql_maker->name_sep('.'); |
36 | |
5a1f2d73 |
37 | eval { $rs->count }; |
9b459129 |
38 | is_same_sql_bind( |
a258ee5d |
39 | $sql, \@bind, |
02a2db55 |
40 | "SELECT COUNT( * ) FROM cd `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", |
41 | $expected_bind, |
a258ee5d |
42 | 'got correct SQL for count query with quoting' |
9b459129 |
43 | ); |
2a816814 |
44 | |
5a1f2d73 |
45 | my $order = 'year DESC'; |
c216324a |
46 | $rs = $schema->resultset('CD')->search({}, |
5a1f2d73 |
47 | { 'order_by' => $order }); |
48 | eval { $rs->first }; |
49 | like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)'); |
e535069e |
50 | |
c216324a |
51 | $rs = $schema->resultset('CD')->search({}, |
e535069e |
52 | { 'order_by' => \$order }); |
5a1f2d73 |
53 | eval { $rs->first }; |
54 | like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref'); |
e535069e |
55 | |
02a2db55 |
56 | is( |
57 | $schema->storage->sql_maker->update('group', { name => 'Bill', order => 12 }), |
58 | 'UPDATE `group` SET `name` = ?, `order` = ?', |
59 | 'quoted table names for UPDATE' ); |
56166f36 |
60 | |
61 | done_testing; |