Now SQLA 1.50 compatible - no changes to tests, no additions. Just compat
[dbsrgits/DBIx-Class.git] / t / 19quotes_newstyle.t
index 02c1450..5eb22e0 100644 (file)
@@ -13,12 +13,12 @@ BEGIN {
 
 use lib qw(t/lib);
 
+use DBIC::SqlMakerTest;
+use DBIC::DebugObj;
+
 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/));
 
 my $dsn = $schema->storage->connect_info->[0];
@@ -30,28 +30,43 @@ $schema->connection(
   { quote_char => '`', name_sep => '.' },
 );
 
-my $sql = '';
-$schema->storage->debugcb(sub { $sql = $_[1] });
-$schema->storage->debug(1);
-
-my $rs;
+my $sql;
+$schema->storage->debugobj(DBIC::DebugObj->new(\$sql));
+$schema->storage->debug (1);
 
-$rs = $schema->resultset('CD')->search(
+my $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');
-
+ok (eq_sql
+  (
+    $sql,
+    q/SELECT COUNT( * ) FROM `cd` `me`  JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )/,
+  ),
+  '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)');
+ok (eq_sql
+  (
+    $sql,
+    qq/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `${order}`/,
+  ),
+  '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');
+ok (eq_sql
+  (
+    $sql,
+    qq/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY ${order}/,
+  ),
+  'did not quote ORDER BY with scalarref'
+);
 
 $schema->connection(
   $dsn,
@@ -59,14 +74,20 @@ $schema->connection(
   undef,
   { AutoCommit => 1, quote_char => [qw/[ ]/], name_sep => '.' }
 );
-$schema->storage->debugcb(sub { $sql = $_[1] });
+$schema->storage->debugobj(DBIC::DebugObj->new(\$sql));
 $schema->storage->debug(1);
 
 $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');
+ok (eq_sql
+  (
+    $sql,
+    q/SELECT COUNT( * ) FROM [cd] [me]  JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/,
+  ),
+  'got correct SQL for count query with bracket quoting'
+);
 
 my %data = (
        name => 'Bill',
@@ -81,6 +102,3 @@ $schema->connection(
 );
 
 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);