Merge 'trunk' into 'DBIx-Class-current'
[dbsrgits/DBIx-Class-Historic.git] / t / 19quotes_newstyle.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 my $dsn = DBICTest->schema->storage->connect_info->[0];
20
21 DBICTest->schema->connection($dsn, { quote_char => '`', name_sep => '.' });
22
23 my $rs = DBICTest::CD->search(
24            { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
25            { join => 'artist' });
26
27 cmp_ok( $rs->count, '==', 1, "join with fields quoted");
28
29 $rs = DBICTest::CD->search({},
30             { 'order_by' => 'year DESC'});
31 {
32        eval { $rs->first() };
33        like( $@, qr/no such column: year DESC/, "Problem with ORDER BY quotes" );
34 }
35
36 my $order = 'year DESC';
37 $rs = DBICTest::CD->search({},
38             { 'order_by' => \$order });
39 {
40        eval { $rs->first() };
41        ok(!$@, "No problem handling ORDER by scalaref" );
42 }
43
44 DBICTest->schema->connection($dsn, { quote_char => [qw/[ ]/], 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->connection($dsn, { quote_char => '`', name_sep => '.' });
57
58 cmp_ok(DBICTest->schema->storage->sql_maker->update('group', \%data), 'eq', 'UPDATE `group` SET `name` = ?, `order` = ?', "quoted table names for UPDATE");
59