X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F95sql_maker_quote.t;h=a7687f8f461ae372824c25c3046d8c6acb5b7a7c;hb=88e12210acdb453298f90cab7296e538c44bb593;hp=7f8b72caf4a90964ba61963c5cfe97d3e9c65389;hpb=9b4591296c196ea0a32e67159e35091b02ecc539;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/95sql_maker_quote.t b/t/95sql_maker_quote.t index 7f8b72c..a7687f8 100644 --- a/t/95sql_maker_quote.t +++ b/t/95sql_maker_quote.t @@ -2,18 +2,17 @@ use strict; use warnings; use Test::More; -use SQL::Abstract::Test import => ['is_same_sql_bind']; +use lib qw(t/lib); +use DBIC::SqlMakerTest; BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 8 ); + : ( tests => 12 ); } -use lib qw(t/lib); - use_ok('DBICTest'); my $schema = DBICTest->init_schema(); @@ -58,6 +57,7 @@ is_same_sql_bind( 'got correct SQL and bind parameters for count query with quoting' ); + ($sql, @bind) = $sql_maker->select( [ { @@ -71,45 +71,125 @@ is_same_sql_bind( 'me.year' ], undef, + 'year DESC', + undef, + undef +); + +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)' +); + + +($sql, @bind) = $sql_maker->select( [ - 'year DESC' + { + 'me' => 'cd' + } + ], + [ + 'me.cdid', + 'me.artist', + 'me.title', + 'me.year' + ], + undef, + [ + 'year DESC', + 'title ASC' ], undef, undef ); -TODO: { - local $TODO = "order_by with quoting needs fixing (ash/castaway)"; +is_same_sql_bind( + $sql, \@bind, + q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`, `title ASC`/, [], + 'scalar ORDER BY okay (multiple values)' +); + +{ + ($sql, @bind) = $sql_maker->select( + [ + { + 'me' => 'cd' + } + ], + [ + 'me.cdid', + 'me.artist', + 'me.title', + 'me.year' + ], + undef, + { -desc => 'year' }, + undef, + undef + ); + + is_same_sql_bind( + $sql, \@bind, + q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC/, [], + 'hashref ORDER BY okay (single value)' + ); + + + ($sql, @bind) = $sql_maker->select( + [ + { + 'me' => 'cd' + } + ], + [ + 'me.cdid', + 'me.artist', + 'me.title', + 'me.year' + ], + undef, + [ + { -desc => 'year' }, + { -asc => 'title' } + ], + undef, + undef + ); + + is_same_sql_bind( + $sql, \@bind, + q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC, `title` ASC/, [], + 'hashref ORDER BY okay (multiple values)' + ); - 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'); } -TODO: { - local $TODO = "select attr with star needs fixing (mst/nate)"; - ($sql, @bind) = $sql_maker->select( +($sql, @bind) = $sql_maker->select( [ { 'me' => 'cd' } ], [ - 'me.*' + 'me.cdid', + 'me.artist', + 'me.title', + 'me.year' ], undef, - [], + \'year DESC', undef, - undef - ); - - is_same_sql_bind( - $sql, \@bind, - q/SELECT `me`.* FROM `cd` `me`/, [], - 'select attr with me.* is right' - ); -} + undef +); + +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 (single value)' +); + ($sql, @bind) = $sql_maker->select( [ @@ -125,7 +205,8 @@ TODO: { ], undef, [ - \'year DESC' + \'year DESC', + \'title ASC' ], undef, undef @@ -133,10 +214,11 @@ TODO: { 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' + q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC, title ASC/, [], + 'did not quote ORDER BY with scalarref (multiple values)' ); + ($sql, @bind) = $sql_maker->update( 'group', { @@ -151,6 +233,30 @@ is_same_sql_bind( 'quoted table names for UPDATE' ); +{ + ($sql, @bind) = $sql_maker->select( + [ + { + 'me' => 'cd' + } + ], + [ + 'me.*' + ], + undef, + [], + undef, + undef + ); + + is_same_sql_bind( + $sql, \@bind, + q/SELECT `me`.* FROM `cd` `me`/, [], + 'select attr with me.* is right' + ); +} + + $sql_maker->quote_char([qw/[ ]/]); ($sql, @bind) = $sql_maker->select(