From: Peter Rabbitson Date: Thu, 29 Mar 2012 02:53:28 +0000 (+0200) Subject: Do not alias plain column names to the inflator spec, do it only for funcs X-Git-Tag: v0.08197~37^2~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=90ed89cbd9951c4eeccb227b586b200eb34574d2;p=dbsrgits%2FDBIx-Class.git Do not alias plain column names to the inflator spec, do it only for funcs This solves a problem with deliberate column renames in complex subqueries --- diff --git a/lib/DBIx/Class/SQLMaker/LimitDialects.pm b/lib/DBIx/Class/SQLMaker/LimitDialects.pm index e9a1c87..1c16805 100644 --- a/lib/DBIx/Class/SQLMaker/LimitDialects.pm +++ b/lib/DBIx/Class/SQLMaker/LimitDialects.pm @@ -702,6 +702,7 @@ sub _subqueried_limit_attrs { my $sql_alias = (ref $s) eq 'HASH' ? $s->{-as} : undef; push @sel, { + arg => $s, sql => $sql_sel, unquoted_sql => do { local $self->{quote_char}; @@ -749,7 +750,7 @@ sub _subqueried_limit_attrs { } else { push @{$sel->{inner}}, $node->{sql}; - push @{$sel->{outer}}, $self->_quote ($node->{as}); + push @{$sel->{outer}}, $self->_quote (ref $node->{arg} ? $node->{as} : $node->{arg}); } } diff --git a/t/73oracle_hq.t b/t/73oracle_hq.t index de4673b..8189479 100644 --- a/t/73oracle_hq.t +++ b/t/73oracle_hq.t @@ -325,7 +325,7 @@ do_creates($dbh); is_same_sql_bind ( $rs->as_query, '( - SELECT artistid, name, rank, charfield, parentid + SELECT me.artistid, me.name, me.rank, me.charfield, me.parentid FROM ( SELECT me.artistid, me.name, me.rank, me.charfield, me.parentid FROM artist me @@ -352,7 +352,7 @@ do_creates($dbh); '( SELECT COUNT( * ) FROM ( - SELECT artistid + SELECT me.artistid FROM ( SELECT me.artistid FROM artist me diff --git a/t/sqlmaker/limit_dialects/fetch_first.t b/t/sqlmaker/limit_dialects/fetch_first.t index fcb08d5..8c7fa47 100644 --- a/t/sqlmaker/limit_dialects/fetch_first.t +++ b/t/sqlmaker/limit_dialects/fetch_first.t @@ -27,7 +27,7 @@ for my $null_order ( my $rs = $books_45_and_owners->search ({}, {order_by => $null_order }); is_same_sql_bind( $rs->as_query, - '(SELECT id, source, owner, price, owner__id, owner__name + '(SELECT me.id, me.source, me.owner, me.price, owner__id, owner__name FROM ( SELECT me.id, me.source, me.owner, me.price, owner.id AS owner__id, owner.name AS owner__name FROM books me @@ -126,9 +126,9 @@ for my $ord_set ( is_same_sql_bind( $books_45_and_owners->search ({}, {order_by => $ord_set->{order_by}})->as_query, - "(SELECT id, source, owner, price, owner__id, owner__name + "(SELECT me.id, me.source, me.owner, me.price, owner__id, owner__name FROM ( - SELECT id, source, owner, price, owner__id, owner__name$o_sel + SELECT me.id, me.source, me.owner, me.price, owner__id, owner__name$o_sel FROM ( SELECT me.id, me.source, me.owner, me.price, owner.id AS owner__id, owner.name AS owner__name$i_sel FROM books me @@ -152,9 +152,9 @@ is_same_sql_bind ( $books_45_and_owners->search ({}, { group_by => 'title', order_by => 'title' })->as_query, '(SELECT me.id, me.source, me.owner, me.price, owner.id, owner.name FROM ( - SELECT id, source, owner, price, ORDER__BY__1 AS title + SELECT me.id, me.source, me.owner, me.price, ORDER__BY__1 AS title FROM ( - SELECT id, source, owner, price, ORDER__BY__1 + SELECT me.id, me.source, me.owner, me.price, ORDER__BY__1 FROM ( SELECT me.id, me.source, me.owner, me.price, title AS ORDER__BY__1 FROM books me diff --git a/t/sqlmaker/limit_dialects/generic_subq.t b/t/sqlmaker/limit_dialects/generic_subq.t index 8b4b056..2d483e9 100644 --- a/t/sqlmaker/limit_dialects/generic_subq.t +++ b/t/sqlmaker/limit_dialects/generic_subq.t @@ -27,7 +27,7 @@ my $rs = $schema->resultset ('BooksInLibrary')->search ({}, { is_same_sql_bind( $rs->as_query, '( - SELECT id, source, owner, title, price, + SELECT me.id, me.source, me.owner, me.title, me.price, owner_name FROM ( SELECT me.id, me.source, me.owner, me.title, me.price, @@ -71,7 +71,7 @@ $rs = $schema->resultset ('BooksInLibrary')->search ({}, { is_same_sql_bind( $rs->as_query, '( - SELECT "id", "source", "owner", "title", "price", + SELECT "me"."id", "me"."source", "me"."owner", "me"."title", "me"."price", "owner__name" FROM ( SELECT "me"."id", "me"."source", "me"."owner", "me"."title", "me"."price", diff --git a/t/sqlmaker/limit_dialects/rno.t b/t/sqlmaker/limit_dialects/rno.t index 58c38b5..4f24e56 100644 --- a/t/sqlmaker/limit_dialects/rno.t +++ b/t/sqlmaker/limit_dialects/rno.t @@ -26,10 +26,10 @@ my $rs_selectas_col = $schema->resultset ('BooksInLibrary')->search ({}, { is_same_sql_bind( $rs_selectas_col->as_query, '( - SELECT id, source, owner, title, price, + SELECT me.id, me.source, me.owner, me.title, me.price, owner__name FROM ( - SELECT id, source, owner, title, price, + SELECT me.id, me.source, me.owner, me.title, me.price, owner__name, ROW_NUMBER() OVER( ) AS rno__row__index FROM ( @@ -62,10 +62,10 @@ my $rs_selectas_rel = $schema->resultset ('BooksInLibrary')->search ({}, { is_same_sql_bind( $rs_selectas_rel->as_query, '( - SELECT [id], [source], [owner], [title], [price], + SELECT [me].[id], [me].[source], [me].[owner], [me].[title], [me].[price], [owner_name] FROM ( - SELECT [id], [source], [owner], [title], [price], + SELECT [me].[id], [me].[source], [me].[owner], [me].[title], [me].[price], [owner_name], ROW_NUMBER() OVER( ) AS [rno__row__index] FROM ( @@ -198,8 +198,8 @@ my $rs_selectas_rel = $schema->resultset('BooksInLibrary')->search( { -exists => is_same_sql_bind( $rs_selectas_rel->as_query, '( - SELECT [id], [owner] FROM ( - SELECT [id], [owner], ROW_NUMBER() OVER( ) AS [rno__row__index] FROM ( + SELECT [me].[id], [me].[owner] FROM ( + SELECT [me].[id], [me].[owner], ROW_NUMBER() OVER( ) AS [rno__row__index] FROM ( SELECT [me].[id], [me].[owner] FROM [books] [me] WHERE ( ( (EXISTS ( diff --git a/t/sqlmaker/limit_dialects/rownum.t b/t/sqlmaker/limit_dialects/rownum.t index 8eefd17..2f46599 100644 --- a/t/sqlmaker/limit_dialects/rownum.t +++ b/t/sqlmaker/limit_dialects/rownum.t @@ -244,7 +244,7 @@ my $rs_selectas_rel = $s->resultset('BooksInLibrary')->search( { -exists => $sub is_same_sql_bind( $rs_selectas_rel->as_query, '( - SELECT id, owner FROM ( + SELECT me.id, me.owner FROM ( SELECT me.id, me.owner FROM books me WHERE ( ( (EXISTS (SELECT COUNT( * ) FROM owners owner WHERE ( books.owner = owner.id ))) AND source = ? ) ) ) me WHERE ROWNUM <= ? diff --git a/t/sqlmaker/limit_dialects/toplimit.t b/t/sqlmaker/limit_dialects/toplimit.t index 8ac32fc..2f86103 100644 --- a/t/sqlmaker/limit_dialects/toplimit.t +++ b/t/sqlmaker/limit_dialects/toplimit.t @@ -30,7 +30,7 @@ for my $null_order ( is_same_sql_bind( $rs->as_query, '(SELECT TOP 2 - id, source, owner, price, owner__id, owner__name + me.id, me.source, me.owner, me.price, owner__id, owner__name FROM ( SELECT TOP 5 me.id, me.source, me.owner, me.price, owner.id AS owner__id, owner.name AS owner__name @@ -166,10 +166,10 @@ for my $ord_set ( is_same_sql_bind( $books_45_and_owners->search ({}, {order_by => $ord_set->{order_by}})->as_query, - "(SELECT id, source, owner, price, owner__id, owner__name + "(SELECT me.id, me.source, me.owner, me.price, owner__id, owner__name FROM ( SELECT TOP 2 - id, source, owner, price, owner__id, owner__name$o_sel + me.id, me.source, me.owner, me.price, owner__id, owner__name$o_sel FROM ( SELECT TOP 5 me.id, me.source, me.owner, me.price, owner.id AS owner__id, owner.name AS owner__name$i_sel @@ -192,10 +192,10 @@ is_same_sql_bind ( $books_45_and_owners->search ({}, { group_by => 'title', order_by => 'title' })->as_query, '(SELECT me.id, me.source, me.owner, me.price, owner.id, owner.name FROM ( - SELECT id, source, owner, price, ORDER__BY__1 AS title + SELECT me.id, me.source, me.owner, me.price, ORDER__BY__1 AS title FROM ( SELECT TOP 2 - id, source, owner, price, ORDER__BY__1 + me.id, me.source, me.owner, me.price, ORDER__BY__1 FROM ( SELECT TOP 5 me.id, me.source, me.owner, me.price, title AS ORDER__BY__1