X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F19quotes_newstyle.t;h=02c145070649cfd91d80acd6d1786da53b3a5109;hb=3ff1602f88b7824c75f2a32f18777347e6139b81;hp=d2c40e0d4ba803718ff7c47f6b919093a42e0034;hpb=a0f1c4de9f4896f8d4ab8d7f3b23a57411f35bfd;p=dbsrgits%2FDBIx-Class.git diff --git a/t/19quotes_newstyle.t b/t/19quotes_newstyle.t index d2c40e0..02c1450 100644 --- a/t/19quotes_newstyle.t +++ b/t/19quotes_newstyle.t @@ -14,46 +14,73 @@ BEGIN { use lib qw(t/lib); use_ok('DBICTest'); -DBICTest->init_schema(); +my $schema = DBICTest->init_schema(); -my $dsn = DBICTest->schema->storage->connect_info->[0]; +my $orig_debugcb = $schema->storage->debugcb; +my $orig_debug = $schema->storage->debug; -DBICTest->schema->connection($dsn, { quote_char => '`', name_sep => '.' }); +diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); -my $rs = DBICTest::CD->search( - { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, - { join => 'artist' }); +my $dsn = $schema->storage->connect_info->[0]; +$schema->connection( + $dsn, + undef, + undef, + { AutoCommit => 1 }, + { quote_char => '`', name_sep => '.' }, +); -cmp_ok( $rs->count, '==', 1, "join with fields quoted"); +my $sql = ''; +$schema->storage->debugcb(sub { $sql = $_[1] }); +$schema->storage->debug(1); -$rs = DBICTest::CD->search({}, - { 'order_by' => 'year DESC'}); -{ - eval { $rs->first() }; - like( $@, qr/no such column: year DESC/, "Problem with ORDER BY quotes" ); -} +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 = DBICTest::CD->search({}, - { 'order_by' => \$order }); -{ - eval { $rs->first() }; - ok(!$@, "No problem handling ORDER by scalaref" ); -} +$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)'); -DBICTest->schema->connection($dsn, { quote_char => [qw/[ ]/], name_sep => '.' }); +$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->connection( + $dsn, + undef, + undef, + { AutoCommit => 1, quote_char => [qw/[ ]/], name_sep => '.' } +); +$schema->storage->debugcb(sub { $sql = $_[1] }); +$schema->storage->debug(1); -$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 }; +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' ); -DBICTest->schema->connection($dsn, { quote_char => '`', name_sep => '.' }); +$schema->connection( + $dsn, + undef, + undef, + { AutoCommit => 1, quote_char => '`', name_sep => '.' } +); -cmp_ok(DBICTest->schema->storage->sql_maker->update('group', \%data), 'eq', 'UPDATE `group` SET `name` = ?, `order` = ?', "quoted table names for UPDATE"); +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);