ad44bcb55086b3ca0a69b67af0fdc7c5abd651fd
[dbsrgits/DBIx-Class.git] / t / 19quotes.t
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');
17 DBICTest->init_schema();
18
19 DBICTest->schema->storage->sql_maker->quote_char("'");
20 DBICTest->schema->storage->sql_maker->name_sep('.');
21
22 my $rs = DBICTest::CD->search(
23            { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
24            { join => 'artist' });
25
26 cmp_ok( $rs->count, '==', 1, "join with fields quoted");
27
28 $rs = DBICTest::CD->search({},
29             { 'order_by' => 'year DESC'});
30 {
31        my $warnings = '';
32        local $SIG{__WARN__} = sub { $warnings .= $_[0] };
33        my $first = eval{ $rs->first() };
34        like( $warnings, qr/ORDER BY terms/, "Problem with ORDER BY quotes" );
35 }
36
37 my $order = 'year DESC';
38 $rs = DBICTest::CD->search({},
39             { 'order_by' => \$order });
40 {
41        my $warnings = '';
42        local $SIG{__WARN__} = sub { $warnings .= $_[0] };
43        my $first = $rs->first();
44        ok( $warnings !~ /ORDER BY terms/,
45             "No problem handling ORDER by scalaref" );
46 }
47
48 DBICTest->schema->storage->sql_maker->quote_char([qw/[ ]/]);
49 DBICTest->schema->storage->sql_maker->name_sep('.');
50
51 $rs = DBICTest::CD->search(
52            { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
53            { join => 'artist' });
54 cmp_ok($rs->count,'==', 1,"join quoted with brackets.");
55
56 my %data = (
57        name => 'Bill',
58        order => '12'
59 );
60
61 DBICTest->schema->storage->sql_maker->quote_char('`');
62 DBICTest->schema->storage->sql_maker->name_sep('.');
63
64 cmp_ok(DBICTest->schema->storage->sql_maker->update('group', \%data), 'eq', 'UPDATE `group` SET `name` = ?, `order` = ?', "quoted table names for UPDATE");
65