X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F19quotes.t;h=2412e1d04cf716bcdb2ac19e367ba7c1556cbf00;hb=9b4591296c196ea0a32e67159e35091b02ecc539;hp=7a85075b03ff51b51ae177061bf118f891ae2730;hpb=6346a152bc0b64e0bb43fdd58b6431eb935db051;p=dbsrgits%2FDBIx-Class.git diff --git a/t/19quotes.t b/t/19quotes.t index 7a85075..2412e1d 100644 --- a/t/19quotes.t +++ b/t/19quotes.t @@ -1,6 +1,9 @@ use strict; +use warnings; + use Test::More; use IO::File; +use SQL::Abstract::Test import => ['is_same_sql_bind']; BEGIN { eval "use DBD::SQLite"; @@ -12,53 +15,60 @@ BEGIN { use lib qw(t/lib); use_ok('DBICTest'); +use_ok('DBICTest::DBICDebugObj'); +my $schema = DBICTest->init_schema(); -use_ok('DBICTest::HelperRels'); +diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); -DBICTest->schema->storage->sql_maker->quote_char("'"); -DBICTest->schema->storage->sql_maker->name_sep('.'); +$schema->storage->sql_maker->quote_char('`'); +$schema->storage->sql_maker->name_sep('.'); -my $rs = DBICTest::CD->search( - { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, - { join => 'artist' }); +my ($sql, @bind) = (''); +$schema->storage->debugobj(DBICTest::DBICDebugObj->new(\$sql, \@bind)); +$schema->storage->debug(1); -cmp_ok( $rs->count, '==', 1, "join with fields quoted"); +my $rs; -$rs = DBICTest::CD->search({}, - { 'order_by' => 'year DESC'}); -{ - my $warnings; - local $SIG{__WARN__} = sub { $warnings .= $_[0] }; - my $first = eval{ $rs->first() }; - ok( $warnings =~ /ORDER BY terms/, "Problem with ORDER BY quotes" ); -} +$rs = $schema->resultset('CD')->search( + { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, + { join => 'artist' }); +eval { $rs->count }; +is_same_sql_bind( + $sql, \@bind, + "SELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"], + 'got correct SQL for count query with quoting' +); my $order = 'year DESC'; -$rs = DBICTest::CD->search({}, +$rs = $schema->resultset('CD')->search({}, + { 'order_by' => $order }); +eval { $rs->first }; +like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)'); + +$rs = $schema->resultset('CD')->search({}, { 'order_by' => \$order }); -{ - my $warnings; - local $SIG{__WARN__} = sub { $warnings .= $_[0] }; - my $first = $rs->first(); - ok( $warnings !~ /ORDER BY terms/, - "No problem handling ORDER by scalaref" ); -} +eval { $rs->first }; +like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref'); -DBICTest->schema->storage->sql_maker->quote_char([qw/[ ]/]); -DBICTest->schema->storage->sql_maker->name_sep('.'); +$schema->storage->sql_maker->quote_char([qw/[ ]/]); +$schema->storage->sql_maker->name_sep('.'); -$rs = DBICTest::CD->search( +$rs = $schema->resultset('CD')->search( { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' }); -cmp_ok($rs->count,'==', 1,"join quoted with brackets."); +eval { $rs->count }; +is_same_sql_bind( + $sql, \@bind, + "SELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )", ["'Caterwauler McCrae'", "'2001'"], + 'got correct SQL for count query with bracket quoting' +); my %data = ( name => 'Bill', order => '12' ); -DBICTest->schema->storage->sql_maker->quote_char('`'); -DBICTest->schema->storage->sql_maker->name_sep('.'); - -cmp_ok(DBICTest->schema->storage->sql_maker->update('group', \%data), 'eq', 'UPDATE `group` SET `name` = ?, `order` = ?', "quoted table names for UPDATE"); +$schema->storage->sql_maker->quote_char('`'); +$schema->storage->sql_maker->name_sep('.'); +is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');