X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F19quotes_newstyle.t;h=02c145070649cfd91d80acd6d1786da53b3a5109;hb=5ce78bdc81e8e98dc92f9fa978f4e3c035c1d616;hp=65cd3aa86d7a46f8d1a60074cf5e4b97886431ea;hpb=2cc3a7be389cb22aacc99425cf7ed3493b4ebf2a;p=dbsrgits%2FDBIx-Class.git diff --git a/t/19quotes_newstyle.t b/t/19quotes_newstyle.t index 65cd3aa..02c1450 100644 --- a/t/19quotes_newstyle.t +++ b/t/19quotes_newstyle.t @@ -14,51 +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'}); -{ - my $warnings = ''; - local $SIG{__WARN__} = sub { $warnings .= $_[0] }; - my $first = eval{ $rs->first() }; - like( $warnings, qr/ORDER BY terms/, "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 }); -{ - my $warnings = ''; - local $SIG{__WARN__} = sub { $warnings .= $_[0] }; - my $first = $rs->first(); - ok( $warnings !~ /ORDER BY terms/, - "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);