From: Peter Rabbitson Date: Wed, 20 May 2009 21:00:13 +0000 (+0000) Subject: Switch as_query testing to direct specification in is_same_sql_bind X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=af6aac2d51a435fa60151ac047e1559257fd4eba;p=dbsrgits%2FDBIx-Class-Historic.git Switch as_query testing to direct specification in is_same_sql_bind --- diff --git a/t/19quotes.t b/t/19quotes.t index 622eefb..c4768c8 100644 --- a/t/19quotes.t +++ b/t/19quotes.t @@ -24,7 +24,7 @@ my $schema = DBICTest->init_schema(); $schema->storage->sql_maker->quote_char('`'); $schema->storage->sql_maker->name_sep('.'); -my ($sql, @bind) = (''); +my ($sql, @bind); $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)); $schema->storage->debug(1); diff --git a/t/19quotes_newstyle.t b/t/19quotes_newstyle.t index 80e6d04..f0c34a9 100644 --- a/t/19quotes_newstyle.t +++ b/t/19quotes_newstyle.t @@ -30,7 +30,7 @@ $schema->connection( { quote_char => '`', name_sep => '.' }, ); -my ($sql, @bind) = (''); +my ($sql, @bind); $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)), $schema->storage->debug(1); diff --git a/t/47bind_attribute.t b/t/47bind_attribute.t index be662a2..b9946a4 100644 --- a/t/47bind_attribute.t +++ b/t/47bind_attribute.t @@ -74,9 +74,8 @@ is ( $rs->count, 1, '...cookbook (bind first) + chained search' ); { $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })->search({}, { where => \"title LIKE ?", bind => [ 'Spoon%' ] }); - my ($sql, @bind) = @${$rs->as_query}; is_same_sql_bind( - $sql, \@bind, + $rs->as_query, "(SELECT me.artistid, me.name, me.rank, me.charfield FROM (SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year FROM artist a JOIN cd ON cd.artist = a.artistid WHERE cd.year = ?) WHERE title LIKE ?)", [ [ '!!dummy' => '1999' ], diff --git a/t/76joins.t b/t/76joins.t index c6e795c..5706dfa 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -32,9 +32,9 @@ my $match = 'person child JOIN person father ON ( father.person_id = ' . 'child.father_id ) JOIN person mother ON ( mother.person_id ' . '= child.mother_id )' ; -is_same_sql_bind( - $sa->_recurse_from(@j), [], - $match, [], +is_same_sql( + $sa->_recurse_from(@j), + $match, 'join 1 ok' ); @@ -52,9 +52,9 @@ $match = 'person mother JOIN (person child JOIN person father ON (' . ' father.person_id = child.father_id )) ON ( mother.person_id = ' . 'child.mother_id )' ; -is_same_sql_bind( - $sa->_recurse_from(@j2), [], - $match, [], +is_same_sql( + $sa->_recurse_from(@j2), + $match, 'join 2 ok' ); @@ -69,9 +69,9 @@ $match = 'person child INNER JOIN person father ON ( father.person_id = ' . '= child.mother_id )' ; -is_same_sql_bind( - $sa->_recurse_from(@j3), [], - $match, [], +is_same_sql( + $sa->_recurse_from(@j3), + $match, 'join 3 (inner join) ok' ); @@ -89,9 +89,9 @@ $match = 'person mother LEFT JOIN (person child RIGHT JOIN person father ON (' . ' father.person_id = child.father_id )) ON ( mother.person_id = ' . 'child.mother_id )' ; -is_same_sql_bind( - $sa->_recurse_from(@j4), [], - $match, [], +is_same_sql( + $sa->_recurse_from(@j4), + $match, 'join 4 (nested joins + join types) ok' ); @@ -104,9 +104,9 @@ $match = 'person child JOIN person father ON ( father.person_id != ' . 'child.father_id ) JOIN person mother ON ( mother.person_id ' . '= child.mother_id )' ; -is_same_sql_bind( - $sa->_recurse_from(@j5), [], - $match, [], +is_same_sql( + $sa->_recurse_from(@j5), + $match, 'join 5 (SCALAR reference for ON statement) ok' ); diff --git a/t/76select.t b/t/76select.t index 40045b4..bee69e6 100644 --- a/t/76select.t +++ b/t/76select.t @@ -84,10 +84,8 @@ $rs = $schema->resultset('CD')->search({}, } ); -my ($sql, @bind) = @${$rs->as_query}; is_same_sql_bind ( - $sql, - \@bind, + $rs->as_query, '(SELECT me.cdid, me.title, artist.name FROM cd me JOIN artist artist ON artist.artistid = me.artist)', [], 'Use of columns attribute results in proper sql' @@ -114,10 +112,8 @@ $rs = $schema->resultset('CD')->search({}, } ); -($sql, @bind) = @${$rs->as_query}; is_same_sql_bind ( - $sql, - \@bind, + $rs->as_query, '(SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, me.cdid, me.title, artist.name FROM cd me JOIN artist artist ON artist.artistid = me.artist)', [], 'Use of columns attribute results in proper sql' diff --git a/t/91debug.t b/t/91debug.t index 5b5514b..bb55aba 100644 --- a/t/91debug.t +++ b/t/91debug.t @@ -51,18 +51,17 @@ open(STDERR, '>&STDERRCOPY'); # test trace output correctness for bind params { - my ($sql, @bind) = (''); - $schema->storage->debugcb( sub { $sql = $_[1] } ); + my ($sql, @bind); + $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)); my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } ); is_same_sql_bind( - $sql, [], - "SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND (cdid BETWEEN ? AND ?) ): '1', '1', '3'", [], + $sql, \@bind, + "SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND (cdid BETWEEN ? AND ?) ): '1', '1', '3'", + [qw/'1' '1' '3'/], 'got correct SQL with all bind parameters (debugcb)' ); - $schema->storage->debugcb(undef); - $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)); @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } ); is_same_sql_bind( $sql, \@bind, diff --git a/t/count/prefetch.t b/t/count/prefetch.t index bd0426b..7c9bf95 100644 --- a/t/count/prefetch.t +++ b/t/count/prefetch.t @@ -33,7 +33,7 @@ my $schema = DBICTest->init_schema(); $sql, \@bind, 'SELECT COUNT( * ) FROM (SELECT cds.cdid FROM artist me LEFT JOIN cd cds ON cds.artist = me.artistid LEFT JOIN track tracks ON tracks.cd = cds.cdid JOIN artist artist ON artist.artistid = cds.artist WHERE tracks.position = ? OR tracks.position = ? GROUP BY cds.cdid ORDER BY tracks.cd) count_subq', - [ qw/'1' '2'/ ], # wtf? we quote bind vals? + [ qw/'1' '2'/ ], ); } @@ -58,6 +58,6 @@ my $schema = DBICTest->init_schema(); $sql, \@bind, 'SELECT COUNT( * ) FROM cd me LEFT JOIN track tracks ON tracks.cd = me.cdid JOIN cd disc ON disc.cdid = tracks.cd LEFT JOIN lyrics lyrics ON lyrics.track_id = tracks.trackid WHERE ( ( position = ? OR position = ? ) )', - [ qw/'1' '2'/ ], # wtf? we quote bind vals? + [ qw/'1' '2'/ ], ); } diff --git a/t/from_subquery.t b/t/from_subquery.t index 5dc91d0..8c777ea 100644 --- a/t/from_subquery.t +++ b/t/from_subquery.t @@ -23,10 +23,8 @@ my $cdrs = $schema->resultset('CD'); artist_id => { 'in' => $art_rs->search({}, { rows => 1 })->get_column( 'id' )->as_query }, }); - my $arr = $cdrs2->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $cdrs2->as_query, "(SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE artist_id IN ( SELECT id FROM artist me LIMIT 1 ))", [], ); @@ -42,10 +40,8 @@ my $cdrs = $schema->resultset('CD'); }, ); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $rs->as_query, "(SELECT (SELECT id FROM cd me LIMIT 1) FROM artist me)", [], ); @@ -61,10 +57,8 @@ my $cdrs = $schema->resultset('CD'); }, ); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $rs->as_query, "(SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cd me LIMIT 1) FROM artist me)", [], ); @@ -82,10 +76,8 @@ my $cdrs = $schema->resultset('CD'); }, ); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $rs->as_query, "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE ( id > ? ) ) cd2)", [ [ 'id', 20 ] @@ -102,10 +94,8 @@ my $cdrs = $schema->resultset('CD'); { 'me.artistid' => 'cds_artist' } ] ] }); - my $arr = $art_rs2->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $art_rs2->as_query, "(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me JOIN (SELECT me.artist as cds_artist FROM cd me) cds ON me.artistid = cds_artist)", [] ); @@ -132,10 +122,8 @@ my $cdrs = $schema->resultset('CD'); }, ); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $rs->as_query, "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT cd3.cdid,cd3.artist,cd3.title,cd3.year,cd3.genreid,cd3.single_track @@ -160,10 +148,8 @@ my $cdrs = $schema->resultset('CD'); )->get_column('year')->max_rs->as_query, }, }); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $rs->as_query, "(SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE year = (SELECT MAX(inner.year) FROM cd inner WHERE artistid = me.artistid))", [], ); @@ -180,13 +166,9 @@ my $cdrs = $schema->resultset('CD'); }, ); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $rs->as_query, "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE ( title = ? ) ) cd2)", [ [ 'title', 'Thriller' ] ], ); } - -__END__ diff --git a/t/resultset/as_query.t b/t/resultset/as_query.t index f3a09fc..9cf2e36 100644 --- a/t/resultset/as_query.t +++ b/t/resultset/as_query.t @@ -18,11 +18,8 @@ my $art_rs = $schema->resultset('Artist'); my $cdrs = $schema->resultset('CD'); { - my $arr = $art_rs->as_query; - my ($query, @bind) = @{$$arr}; - is_same_sql_bind( - $query, \@bind, + $art_rs->as_query, "(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me)", [], ); } @@ -30,11 +27,8 @@ my $cdrs = $schema->resultset('CD'); $art_rs = $art_rs->search({ name => 'Billy Joel' }); { - my $arr = $art_rs->as_query; - my ($query, @bind) = @{$$arr}; - is_same_sql_bind( - $query, \@bind, + $art_rs->as_query, "(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE ( name = ? ))", [ [ name => 'Billy Joel' ] ], ); @@ -43,11 +37,8 @@ $art_rs = $art_rs->search({ name => 'Billy Joel' }); $art_rs = $art_rs->search({ rank => 2 }); { - my $arr = $art_rs->as_query; - my ($query, @bind) = @{$$arr}; - is_same_sql_bind( - $query, \@bind, + $art_rs->as_query, "(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE ( ( ( rank = ? ) AND ( name = ? ) ) ) )", [ [ rank => 2 ], [ name => 'Billy Joel' ] ], ); @@ -56,11 +47,8 @@ $art_rs = $art_rs->search({ rank => 2 }); my $rscol = $art_rs->get_column( 'charfield' ); { - my $arr = $rscol->as_query; - my ($query, @bind) = @{$$arr}; - is_same_sql_bind( - $query, \@bind, + $rscol->as_query, "(SELECT me.charfield FROM artist me WHERE ( ( ( rank = ? ) AND ( name = ? ) ) ) )", [ [ rank => 2 ], [ name => 'Billy Joel' ] ], ); diff --git a/t/search/subquery.t b/t/search/subquery.t index 2d96605..aa01183 100644 --- a/t/search/subquery.t +++ b/t/search/subquery.t @@ -22,10 +22,8 @@ my $cdrs = $schema->resultset('CD'); artist_id => { 'in' => $art_rs->search({}, { rows => 1 })->get_column( 'id' )->as_query }, }); - my $arr = $cdrs2->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $cdrs2->as_query, "( SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE artist_id IN ( SELECT id FROM artist me LIMIT 1 ) )", [], ); @@ -41,10 +39,8 @@ my $cdrs = $schema->resultset('CD'); }, ); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $rs->as_query, "( SELECT (SELECT id FROM cd me LIMIT 1) FROM artist me )", [], ); @@ -60,10 +56,8 @@ my $cdrs = $schema->resultset('CD'); }, ); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $rs->as_query, "( SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cd me LIMIT 1) FROM artist me )", [], ); @@ -81,10 +75,8 @@ my $cdrs = $schema->resultset('CD'); }, ); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $rs->as_query, "( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE id > ?) cd2 )", [ [ 'id', 20 ] @@ -101,10 +93,8 @@ my $cdrs = $schema->resultset('CD'); { 'me.artistid' => 'cds_artist' } ] ] }); - my $arr = $art_rs2->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $art_rs2->as_query, "( SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me JOIN (SELECT me.artist as cds_artist FROM cd me) cds ON me.artistid = cds_artist )", [] ); @@ -130,10 +120,8 @@ my $cdrs = $schema->resultset('CD'); }, ); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $rs->as_query, "( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT cd3.cdid,cd3.artist,cd3.title,cd3.year,cd3.genreid,cd3.single_track @@ -159,10 +147,9 @@ my $cdrs = $schema->resultset('CD'); )->get_column('year')->max_rs->as_query, }, }); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; + is_same_sql_bind( - $query, \@bind, + $rs->as_query, "( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE year = (SELECT MAX(inner.year) FROM cd inner WHERE artistid = me.artistid) )", [], ); @@ -179,10 +166,8 @@ my $cdrs = $schema->resultset('CD'); }, ); - my $arr = $rs->as_query; - my ($query, @bind) = @{$$arr}; is_same_sql_bind( - $query, \@bind, + $rs->as_query, "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE title = ?) cd2)", [ [ 'title', @@ -191,5 +176,3 @@ my $cdrs = $schema->resultset('CD'); ], ); } - -__END__