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