X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSQLMaker%2FLimitDialects.pm;h=da65b7c2e9fa8dfefa32261289c57fb152ce8db3;hb=4faaf174b94290230f2ebb2cc5077bc11752f69c;hp=1f0637722b9f40a730492435f00261aa6a600ddc;hpb=318e3d94c5332d5af335706b26fc5b6f6fc5c703;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/SQLMaker/LimitDialects.pm b/lib/DBIx/Class/SQLMaker/LimitDialects.pm index 1f06377..da65b7c 100644 --- a/lib/DBIx/Class/SQLMaker/LimitDialects.pm +++ b/lib/DBIx/Class/SQLMaker/LimitDialects.pm @@ -221,7 +221,7 @@ sub _FirstSkip { Depending on the resultset attributes one of: SELECT * FROM ( - SELECT *, ROWNUM rownum__index FROM ( + SELECT *, ROWNUM AS rownum__index FROM ( SELECT ... ) WHERE ROWNUM <= ($limit+$offset) ) WHERE rownum__index >= ($offset+1) @@ -229,7 +229,7 @@ Depending on the resultset attributes one of: or SELECT * FROM ( - SELECT *, ROWNUM rownum__index FROM ( + SELECT *, ROWNUM AS rownum__index FROM ( SELECT ... ) ) WHERE rownum__index BETWEEN ($offset+1) AND ($limit+$offset) @@ -286,7 +286,7 @@ EOS return <{selection_outer} FROM ( - SELECT $sq_attrs->{selection_outer}, ROWNUM $idx_name FROM ( + SELECT $sq_attrs->{selection_outer}, ROWNUM AS $idx_name FROM ( SELECT $sq_attrs->{selection_inner} $sq_attrs->{query_leftover}${order_group_having} ) $qalias WHERE ROWNUM <= ? ) $qalias WHERE $idx_name >= ? @@ -297,7 +297,7 @@ EOS return <{selection_outer} FROM ( - SELECT $sq_attrs->{selection_outer}, ROWNUM $idx_name FROM ( + SELECT $sq_attrs->{selection_outer}, ROWNUM AS $idx_name FROM ( SELECT $sq_attrs->{selection_inner} $sq_attrs->{query_leftover}${order_group_having} ) $qalias ) $qalias WHERE $idx_name BETWEEN ? AND ? @@ -358,12 +358,10 @@ sub _prep_for_skimming_limit { for my $ch ($self->_order_by_chunks ($inner_order)) { $ch = $ch->[0] if ref $ch eq 'ARRAY'; - my $is_desc = ( - $ch =~ s/\s+ ( ASC|DESC ) \s* $//ix - and - uc($1) eq 'DESC' - ) ? 1 : 0; - push @out_chunks, \join (' ', $ch, $is_desc ? 'ASC' : 'DESC' ); + ($ch, my $is_desc) = $self->_split_order_chunk($ch); + + # !NOTE! outside chunks come in reverse order ( !$is_desc ) + push @out_chunks, { ($is_desc ? '-asc' : '-desc') => \$ch }; } $sq_attrs->{order_by_middle} = $self->_order_by (\@out_chunks); @@ -583,11 +581,7 @@ sub _GenericSubQ { for my $bit (@order_bits) { - my $is_desc = ( - $bit =~ s/\s+ ( ASC|DESC ) \s* $//ix - and - uc($1) eq 'DESC' - ) ? 1 : 0; + ($bit, my $is_desc) = $self->_split_order_chunk($bit); push @is_desc, $is_desc; push @unqualified_names, $usable_order_ci->{$bit}{-colname}; @@ -731,23 +725,22 @@ sub _subqueried_limit_attrs { my ($re_sep, $re_alias) = map { quotemeta $_ } ( $self->{name_sep}, $rs_attrs->{alias} ); - # insulate from the multiple _recurse_fields calls below - local $self->{select_bind}; - # correlate select and as, build selection index my (@sel, $in_sel_index); for my $i (0 .. $#{$rs_attrs->{select}}) { my $s = $rs_attrs->{select}[$i]; - my $sql_sel = $self->_recurse_fields ($s); my $sql_alias = (ref $s) eq 'HASH' ? $s->{-as} : undef; + # we throw away the @bind here deliberately + my ($sql_sel) = $self->_recurse_fields ($s); + push @sel, { arg => $s, sql => $sql_sel, unquoted_sql => do { local $self->{quote_char}; - $self->_recurse_fields ($s); + ($self->_recurse_fields ($s))[0]; # ignore binds again }, as => $sql_alias @@ -805,7 +798,7 @@ sub _subqueried_limit_attrs { for my $chunk ($self->_order_by_chunks ($rs_attrs->{order_by})) { # order with bind $chunk = $chunk->[0] if (ref $chunk) eq 'ARRAY'; - $chunk =~ s/\s+ (?: ASC|DESC ) \s* $//ix; + ($chunk) = $self->_split_order_chunk($chunk); next if $in_sel_index->{$chunk};