Fix for recent SQLite versions interpreting single quotes as string literals
[dbsrgits/DBIx-Class.git] / t / 19quotes.t
CommitLineData
2a816814 1use strict;
58d387fe 2use warnings;
3
2a816814 4use Test::More;
5use IO::File;
6
7BEGIN {
8 eval "use DBD::SQLite";
9 plan $@
10 ? ( skip_all => 'needs DBD::SQLite for testing' )
58d387fe 11 : ( tests => 6 );
2a816814 12}
13
14use lib qw(t/lib);
15
16use_ok('DBICTest');
a47e1233 17DBICTest->init_schema();
22b15c96 18
02af104d 19DBICTest->schema->storage->sql_maker->quote_char('`');
2437a1e3 20DBICTest->schema->storage->sql_maker->name_sep('.');
2a816814 21
22my $rs = DBICTest::CD->search(
54540863 23 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
2a816814 24 { join => 'artist' });
25
26cmp_ok( $rs->count, '==', 1, "join with fields quoted");
27
e535069e 28$rs = DBICTest::CD->search({},
29 { 'order_by' => 'year DESC'});
30{
5db49b9a 31 my $warnings = '';
e535069e 32 local $SIG{__WARN__} = sub { $warnings .= $_[0] };
33 my $first = eval{ $rs->first() };
02af104d 34 like( $warnings, qr/no such column: year DESC/, "Problem with ORDER BY quotes" );
e535069e 35}
36
37my $order = 'year DESC';
38$rs = DBICTest::CD->search({},
39 { 'order_by' => \$order });
40{
5db49b9a 41 my $warnings = '';
e535069e 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
2437a1e3 48DBICTest->schema->storage->sql_maker->quote_char([qw/[ ]/]);
49DBICTest->schema->storage->sql_maker->name_sep('.');
50
51$rs = DBICTest::CD->search(
52 { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' },
53 { join => 'artist' });
54cmp_ok($rs->count,'==', 1,"join quoted with brackets.");
55
6346a152 56my %data = (
57 name => 'Bill',
58 order => '12'
59);
2437a1e3 60
6346a152 61DBICTest->schema->storage->sql_maker->quote_char('`');
62DBICTest->schema->storage->sql_maker->name_sep('.');
2437a1e3 63
6346a152 64cmp_ok(DBICTest->schema->storage->sql_maker->update('group', \%data), 'eq', 'UPDATE `group` SET `name` = ?, `order` = ?', "quoted table names for UPDATE");
2437a1e3 65