X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F19quotes_newstyle.t;h=3e7595aab975a94a1d4016418843e281d9200473;hb=5ce107ad1f89bedd676d85c570be4de9f7c03f69;hp=d2c40e0d4ba803718ff7c47f6b919093a42e0034;hpb=a0f1c4de9f4896f8d4ab8d7f3b23a57411f35bfd;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/19quotes_newstyle.t b/t/19quotes_newstyle.t index d2c40e0..3e7595a 100644 --- a/t/19quotes_newstyle.t +++ b/t/19quotes_newstyle.t @@ -4,56 +4,89 @@ 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(); +use_ok('DBIC::DebugObj'); -my $dsn = DBICTest->schema->storage->connect_info->[0]; +my $schema = DBICTest->init_schema(); -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->_dbi_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, @bind); +$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)), +$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 }; +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 = $schema->resultset('CD')->search({}, { 'order_by' => \$order }); -{ - eval { $rs->first() }; - ok(!$@, "No problem handling ORDER by scalaref" ); -} +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 => '.' } +); -DBICTest->schema->connection($dsn, { quote_char => [qw/[ ]/], name_sep => '.' }); +$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)), +$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 }; +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->connection($dsn, { 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"); +$schema->connection( + $dsn, + undef, + undef, + { AutoCommit => 1, quote_char => '`', name_sep => '.' } +); +is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');