From: Peter Rabbitson Date: Tue, 27 May 2014 05:50:48 +0000 (+0200) Subject: This test was essentially c/p-ed in 2cc3a7be3, consolidate X-Git-Tag: v0.082800~209 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=02a2db55ba0471379640a89ba5d9d128b5486270;p=dbsrgits%2FDBIx-Class.git This test was essentially c/p-ed in 2cc3a7be3, consolidate The overriding difference is the new-connection == new-storage == new-sqla Add an explicit codepath to test that, but overall there is plenty of other places that verify this behavior to death Examine under -w -C -M to make sense out of the consolidation (minimal changes were attempted) --- diff --git a/t/sqlmaker/quotes/quotes.t b/t/sqlmaker/quotes.t similarity index 66% rename from t/sqlmaker/quotes/quotes.t rename to t/sqlmaker/quotes.t index 3fbc94c..84f2a3f 100644 --- a/t/sqlmaker/quotes/quotes.t +++ b/t/sqlmaker/quotes.t @@ -10,22 +10,35 @@ use DBIC::DebugObj; my $schema = DBICTest->init_schema(); -$schema->storage->sql_maker->quote_char('`'); -$schema->storage->sql_maker->name_sep('.'); +$schema->connection( + @{ $schema->storage->_dbi_connect_info }, + { AutoCommit => 1, quote_char => [qw/[ ]/] } +); my ($sql, @bind); $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)); $schema->storage->debug(1); -my $rs; - -$rs = $schema->resultset('CD')->search( +my $rs = $schema->resultset('CD')->search( { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' }); +my $expected_bind = ["'Caterwauler McCrae'", "'2001'"]; +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] = ? )", + $expected_bind, + 'got correct SQL for count query with bracket quoting' +); + +$schema->storage->sql_maker->quote_char('`'); +$schema->storage->sql_maker->name_sep('.'); + 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'"], + "SELECT COUNT( * ) FROM cd `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", + $expected_bind, 'got correct SQL for count query with quoting' ); @@ -40,27 +53,9 @@ $rs = $schema->resultset('CD')->search({}, eval { $rs->first }; like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref'); -$schema->storage->sql_maker->quote_char([qw/[ ]/]); -$schema->storage->sql_maker->name_sep('.'); - -$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 bracket quoting' -); - -my %data = ( - name => 'Bill', - order => '12' -); - -$schema->storage->sql_maker->quote_char('`'); -$schema->storage->sql_maker->name_sep('.'); - -is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE'); +is( + $schema->storage->sql_maker->update('group', { name => 'Bill', order => 12 }), + 'UPDATE `group` SET `name` = ?, `order` = ?', + 'quoted table names for UPDATE' ); done_testing; diff --git a/t/sqlmaker/quotes/quotes_newstyle.t b/t/sqlmaker/quotes/quotes_newstyle.t deleted file mode 100644 index 900a68a..0000000 --- a/t/sqlmaker/quotes/quotes_newstyle.t +++ /dev/null @@ -1,83 +0,0 @@ -use strict; -use warnings; - -use Test::More; - -use lib qw(t/lib); -use DBICTest; -use DBIC::SqlMakerTest; -use DBIC::DebugObj; - -my $schema = DBICTest->init_schema(); - -my $dsn = $schema->storage->_dbi_connect_info->[0]; -$schema->connection( - $dsn, - undef, - undef, - { AutoCommit => 1 }, - { quote_char => '`', name_sep => '.' }, -); - -my ($sql, @bind); -$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)), -$schema->storage->debug(1); - -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 = $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 }; -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->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 }; -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' -); - -$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'); - -done_testing;