first draft of storage exception stuff
[dbsrgits/DBIx-Class.git] / t / 19quotes_newstyle.t
CommitLineData
2cc3a7be 1use strict;
2use warnings;
3
4use Test::More;
5use IO::File;
6
7BEGIN {
8 eval "use DBD::SQLite";
9 plan $@
10 ? ( skip_all => 'needs DBD::SQLite for testing' )
11 : ( tests => 6 );
12}
13
14use lib qw(t/lib);
15
16use_ok('DBICTest');
17DBICTest->init_schema();
18
19my $dsn = DBICTest->schema->storage->connect_info->[0];
20
21DBICTest->schema->connection($dsn, { quote_char => "'", name_sep => '.' });
22
23my $rs = DBICTest::CD->search(
24 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
25 { join => 'artist' });
26
27cmp_ok( $rs->count, '==', 1, "join with fields quoted");
28
29$rs = DBICTest::CD->search({},
30 { 'order_by' => 'year DESC'});
31{
f11383c2 32 eval{ $rs->first() };
33 like( $@, qr/ORDER BY terms/, "Problem with ORDER BY quotes" );
2cc3a7be 34}
35
36my $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
47DBICTest->schema->connection($dsn, { quote_char => [qw/[ ]/], name_sep => '.' });
48
49$rs = DBICTest::CD->search(
50 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
51 { join => 'artist' });
52cmp_ok($rs->count,'==', 1,"join quoted with brackets.");
53
54my %data = (
55 name => 'Bill',
56 order => '12'
57);
58
59DBICTest->schema->connection($dsn, { quote_char => '`', name_sep => '.' });
60
61cmp_ok(DBICTest->schema->storage->sql_maker->update('group', \%data), 'eq', 'UPDATE `group` SET `name` = ?, `order` = ?', "quoted table names for UPDATE");
62