Commit | Line | Data |
2cc3a7be |
1 | use strict; |
2 | use warnings; |
3 | |
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; |
2cc3a7be |
10 | |
9b459129 |
11 | my $schema = DBICTest->init_schema(); |
5a1f2d73 |
12 | |
ee3bc4ea |
13 | my $dsn = $schema->storage->_dbi_connect_info->[0]; |
77d76d0f |
14 | $schema->connection( |
15 | $dsn, |
16 | undef, |
17 | undef, |
18 | { AutoCommit => 1 }, |
19 | { quote_char => '`', name_sep => '.' }, |
20 | ); |
2cc3a7be |
21 | |
af6aac2d |
22 | my ($sql, @bind); |
67e1ac6d |
23 | $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)), |
c216324a |
24 | $schema->storage->debug(1); |
5a1f2d73 |
25 | |
26 | my $rs; |
27 | |
c216324a |
28 | $rs = $schema->resultset('CD')->search( |
2cc3a7be |
29 | { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, |
30 | { join => 'artist' }); |
5a1f2d73 |
31 | eval { $rs->count }; |
9b459129 |
32 | is_same_sql_bind( |
a258ee5d |
33 | $sql, \@bind, |
cebb7cce |
34 | "SELECT COUNT( * ) FROM cd `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"], |
9b459129 |
35 | 'got correct SQL for count query with quoting' |
36 | ); |
2cc3a7be |
37 | |
5a1f2d73 |
38 | my $order = 'year DESC'; |
c216324a |
39 | $rs = $schema->resultset('CD')->search({}, |
5a1f2d73 |
40 | { 'order_by' => $order }); |
41 | eval { $rs->first }; |
42 | like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)'); |
2cc3a7be |
43 | |
c216324a |
44 | $rs = $schema->resultset('CD')->search({}, |
2cc3a7be |
45 | { 'order_by' => \$order }); |
5a1f2d73 |
46 | eval { $rs->first }; |
47 | like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref'); |
2cc3a7be |
48 | |
77d76d0f |
49 | $schema->connection( |
50 | $dsn, |
51 | undef, |
52 | undef, |
53 | { AutoCommit => 1, quote_char => [qw/[ ]/], name_sep => '.' } |
54 | ); |
9b459129 |
55 | |
67e1ac6d |
56 | $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)), |
c216324a |
57 | $schema->storage->debug(1); |
2cc3a7be |
58 | |
c216324a |
59 | $rs = $schema->resultset('CD')->search( |
2cc3a7be |
60 | { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, |
61 | { join => 'artist' }); |
5a1f2d73 |
62 | eval { $rs->count }; |
9b459129 |
63 | is_same_sql_bind( |
a258ee5d |
64 | $sql, \@bind, |
cebb7cce |
65 | "SELECT COUNT( * ) FROM cd [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )", ["'Caterwauler McCrae'", "'2001'"], |
9b459129 |
66 | 'got correct SQL for count query with bracket quoting' |
67 | ); |
2cc3a7be |
68 | |
69 | my %data = ( |
70 | name => 'Bill', |
71 | order => '12' |
72 | ); |
73 | |
77d76d0f |
74 | $schema->connection( |
75 | $dsn, |
76 | undef, |
77 | undef, |
78 | { AutoCommit => 1, quote_char => '`', name_sep => '.' } |
79 | ); |
2cc3a7be |
80 | |
c216324a |
81 | is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE'); |
56166f36 |
82 | |
83 | done_testing; |