X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F19quotes_newstyle.t;h=3e7595aab975a94a1d4016418843e281d9200473;hb=ae645c61cf6461f67e023e1f36b2ebc9c5ea411b;hp=02c145070649cfd91d80acd6d1786da53b3a5109;hpb=77d76d0f2fe3f253eea0fb2b4b1f0f604d130d9e;p=dbsrgits%2FDBIx-Class.git diff --git a/t/19quotes_newstyle.t b/t/19quotes_newstyle.t index 02c1450..3e7595a 100644 --- a/t/19quotes_newstyle.t +++ b/t/19quotes_newstyle.t @@ -4,24 +4,24 @@ 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 => 6 ); + : ( tests => 7 ); } -use lib qw(t/lib); - use_ok('DBICTest'); -my $schema = DBICTest->init_schema(); +use_ok('DBIC::DebugObj'); -my $orig_debugcb = $schema->storage->debugcb; -my $orig_debug = $schema->storage->debug; +my $schema = DBICTest->init_schema(); -diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); +#diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); -my $dsn = $schema->storage->connect_info->[0]; +my $dsn = $schema->storage->_dbi_connect_info->[0]; $schema->connection( $dsn, undef, @@ -30,8 +30,8 @@ $schema->connection( { quote_char => '`', name_sep => '.' }, ); -my $sql = ''; -$schema->storage->debugcb(sub { $sql = $_[1] }); +my ($sql, @bind); +$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)), $schema->storage->debug(1); my $rs; @@ -40,7 +40,11 @@ $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'); +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({}, @@ -59,14 +63,19 @@ $schema->connection( undef, { AutoCommit => 1, quote_char => [qw/[ ]/], name_sep => '.' } ); -$schema->storage->debugcb(sub { $sql = $_[1] }); + +$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)), $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'); +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', @@ -81,6 +90,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);