X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F19quotes.t;h=646131b07558f34c5c1459676f302cdec4081644;hb=d96034a1cc274ea315d6482de4633ec0c60b95ce;hp=a312e358e040e1bc19ffecd841aced9b79040938;hpb=2a8168143cea9db25fc7531f08c84b01ef4cf395;p=dbsrgits%2FDBIx-Class.git diff --git a/t/19quotes.t b/t/19quotes.t index a312e35..646131b 100644 --- a/t/19quotes.t +++ b/t/19quotes.t @@ -1,4 +1,6 @@ use strict; +use warnings; + use Test::More; use IO::File; @@ -6,19 +8,64 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 2 ); + : ( tests => 6 ); } use lib qw(t/lib); use_ok('DBICTest'); +my $schema = DBICTest->init_schema(); + +my $orig_debugcb = $schema->storage->debugcb; +my $orig_debug = $schema->storage->debug; + +diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); + +$schema->storage->sql_maker->quote_char('`'); +$schema->storage->sql_maker->name_sep('.'); -DBICTest::_db->storage->sql_maker->{'quote_char'} = q!'!; -DBICTest::_db->storage->sql_maker->{'name_sep'} = '.'; +my $sql = ''; -my $rs = DBICTest::CD->search( - { 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, +$schema->storage->debugcb(sub { $sql = $_[1] }); +$schema->storage->debug(1); + +my $rs; + +$rs = $schema->resultset('CD')->search( + { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' }); +eval { $rs->count }; +like($sql, qr/\QSELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )\E/, '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 }; +like($sql, qr/\QSELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )\E/, 'got correct SQL for count query with bracket quoting'); + +my %data = ( + name => 'Bill', + order => '12' +); + +$schema->storage->sql_maker->quote_char('`'); +$schema->storage->sql_maker->name_sep('.'); -cmp_ok( $rs->count, '==', 1, "join with fields quoted"); +is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE'); +$schema->storage->debugcb($orig_debugcb); +$schema->storage->debug($orig_debug);