Commit | Line | Data |
2a816814 |
1 | use strict; |
58d387fe |
2 | use warnings; |
3 | |
2a816814 |
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' ) |
58d387fe |
11 | : ( tests => 6 ); |
2a816814 |
12 | } |
13 | |
14 | use lib qw(t/lib); |
15 | |
16 | use_ok('DBICTest'); |
c216324a |
17 | my $schema = DBICTest->init_schema(); |
22b15c96 |
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/)); |
5a1f2d73 |
23 | |
c216324a |
24 | $schema->storage->sql_maker->quote_char('`'); |
25 | $schema->storage->sql_maker->name_sep('.'); |
2a816814 |
26 | |
5a1f2d73 |
27 | my $sql = ''; |
28 | |
c216324a |
29 | $schema->storage->debugcb(sub { $sql = $_[1] }); |
30 | $schema->storage->debug(1); |
5a1f2d73 |
31 | |
32 | my $rs; |
33 | |
c216324a |
34 | $rs = $schema->resultset('CD')->search( |
54540863 |
35 | { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, |
2a816814 |
36 | { join => 'artist' }); |
5a1f2d73 |
37 | eval { $rs->count }; |
38 | 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'); |
2a816814 |
39 | |
5a1f2d73 |
40 | my $order = 'year DESC'; |
c216324a |
41 | $rs = $schema->resultset('CD')->search({}, |
5a1f2d73 |
42 | { 'order_by' => $order }); |
43 | eval { $rs->first }; |
44 | like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)'); |
e535069e |
45 | |
c216324a |
46 | $rs = $schema->resultset('CD')->search({}, |
e535069e |
47 | { 'order_by' => \$order }); |
5a1f2d73 |
48 | eval { $rs->first }; |
49 | like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref'); |
e535069e |
50 | |
c216324a |
51 | $schema->storage->sql_maker->quote_char([qw/[ ]/]); |
52 | $schema->storage->sql_maker->name_sep('.'); |
2437a1e3 |
53 | |
c216324a |
54 | $rs = $schema->resultset('CD')->search( |
2437a1e3 |
55 | { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, |
56 | { join => 'artist' }); |
5a1f2d73 |
57 | eval { $rs->count }; |
58 | 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'); |
2437a1e3 |
59 | |
6346a152 |
60 | my %data = ( |
61 | name => 'Bill', |
62 | order => '12' |
63 | ); |
2437a1e3 |
64 | |
c216324a |
65 | $schema->storage->sql_maker->quote_char('`'); |
66 | $schema->storage->sql_maker->name_sep('.'); |
2437a1e3 |
67 | |
c216324a |
68 | is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE'); |
2437a1e3 |
69 | |
c216324a |
70 | $schema->storage->debugcb($orig_debugcb); |
71 | $schema->storage->debug($orig_debug); |