X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F19quotes.t;h=8750d5ad1139fd26105d59342788c03cfeb4aaa7;hb=ce35224fef0822f6b05f7883ca955eb830a307a5;hp=303f29755a11452ccf43e38f984cab4ff5c16229;hpb=5a1f2d730c2ce5d0b7e8b996ffaa529c4872b410;p=dbsrgits%2FDBIx-Class.git diff --git a/t/19quotes.t b/t/19quotes.t index 303f297..8750d5a 100644 --- a/t/19quotes.t +++ b/t/19quotes.t @@ -4,68 +4,72 @@ 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'); -DBICTest->init_schema(); - -my $orig_debugcb = DBICTest->schema->storage->debugcb; -my $orig_debug = DBICTest->schema->storage->debug; +use_ok('DBIC::DebugObj'); +my $schema = DBICTest->init_schema(); -diag('Testing against ' . join(' ', map { DBICTest->schema->storage->dbh->get_info($_) } qw/17 18/)); +#diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); -DBICTest->schema->storage->sql_maker->quote_char('`'); -DBICTest->schema->storage->sql_maker->name_sep('.'); +$schema->storage->sql_maker->quote_char('`'); +$schema->storage->sql_maker->name_sep('.'); -my $sql = ''; - -DBICTest->schema->storage->debugcb(sub { $sql = $_[1] }); -DBICTest->schema->storage->debug(1); +my ($sql, @bind); +$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)); +$schema->storage->debug(1); my $rs; -$rs = DBICTest::CD->search( +$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 = DBICTest::CD->search({}, +$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 = DBICTest::CD->search({}, +$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'); -DBICTest->schema->storage->sql_maker->quote_char([qw/[ ]/]); -DBICTest->schema->storage->sql_maker->name_sep('.'); +$schema->storage->sql_maker->quote_char([qw/[ ]/]); +$schema->storage->sql_maker->name_sep('.'); -$rs = DBICTest::CD->search( +$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', order => '12' ); -DBICTest->schema->storage->sql_maker->quote_char('`'); -DBICTest->schema->storage->sql_maker->name_sep('.'); - -is(DBICTest->schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE'); +$schema->storage->sql_maker->quote_char('`'); +$schema->storage->sql_maker->name_sep('.'); -DBICTest->schema->storage->debugcb($orig_debugcb); -DBICTest->schema->storage->debug($orig_debug); +is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');