Quoting fixes for single-table ops
[dbsrgits/DBIx-Class.git] / t / 19quotes.t
1 use strict;
2 use Test::More;
3 use IO::File;
4
5 BEGIN {
6     eval "use DBD::SQLite";
7     plan $@
8         ? ( skip_all => 'needs DBD::SQLite for testing' )
9         : ( tests => 7 );
10 }
11
12 use lib qw(t/lib);
13
14 use_ok('DBICTest');
15
16 use_ok('DBICTest::HelperRels');
17
18 DBICTest->schema->storage->sql_maker->quote_char("'");
19 DBICTest->schema->storage->sql_maker->name_sep('.');
20
21 my $rs = DBICTest::CD->search(
22            { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
23            { join => 'artist' });
24
25 cmp_ok( $rs->count, '==', 1, "join with fields quoted");
26
27 $rs = DBICTest::CD->search({},
28             { 'order_by' => 'year DESC'});
29 {
30        my $warnings;
31        local $SIG{__WARN__} = sub { $warnings .= $_[0] };
32        my $first = eval{ $rs->first() };
33        ok( $warnings =~ /ORDER BY terms/, "Problem with ORDER BY quotes" );
34 }
35
36 my $order = 'year DESC';
37 $rs = DBICTest::CD->search({},
38             { 'order_by' => \$order });
39 {
40        my $warnings;
41        local $SIG{__WARN__} = sub { $warnings .= $_[0] };
42        my $first = $rs->first();
43        ok( $warnings !~ /ORDER BY terms/,
44             "No problem handling ORDER by scalaref" );
45 }
46
47 DBICTest->schema->storage->sql_maker->quote_char([qw/[ ]/]);
48 DBICTest->schema->storage->sql_maker->name_sep('.');
49
50 $rs = DBICTest::CD->search(
51            { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
52            { join => 'artist' });
53 cmp_ok($rs->count,'==', 1,"join quoted with brackets.");
54
55 my %data = (
56        name => 'Bill',
57        order => '12'
58 );
59
60 DBICTest->schema->storage->sql_maker->quote_char('`');
61 DBICTest->schema->storage->sql_maker->name_sep('.');
62
63 cmp_ok(DBICTest->schema->storage->sql_maker->update('group', \%data), 'eq', 'UPDATE `group` SET `name` = ?, `order` = ?', "quoted table names for UPDATE");
64