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