fixed regex in t/76joins (was relying on a 5.8.8 bug that is fixed in bleadperl,...
[dbsrgits/DBIx-Class.git] / t / 19quotes_newstyle.t
CommitLineData
2cc3a7be 1use strict;
2use warnings;
3
4use Test::More;
5use IO::File;
6
7BEGIN {
8 eval "use DBD::SQLite";
9 plan $@
10 ? ( skip_all => 'needs DBD::SQLite for testing' )
11 : ( tests => 6 );
12}
13
14use lib qw(t/lib);
15
16use_ok('DBICTest');
17DBICTest->init_schema();
18
5a1f2d73 19my $orig_debugcb = DBICTest->schema->storage->debugcb;
20my $orig_debug = DBICTest->schema->storage->debug;
21
22diag('Testing against ' . join(' ', map { DBICTest->schema->storage->dbh->get_info($_) } qw/17 18/));
2cc3a7be 23
5a1f2d73 24my $dsn = DBICTest->schema->storage->connect_info->[0];
02af104d 25DBICTest->schema->connection($dsn, { quote_char => '`', name_sep => '.' });
2cc3a7be 26
5a1f2d73 27my $sql = '';
28DBICTest->schema->storage->debugcb(sub { $sql = $_[1] });
29DBICTest->schema->storage->debug(1);
30
31my $rs;
32
33$rs = DBICTest::CD->search(
2cc3a7be 34 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
35 { join => 'artist' });
5a1f2d73 36eval { $rs->count };
37like($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 38
5a1f2d73 39my $order = 'year DESC';
2cc3a7be 40$rs = DBICTest::CD->search({},
5a1f2d73 41 { 'order_by' => $order });
42eval { $rs->first };
43like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)');
2cc3a7be 44
2cc3a7be 45$rs = DBICTest::CD->search({},
46 { 'order_by' => \$order });
5a1f2d73 47eval { $rs->first };
48like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
2cc3a7be 49
50DBICTest->schema->connection($dsn, { quote_char => [qw/[ ]/], name_sep => '.' });
5a1f2d73 51DBICTest->schema->storage->debugcb(sub { $sql = $_[1] });
52DBICTest->schema->storage->debug(1);
2cc3a7be 53
54$rs = DBICTest::CD->search(
55 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
56 { join => 'artist' });
5a1f2d73 57eval { $rs->count };
58like($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 59
60my %data = (
61 name => 'Bill',
62 order => '12'
63);
64
65DBICTest->schema->connection($dsn, { quote_char => '`', name_sep => '.' });
66
5a1f2d73 67is(DBICTest->schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');
2cc3a7be 68
5a1f2d73 69DBICTest->schema->storage->debugcb($orig_debugcb);
70DBICTest->schema->storage->debug($orig_debug);