From: Peter Rabbitson Date: Wed, 15 Dec 2010 15:58:46 +0000 (+0100) Subject: Stop mangling sql on the way out of the limit dialects X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d763268755f6b9ee1d0d4d8442d989ef7c5a4d7d;hp=a6646e1b0a25acfd21cc3e32b8c479dd0f3526ef;p=dbsrgits%2FDBIx-Class-Historic.git Stop mangling sql on the way out of the limit dialects --- diff --git a/Changes b/Changes index 554b9d8..ed1bfa4 100644 --- a/Changes +++ b/Changes @@ -37,6 +37,8 @@ Revision history for DBIx::Class - Fix count of grouped resultsets using HAVING with aliases - Setting belongs_to columns/relationships no longer leaves the FK value and related object out of sync + - Stop stripping newlines from SQL statements in the limit emulators + as it is possible that custom sql with comments was provided * Misc - Switch all serialization to use Storable::nfreeze for portable diff --git a/lib/DBIx/Class/SQLMaker/LimitDialects.pm b/lib/DBIx/Class/SQLMaker/LimitDialects.pm index 846cab7..bb884d7 100644 --- a/lib/DBIx/Class/SQLMaker/LimitDialects.pm +++ b/lib/DBIx/Class/SQLMaker/LimitDialects.pm @@ -202,7 +202,6 @@ SELECT $out_sel FROM ( EOS - $sql =~ s/\s*\n\s*/ /g; # easier to read in the debugger return $sql; } @@ -307,7 +306,6 @@ EOS EOS } - $sql =~ s/\s*\n\s*/ /g; # easier to read in the debugger return $sql; } @@ -433,7 +431,6 @@ sub _Top { $order_by_requested, ) if ( ($offset && $order_by_requested) || ($mid_sel ne $out_sel) ); - $sql =~ s/\s*\n\s*/ /g; # easier to read in the debugger return $sql; } @@ -579,7 +576,6 @@ EOS , ); - $sql =~ s/\s*\n\s*/ /g; # easier to read in the debugger return $sql; } diff --git a/t/sqlmaker/limit_dialects/generic_subq.t b/t/sqlmaker/limit_dialects/generic_subq.t index 8bd47b7..9e771a9 100644 --- a/t/sqlmaker/limit_dialects/generic_subq.t +++ b/t/sqlmaker/limit_dialects/generic_subq.t @@ -122,4 +122,19 @@ is_deeply ( 'Correct columns selected with rows', ); +{ + $rs = $schema->resultset('Artist')->search({}, { + columns => 'name', + offset => 1, + order_by => 'name', + }); + local $rs->result_source->{name} = "weird \n newline/multi \t \t space containing \n table"; + + like ( + ${$rs->as_query}->[0], + qr| weird \s \n \s newline/multi \s \t \s \t \s space \s containing \s \n \s table|x, + 'Newlines/spaces preserved in final sql', + ); +} + done_testing; diff --git a/t/sqlmaker/limit_dialects/rno.t b/t/sqlmaker/limit_dialects/rno.t index dc598c0..4b96a65 100644 --- a/t/sqlmaker/limit_dialects/rno.t +++ b/t/sqlmaker/limit_dialects/rno.t @@ -71,4 +71,20 @@ is_same_sql_bind( [ [ 'source', 'Library' ] ], ); +{ + my $rs = $schema->resultset('Artist')->search({}, { + columns => 'name', + offset => 1, + order_by => 'name', + }); + local $rs->result_source->{name} = "weird \n newline/multi \t \t space containing \n table"; + + like ( + ${$rs->as_query}->[0], + qr| weird \s \n \s newline/multi \s \t \s \t \s space \s containing \s \n \s table|x, + 'Newlines/spaces preserved in final sql', + ); +} + + done_testing; diff --git a/t/sqlmaker/limit_dialects/rownum.t b/t/sqlmaker/limit_dialects/rownum.t index 909367b..2fa12ca 100644 --- a/t/sqlmaker/limit_dialects/rownum.t +++ b/t/sqlmaker/limit_dialects/rownum.t @@ -54,4 +54,20 @@ is_same_sql_bind ( 'Rownum subsel aliasing works correctly' ); +{ + $rs = $s->resultset('Artist')->search({}, { + columns => 'name', + offset => 1, + order_by => 'name', + }); + local $rs->result_source->{name} = "weird \n newline/multi \t \t space containing \n table"; + + like ( + ${$rs->as_query}->[0], + qr| weird \s \n \s newline/multi \s \t \s \t \s space \s containing \s \n \s table|x, + 'Newlines/spaces preserved in final sql', + ); +} + + done_testing; diff --git a/t/sqlmaker/limit_dialects/toplimit.t b/t/sqlmaker/limit_dialects/toplimit.t index 16f64dc..29ef966 100644 --- a/t/sqlmaker/limit_dialects/toplimit.t +++ b/t/sqlmaker/limit_dialects/toplimit.t @@ -194,4 +194,19 @@ is_same_sql_bind( $rs_selectas_top->search({})->as_query, [ [ 'source', 'Library' ] ], ); +{ + my $rs = $schema->resultset('Artist')->search({}, { + columns => 'name', + offset => 1, + order_by => 'name', + }); + local $rs->result_source->{name} = "weird \n newline/multi \t \t space containing \n table"; + + like ( + ${$rs->as_query}->[0], + qr| weird \s \n \s newline/multi \s \t \s \t \s space \s containing \s \n \s table|x, + 'Newlines/spaces preserved in final sql', + ); +} + done_testing;