Merge 'trunk' into 'DBIx-Class-current'
[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        eval{ $rs->first() };
32        like( $@, qr/no such column: year DESC/, "Problem with ORDER BY quotes" );
33 }
34
35 my $order = 'year DESC';
36 $rs = DBICTest::CD->search({},
37             { 'order_by' => \$order });
38 {
39        eval { $rs->first() };
40        ok(!$@, "No problem handling ORDER by scalaref" );
41 }
42
43 DBICTest->schema->storage->sql_maker->quote_char([qw/[ ]/]);
44 DBICTest->schema->storage->sql_maker->name_sep('.');
45
46 $rs = DBICTest::CD->search(
47            { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
48            { join => 'artist' });
49 cmp_ok($rs->count,'==', 1,"join quoted with brackets.");
50
51 my %data = (
52        name => 'Bill',
53        order => '12'
54 );
55
56 DBICTest->schema->storage->sql_maker->quote_char('`');
57 DBICTest->schema->storage->sql_maker->name_sep('.');
58
59 cmp_ok(DBICTest->schema->storage->sql_maker->update('group', \%data), 'eq', 'UPDATE `group` SET `name` = ?, `order` = ?', "quoted table names for UPDATE");
60