From: Peter Rabbitson Date: Thu, 29 Jan 2009 20:00:16 +0000 (+0000) Subject: Now SQLA 1.50 compatible - no changes to tests, no additions. Just compat X-Git-Tag: v0.08011~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cadd7ab834788b786970753bfd2dc65b4a0e7cc4;p=dbsrgits%2FDBIx-Class.git Now SQLA 1.50 compatible - no changes to tests, no additions. Just compat --- diff --git a/t/19quotes.t b/t/19quotes.t index 646131b..ec5b540 100644 --- a/t/19quotes.t +++ b/t/19quotes.t @@ -12,21 +12,19 @@ BEGIN { } use lib qw(t/lib); +use DBIC::SqlMakerTest; +use DBIC::DebugObj; use_ok('DBICTest'); my $schema = DBICTest->init_schema(); -my $orig_debugcb = $schema->storage->debugcb; -my $orig_debug = $schema->storage->debug; - diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); $schema->storage->sql_maker->quote_char('`'); $schema->storage->sql_maker->name_sep('.'); -my $sql = ''; - -$schema->storage->debugcb(sub { $sql = $_[1] }); +my $sql; +$schema->storage->debugobj(DBIC::DebugObj->new(\$sql)); $schema->storage->debug(1); my $rs; @@ -35,18 +33,37 @@ $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'); +ok (eq_sql + ( + $sql, + q/SELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )/, + ), + '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)'); +ok (eq_sql + ( + $sql, + qq/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `${order}`/, + ), + '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'); +ok (eq_sql + ( + $sql, + qq/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY ${order}/, + ), + 'did not quote ORDER BY with scalarref' +); $schema->storage->sql_maker->quote_char([qw/[ ]/]); $schema->storage->sql_maker->name_sep('.'); @@ -55,7 +72,13 @@ $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'); +ok (eq_sql + ( + $sql, + qq/SELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/, + ), + 'got correct SQL for count query with bracket quoting' +); my %data = ( name => 'Bill', @@ -66,6 +89,3 @@ $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'); - -$schema->storage->debugcb($orig_debugcb); -$schema->storage->debug($orig_debug); diff --git a/t/19quotes_newstyle.t b/t/19quotes_newstyle.t index 02c1450..5eb22e0 100644 --- a/t/19quotes_newstyle.t +++ b/t/19quotes_newstyle.t @@ -13,12 +13,12 @@ BEGIN { use lib qw(t/lib); +use DBIC::SqlMakerTest; +use DBIC::DebugObj; + use_ok('DBICTest'); my $schema = DBICTest->init_schema(); -my $orig_debugcb = $schema->storage->debugcb; -my $orig_debug = $schema->storage->debug; - diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); my $dsn = $schema->storage->connect_info->[0]; @@ -30,28 +30,43 @@ $schema->connection( { quote_char => '`', name_sep => '.' }, ); -my $sql = ''; -$schema->storage->debugcb(sub { $sql = $_[1] }); -$schema->storage->debug(1); - -my $rs; +my $sql; +$schema->storage->debugobj(DBIC::DebugObj->new(\$sql)); +$schema->storage->debug (1); -$rs = $schema->resultset('CD')->search( +my $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'); - +ok (eq_sql + ( + $sql, + q/SELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )/, + ), + '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)'); +ok (eq_sql + ( + $sql, + qq/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `${order}`/, + ), + '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'); +ok (eq_sql + ( + $sql, + qq/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY ${order}/, + ), + 'did not quote ORDER BY with scalarref' +); $schema->connection( $dsn, @@ -59,14 +74,20 @@ $schema->connection( undef, { AutoCommit => 1, quote_char => [qw/[ ]/], name_sep => '.' } ); -$schema->storage->debugcb(sub { $sql = $_[1] }); +$schema->storage->debugobj(DBIC::DebugObj->new(\$sql)); $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'); +ok (eq_sql + ( + $sql, + q/SELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/, + ), + 'got correct SQL for count query with bracket quoting' +); my %data = ( name => 'Bill', @@ -81,6 +102,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); diff --git a/t/41orrible.t b/t/41orrible.t index c9748b3..3e1c921 100644 --- a/t/41orrible.t +++ b/t/41orrible.t @@ -2,34 +2,44 @@ use strict; use warnings; use Test::More; -#use DBIx::Class::Storage::DBI; use DBIx::Class::Storage::DBI::Oracle::WhereJoins; +use lib qw(t/lib); +use DBIC::SqlMakerTest; + plan tests => 4; my $sa = new DBIC::SQL::Abstract::Oracle; $sa->limit_dialect('RowNum'); -is($sa->select('rubbish', - [ 'foo.id', 'bar.id', \'TO_CHAR(foo.womble, "blah")' ], - undef, undef, 1, 3), - 'SELECT * FROM -( - SELECT A.*, ROWNUM r FROM - ( - SELECT foo.id AS col1, bar.id AS col2, TO_CHAR(foo.womble, "blah") AS col3 FROM rubbish - ) A - WHERE ROWNUM < 5 -) B -WHERE r >= 4 -', 'Munged stuff to make Oracle not explode'); +ok (eq_sql + ( + $sa->select ( + 'rubbish', + [ 'foo.id', 'bar.id', \'TO_CHAR(foo.womble, "blah")' ], + undef, undef, 1, 3 + ), + q/SELECT * FROM + ( + SELECT A.*, ROWNUM r FROM + ( + SELECT foo.id AS col1, bar.id AS col2, TO_CHAR(foo.womble, "blah") AS col3 FROM rubbish + ) A + WHERE ROWNUM < 5 + ) B + WHERE r >= 4 + /, + ), + 'Munged stuff to make Oracle not explode' +); # test WhereJoins # search with undefined or empty $cond # my ($self, $table, $fields, $where, $order, @rest) = @_; -is($sa->select([ +my ($sql, @bind) = $sa->select( + [ { me => "cd" }, [ { "-join_type" => "LEFT", artist => "artist" }, @@ -38,10 +48,18 @@ is($sa->select([ ], [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ], undef, - undef), - 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( artist.artistid(+) = me.artist )', 'WhereJoins search with empty where clause'); + undef +); + +is_same_sql_bind ( + $sql, \@bind, + 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( artist.artistid(+) = me.artist )', + [], + 'WhereJoins search with empty where clause', +); -is($sa->select([ +($sql, @bind) = $sa->select( + [ { me => "cd" }, [ { "-join_type" => "", artist => "artist" }, @@ -50,10 +68,18 @@ is($sa->select([ ], [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ], { 'artist.artistid' => 3 }, - undef), - 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( ( ( artist.artistid = me.artist ) AND ( artist.artistid = ? ) ) )', 'WhereJoins search with where clause'); + undef +); -is($sa->select([ +is_same_sql_bind ( + $sql, \@bind, + 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( ( ( artist.artistid = me.artist ) AND ( artist.artistid = ? ) ) )', + [ 3 ], + 'WhereJoins search with where clause' +); + +($sql, @bind) = $sa->select( + [ { me => "cd" }, [ { "-join_type" => "LEFT", artist => "artist" }, @@ -62,7 +88,12 @@ is($sa->select([ ], [ 'cd.cdid', 'cd.artist', 'cd.title', 'cd.year', 'artist.artistid', 'artist.name' ], [{ 'artist.artistid' => 3 }, { 'me.cdid' => 5 }], - undef), - 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( ( ( artist.artistid(+) = me.artist ) AND ( ( ( artist.artistid = ? ) OR ( me.cdid = ? ) ) ) ) )', 'WhereJoins search with or in where clause'); - + undef +); +is_same_sql_bind ( + $sql, \@bind, + 'SELECT cd.cdid, cd.artist, cd.title, cd.year, artist.artistid, artist.name FROM cd me, artist artist WHERE ( ( ( artist.artistid(+) = me.artist ) AND ( ( ( artist.artistid = ? ) OR ( me.cdid = ? ) ) ) ) )', + [ 3, 5 ], + 'WhereJoins search with or in where clause' +); diff --git a/t/76joins.t b/t/76joins.t index 101d71f..69426fd 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -5,6 +5,7 @@ use Test::More; use lib qw(t/lib); use DBICTest; use Data::Dumper; +use DBIC::SqlMakerTest; my $schema = DBICTest->init_schema(); @@ -43,7 +44,13 @@ 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( $sa->_recurse_from(@j), $match, 'join 1 ok' ); +ok (eq_sql + ( + $sa->_recurse_from(@j), + $match, + ), + 'join 1 ok' +); my @j2 = ( { mother => 'person' }, @@ -59,7 +66,14 @@ $match = 'person mother JOIN (person child JOIN person father ON (' . ' father.person_id = child.father_id )) ON ( mother.person_id = ' . 'child.mother_id )' ; -is( $sa->_recurse_from(@j2), $match, 'join 2 ok' ); +ok (eq_sql + ( + $sa->_recurse_from(@j2), + $match, + ), + 'join 2 ok' +); + my @j3 = ( { child => 'person' }, @@ -71,7 +85,13 @@ $match = 'person child INNER JOIN person father ON ( father.person_id = ' . '= child.mother_id )' ; -is( $sa->_recurse_from(@j3), $match, 'join 3 (inner join) ok'); +ok (eq_sql + ( + $sa->_recurse_from(@j3), + $match, + ), + 'join 3 (inner join) ok' +); my @j4 = ( { mother => 'person' }, @@ -87,7 +107,13 @@ $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( $sa->_recurse_from(@j4), $match, 'join 4 (nested joins + join types) ok'); +ok (eq_sql + ( + $sa->_recurse_from(@j4), + $match, + ), + 'join 4 (nested joins + join types) ok' +); my @j5 = ( { child => 'person' }, @@ -98,7 +124,13 @@ $match = 'person child JOIN person father ON ( father.person_id != ' . 'child.father_id ) JOIN person mother ON ( mother.person_id ' . '= child.mother_id )' ; -is( $sa->_recurse_from(@j5), $match, 'join 5 (SCALAR reference for ON statement) ok' ); +ok (eq_sql + ( + $sa->_recurse_from(@j5), + $match, + ), + 'join 5 (SCALAR reference for ON statement) ok' +); my @j6 = ( { child => 'person' }, diff --git a/t/91debug.t b/t/91debug.t index 68e7c57..50de1e3 100644 --- a/t/91debug.t +++ b/t/91debug.t @@ -4,6 +4,8 @@ use warnings; use Test::More; use lib qw(t/lib); use DBICTest; +use DBIC::SqlMakerTest; +use DBIC::DebugObj; my $schema = DBICTest->init_schema(); @@ -49,13 +51,15 @@ open(STDERR, '>&STDERRCOPY'); # test trace output correctness for bind params { - my $sql = ''; - $schema->storage->debugcb( sub { $sql = $_[1] } ); + my ($sql, @bind); + $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)); + $schema->storage->debug(1); my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } ); - like( - $sql, - qr/\QSELECT me.cdid, me.artist, me.title, me.year FROM cd me WHERE ( artist = ? AND cdid BETWEEN ? AND ? ): '1', '1', '3'\E/, + is_same_sql_bind ( + $sql, \@bind, + q/SELECT me.cdid, me.artist, me.title, me.year FROM cd me WHERE ( artist = ? AND cdid BETWEEN ? AND ? )/, + [qw/'1' '1' '3'/], 'got correct SQL with all bind parameters' ); } diff --git a/t/95sql_maker_quote.t b/t/95sql_maker_quote.t index 1f4cd90..80b180f 100644 --- a/t/95sql_maker_quote.t +++ b/t/95sql_maker_quote.t @@ -3,6 +3,8 @@ use warnings; use Test::More; +use lib qw(t/lib); +use DBIC::SqlMakerTest; BEGIN { eval "use DBD::SQLite"; @@ -11,8 +13,6 @@ BEGIN { : ( tests => 8 ); } -use lib qw(t/lib); - use_ok('DBICTest'); my $schema = DBICTest->init_schema(); @@ -22,7 +22,7 @@ my $sql_maker = $schema->storage->sql_maker; $sql_maker->quote_char('`'); $sql_maker->name_sep('.'); -my ($sql,) = $sql_maker->select( +my ($sql, @bind) = $sql_maker->select( [ { 'me' => 'cd' @@ -51,11 +51,15 @@ my ($sql,) = $sql_maker->select( undef ); -is($sql, - q/SELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )/, - 'got correct SQL for count query with quoting'); +is_same_sql_bind( + $sql, \@bind, + q/SELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )/, + [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ], + 'got correct SQL and bind parameters for count query with quoting' +); + -($sql,) = $sql_maker->select( +($sql, @bind) = $sql_maker->select( [ { 'me' => 'cd' @@ -78,15 +82,17 @@ is($sql, TODO: { local $TODO = "order_by with quoting needs fixing (ash/castaway)"; - is($sql, - q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC/, - 'quoted ORDER BY with DESC okay'); + is_same_sql_bind( + $sql, \@bind, + q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`/, [], + 'scalar ORDER BY okay (single value)' + ); } TODO: { local $TODO = "select attr with star needs fixing (mst/nate)"; - ($sql,) = $sql_maker->select( + ($sql, @bind) = $sql_maker->select( [ { 'me' => 'cd' @@ -98,13 +104,17 @@ TODO: { undef, [], undef, - undef + undef ); - is($sql, q/SELECT `me`.* FROM `cd` `me`/, 'select attr with me.* is right'); + is_same_sql_bind( + $sql, \@bind, + q/SELECT `me`.* FROM `cd` `me`/, [], + 'select attr with me.* is right' + ); } -($sql,) = $sql_maker->select( +($sql, @bind) = $sql_maker->select( [ { 'me' => 'cd' @@ -124,18 +134,14 @@ TODO: { undef ); -is($sql, - q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC/, - 'did not quote ORDER BY with scalarref'); - -my %data = ( - name => 'Bill', - order => 12 +is_same_sql_bind( + $sql, \@bind, + q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC/, [], + 'did not quote ORDER BY with scalarref' ); -my @binds; -($sql,@binds) = $sql_maker->update( +($sql, @bind) = $sql_maker->update( 'group', { 'order' => '12', @@ -143,13 +149,15 @@ my @binds; } ); -is($sql, - q/UPDATE `group` SET `name` = ?, `order` = ?/, - 'quoted table names for UPDATE'); +is_same_sql_bind( + $sql, \@bind, + q/UPDATE `group` SET `name` = ?, `order` = ?/, [ ['name' => 'Bill'], ['order' => '12'] ], + 'quoted table names for UPDATE' +); $sql_maker->quote_char([qw/[ ]/]); -($sql,) = $sql_maker->select( +($sql, @bind) = $sql_maker->select( [ { 'me' => 'cd' @@ -178,12 +186,14 @@ $sql_maker->quote_char([qw/[ ]/]); undef ); -is($sql, - q/SELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/, - 'got correct SQL for count query with bracket quoting'); +is_same_sql_bind( + $sql, \@bind, + q/SELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/, [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ], + 'got correct SQL and bind parameters for count query with bracket quoting' +); -($sql,@binds) = $sql_maker->update( +($sql, @bind) = $sql_maker->update( 'group', { 'order' => '12', @@ -191,6 +201,8 @@ is($sql, } ); -is($sql, - q/UPDATE [group] SET [name] = ?, [order] = ?/, - 'bracket quoted table names for UPDATE'); +is_same_sql_bind( + $sql, \@bind, + q/UPDATE [group] SET [name] = ?, [order] = ?/, [ ['name' => 'Bill'], ['order' => '12'] ], + 'bracket quoted table names for UPDATE' +);