X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F95sql_maker_quote.t;h=e7fbb60eb3ebf75884d68bfefeb8e92fb744e38a;hb=b2b2e7fddfd45a365a5cab9c7c9371b1c2557741;hp=a7687f8f461ae372824c25c3046d8c6acb5b7a7c;hpb=20ea616f0157ae01c3af89ce6faa04e1da8248f4;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/95sql_maker_quote.t b/t/95sql_maker_quote.t index a7687f8..e7fbb60 100644 --- a/t/95sql_maker_quote.t +++ b/t/95sql_maker_quote.t @@ -35,12 +35,21 @@ my ($sql, @bind) = $sql_maker->select( { 'artist.artistid' => 'me.artist' } - ] + ], + [ + { + 'tracks' => 'tracks', + '-join_type' => 'left' + }, + { + 'tracks.cd' => 'me.cdid' + } + ], ], [ - { - 'count' => '*' - } + 'me.cdid', + { count => 'tracks.cd' }, + { min => 'me.year', -as => 'me.minyear' }, ], { 'artist.name' => 'Caterwauler McCrae', @@ -53,8 +62,15 @@ my ($sql, @bind) = $sql_maker->select( 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' + q/ + SELECT `me`.`cdid`, COUNT( `tracks`.`cd` ), MIN( `me`.`year` ) AS `me`.`minyear` + FROM `cd` `me` + JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) + LEFT JOIN `tracks` `tracks` ON ( `tracks`.`cd` = `me`.`cdid` ) + WHERE ( `artist`.`name` = ? AND `me`.`year` = ? ) + /, + [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ], + 'got correct SQL and bind parameters for complex select query with quoting' ); @@ -276,7 +292,13 @@ $sql_maker->quote_char([qw/[ ]/]); ], [ { - 'count' => '*' + max => 'rank', + -as => 'max_rank', + }, + 'rank', + { + 'count' => '*', + -as => 'cnt', } ], { @@ -290,7 +312,7 @@ $sql_maker->quote_char([qw/[ ]/]); 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] ], + q/SELECT MAX ( [rank] ) AS [max_rank], [rank], COUNT( * ) AS [cnt] 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' );