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; |
2a816814 |
9 | |
2cfc22dd |
10 | my $schema = DBICTest->init_schema( no_deploy => 1 ); |
22b15c96 |
11 | |
02a2db55 |
12 | $schema->connection( |
13 | @{ $schema->storage->_dbi_connect_info }, |
14 | { AutoCommit => 1, quote_char => [qw/[ ]/] } |
15 | ); |
2a816814 |
16 | |
2cfc22dd |
17 | my $rs = $schema->resultset('CD')->search( |
18 | { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, |
19 | { join => 'artist' } |
20 | )->count_rs; |
21 | |
22 | my $expected_bind = [ |
23 | [ { dbic_colname => "artist.name", sqlt_datatype => "varchar", sqlt_size => 100 } |
24 | => 'Caterwauler McCrae' ], |
25 | [ { dbic_colname => "me.year", sqlt_datatype => "varchar", sqlt_size => 100 } |
26 | => 2001 ], |
27 | ]; |
5a1f2d73 |
28 | |
02a2db55 |
29 | is_same_sql_bind( |
2cfc22dd |
30 | $rs->as_query, |
31 | "(SELECT COUNT( * ) FROM cd [me] JOIN [artist] [artist] ON [artist].[artistid] = [me].[artist] WHERE ( [artist].[name] = ? AND [me].[year] = ? ))", |
02a2db55 |
32 | $expected_bind, |
33 | 'got correct SQL for count query with bracket quoting' |
34 | ); |
35 | |
36 | $schema->storage->sql_maker->quote_char('`'); |
37 | $schema->storage->sql_maker->name_sep('.'); |
38 | |
2cfc22dd |
39 | is_same_sql_bind ( |
40 | $rs->as_query, |
41 | "(SELECT COUNT( * ) FROM cd `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? ))", |
02a2db55 |
42 | $expected_bind, |
2cfc22dd |
43 | 'got correct SQL for count query with mysql quoting' |
9b459129 |
44 | ); |
2a816814 |
45 | |
2cfc22dd |
46 | # !!! talk to ribasushi *explicitly* before modfying these tests !!! |
47 | { |
48 | is_same_sql_bind( |
49 | $schema->resultset('CD')->search({}, { order_by => 'year DESC', columns => 'cdid' })->as_query, |
50 | '(SELECT `me`.`cdid` FROM cd `me` ORDER BY `year DESC`)', |
51 | [], |
52 | 'quoted ORDER BY with DESC (should use a scalarref anyway)' |
53 | ); |
e535069e |
54 | |
2cfc22dd |
55 | is_same_sql_bind( |
56 | $schema->resultset('CD')->search({}, { order_by => \'year DESC', columns => 'cdid' })->as_query, |
57 | '(SELECT `me`.`cdid` FROM cd `me` ORDER BY year DESC)', |
58 | [], |
59 | 'did not quote ORDER BY with scalarref', |
60 | ); |
61 | } |
e535069e |
62 | |
2cfc22dd |
63 | is_same_sql( |
64 | scalar $schema->storage->sql_maker->update('group', { order => 12, name => 'Bill' }), |
02a2db55 |
65 | 'UPDATE `group` SET `name` = ?, `order` = ?', |
66 | 'quoted table names for UPDATE' ); |
56166f36 |
67 | |
68 | done_testing; |