X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F19quotes.t;h=8750d5ad1139fd26105d59342788c03cfeb4aaa7;hb=f66e15f39f65384d95c4a254b9aefe14f32e49e3;hp=79d02eeda61d501d3bed82241c5841cb74230dba;hpb=54540863adce71e931685a37d33e37650e5feb5e;p=dbsrgits%2FDBIx-Class.git diff --git a/t/19quotes.t b/t/19quotes.t index 79d02ee..8750d5a 100644 --- a/t/19quotes.t +++ b/t/19quotes.t @@ -1,26 +1,75 @@ use strict; +use warnings; + use Test::More; use IO::File; +use lib qw(t/lib); +use DBIC::SqlMakerTest; + BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 3 ); + : ( tests => 7 ); } -use lib qw(t/lib); use_ok('DBICTest'); +use_ok('DBIC::DebugObj'); +my $schema = DBICTest->init_schema(); -use_ok('DBICTest::HelperRels'); +#diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); -DBICTest::_db->storage->sql_maker->{'quote_char'} = q!'!; -DBICTest::_db->storage->sql_maker->{'name_sep'} = '.'; +$schema->storage->sql_maker->quote_char('`'); +$schema->storage->sql_maker->name_sep('.'); -my $rs = DBICTest::CD->search( +my ($sql, @bind); +$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)); +$schema->storage->debug(1); + +my $rs; + +$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 = $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 }); +eval { $rs->first }; +like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref'); + +$schema->storage->sql_maker->quote_char([qw/[ ]/]); +$schema->storage->sql_maker->name_sep('.'); + +$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 bracket quoting' +); + +my %data = ( + name => 'Bill', + order => '12' +); -cmp_ok( $rs->count, '==', 1, "join with fields quoted"); +$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');