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