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