From: Norbert Buchmuller Date: Fri, 21 Nov 2008 23:11:16 +0000 (+0100) Subject: * Test cases for every supported order_by syntax. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c80207cdf08857a9d96124ec1f58d2a774816f92;p=dbsrgits%2FDBIx-Class-Historic.git * Test cases for every supported order_by syntax. --- diff --git a/t/95sql_maker_quote.t b/t/95sql_maker_quote.t index 5dd71a8..56a8072 100644 --- a/t/95sql_maker_quote.t +++ b/t/95sql_maker_quote.t @@ -9,7 +9,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 8 ); + : ( tests => 12 ); } use lib qw(t/lib); @@ -58,6 +58,7 @@ is_same_sql_bind( 'got correct SQL and bind parameters for count query with quoting' ); + ($sql, @bind) = $sql_maker->select( [ { @@ -71,8 +72,34 @@ 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( [ - { -desc => 'year' } + { + 'me' => 'cd' + } + ], + [ + 'me.cdid', + 'me.artist', + 'me.title', + 'me.year' + ], + undef, + [ + 'year DESC', + 'title ASC' ], undef, undef @@ -80,32 +107,36 @@ is_same_sql_bind( 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' + 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.*' - ], - undef, - [], - undef, - undef + [ + { + 'me' => 'cd' + } + ], + [ + 'me.cdid', + 'me.artist', + 'me.title', + 'me.year' + ], + undef, + { -desc => 'year' }, + undef, + undef ); is_same_sql_bind( $sql, \@bind, - q/SELECT `me`.* FROM `cd` `me`/, [], - 'select attr with me.* is right' + 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( [ { @@ -120,18 +151,73 @@ is_same_sql_bind( ], undef, [ - \'year DESC' + { -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)' +); + + +($sql, @bind) = $sql_maker->select( + [ + { + 'me' => 'cd' + } + ], + [ + 'me.cdid', + 'me.artist', + 'me.title', + '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/, [], - 'did not quote ORDER BY with scalarref' + 'did not quote ORDER BY with scalarref (single value)' +); + + +($sql, @bind) = $sql_maker->select( + [ + { + 'me' => 'cd' + } + ], + [ + 'me.cdid', + 'me.artist', + 'me.title', + 'me.year' + ], + undef, + [ + \'year DESC', + \'title ASC' + ], + 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/, [], + 'did not quote ORDER BY with scalarref (multiple values)' ); + ($sql, @bind) = $sql_maker->update( 'group', { @@ -146,6 +232,29 @@ 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(