X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSQLMaker%2FLimitDialects.pm;h=1c304363557e63905abd9e49c0d2a1ecd0137eb2;hb=19c4cc62860c3d1d497dd2a3f119a72085caa61d;hp=e189e2c7cd36d94fd06acc47128fd1ad5d9da8db;hpb=e5372da42c1bb393cd2aadde5765a09d64428581;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/SQLMaker/LimitDialects.pm b/lib/DBIx/Class/SQLMaker/LimitDialects.pm index e189e2c..1c30436 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; } @@ -266,8 +265,8 @@ sub _FirstSkip { SELECT * FROM ( SELECT *, ROWNUM rownum__index FROM ( SELECT ... - ) - ) WHERE rownum__index BETWEEN ($offset+1) AND ($limit+$offset) + ) WHERE ROWNUM <= ($limit+$offset) + ) WHERE rownum__index >= ($offset+1) Supported by B. @@ -285,17 +284,28 @@ sub _RowNum { my $idx_name = $self->_quote ('rownum__index'); my $order_group_having = $self->_parse_rs_attrs($rs_attrs); - $sql = sprintf (<= %u EOS + } + else { + $sql = sprintf (<{alias}, $self->{name_sep}||'.', $_ ) } - ( $rs_attrs->{_rsroot_source_handle}->resolve->_pri_cols ) + { "$rs_attrs->{alias}.$_" } + ( $rs_attrs->{_rsroot_rsrc}->_pri_cols ) ] ); @@ -378,9 +388,9 @@ sub _Top { # since whatever order bindvals there are, they will be realiased # and need to show up in front of the entire initial inner subquery - # Unshift *from_bind* to make this happen (horrible, horrible, but - # we don't have another mechanism yet) - unshift @{$self->{from_bind}}, @{$self->{order_bind}}; + # *unshift* the selector bind stack to make this happen (horrible, + # horrible, but we don't have another mechanism yet) + unshift @{$self->{select_bind}}, @{$self->{order_bind}}; } # and this is order re-alias magic @@ -421,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; } @@ -472,7 +481,7 @@ Currently used by B, due to lack of any other option. sub _GenericSubQ { my ($self, $sql, $rs_attrs, $rows, $offset) = @_; - my $root_rsrc = $rs_attrs->{_rsroot_source_handle}->resolve; + my $root_rsrc = $rs_attrs->{_rsroot_rsrc}; my $root_tbl_name = $root_rsrc->name; # mangle the input sql as we will be replacing the selector @@ -567,7 +576,6 @@ EOS , ); - $sql =~ s/\s*\n\s*/ /g; # easier to read in the debugger return $sql; } @@ -596,10 +604,7 @@ sub _subqueried_limit_attrs { croak 'Limit dialect implementation usable only in the context of DBIC (missing $rs_attrs)' unless ref ($rs_attrs) eq 'HASH'; - my ($re_sep, $re_alias) = map { quotemeta $_ } ( - $self->name_sep || '.', - $rs_attrs->{alias}, - ); + my ($re_sep, $re_alias) = map { quotemeta $_ } ( $self->{name_sep}, $rs_attrs->{alias} ); # correlate select and as, build selection index my (@sel, $in_sel_index); @@ -639,7 +644,11 @@ sub _subqueried_limit_attrs { # for possible further chaining) my (@in_sel, @out_sel, %renamed); for my $node (@sel) { - if (first { $_ =~ / (?{as}, $node->{unquoted_sql}) ) { + if ( + $node->{as} =~ / (?{unquoted_sql} =~ / (?{as} = $self->_unqualify_colname($node->{as}); my $quoted_as = $self->_quote($node->{as}); push @in_sel, sprintf '%s AS %s', $node->{sql}, $quoted_as; @@ -678,8 +687,7 @@ sub _subqueried_limit_attrs { sub _unqualify_colname { my ($self, $fqcn) = @_; - my $re_sep = quotemeta($self->name_sep || '.'); - $fqcn =~ s/ $re_sep /__/xg; + $fqcn =~ s/ \. /__/xg; return $fqcn; }