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