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