Now SQLA 1.50 compatible - no changes to tests, no additions. Just compat
[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 use DBIC::SqlMakerTest;
16 use DBIC::DebugObj;
17
18 use_ok('DBICTest');
19 my $schema = DBICTest->init_schema();
20
21 diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/));
22
23 $schema->storage->sql_maker->quote_char('`');
24 $schema->storage->sql_maker->name_sep('.');
25
26 my $sql;
27 $schema->storage->debugobj(DBIC::DebugObj->new(\$sql));
28 $schema->storage->debug(1);
29
30 my $rs;
31
32 $rs = $schema->resultset('CD')->search(
33            { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
34            { join => 'artist' });
35 eval { $rs->count };
36 ok (eq_sql
37   (
38     $sql,
39     q/SELECT COUNT( * ) FROM `cd` `me`  JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )/,
40   ),
41   'got correct SQL for count query with quoting'
42 );
43
44
45 my $order = 'year DESC';
46 $rs = $schema->resultset('CD')->search({},
47             { 'order_by' => $order });
48 eval { $rs->first };
49 ok (eq_sql
50   (
51     $sql,
52     qq/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `${order}`/,
53   ),
54   'quoted ORDER BY with DESC (should use a scalarref anyway)'
55 );
56
57 $rs = $schema->resultset('CD')->search({},
58             { 'order_by' => \$order });
59 eval { $rs->first };
60 ok (eq_sql
61   (
62     $sql,
63     qq/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY ${order}/,
64   ),
65   'did not quote ORDER BY with scalarref'
66 );
67
68 $schema->storage->sql_maker->quote_char([qw/[ ]/]);
69 $schema->storage->sql_maker->name_sep('.');
70
71 $rs = $schema->resultset('CD')->search(
72            { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
73            { join => 'artist' });
74 eval { $rs->count };
75 ok (eq_sql
76   (
77     $sql,
78     qq/SELECT COUNT( * ) FROM [cd] [me]  JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/,
79   ),
80   'got correct SQL for count query with bracket quoting'
81 );
82
83 my %data = (
84        name => 'Bill',
85        order => '12'
86 );
87
88 $schema->storage->sql_maker->quote_char('`');
89 $schema->storage->sql_maker->name_sep('.');
90
91 is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');