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