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