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