X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FMSSQL.pm;h=28b87f2ed6755699c81a74f8186d8a1236a14af7;hb=6553ac3837081c481ecdf269c7aff407c348a807;hp=94597ab7bc4be4657754f7cf145d75a583b60e6f;hpb=9d2a1bb56d0b2ce3901280b031db971046958abc;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/MSSQL.pm b/lib/DBIx/Class/Storage/DBI/MSSQL.pm index 94597ab..28b87f2 100644 --- a/lib/DBIx/Class/Storage/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Storage/DBI/MSSQL.pm @@ -178,6 +178,41 @@ sub _execute { sub last_insert_id { shift->_identity } +# +# MSSQL is retarded wrt ordered subselects. One needs to add a TOP 100% +# to *all* subqueries, do it here. +# +sub _select_args_to_query { + my $self = shift; + + # _select_args does some shady action at a distance + # see DBI.pm for more info + my $sql_maker = $self->sql_maker; + my ($op, $bind, $ident, $bind_attrs, $select, $cond, $order, $rows, $offset); + { + local $sql_maker->{_dbic_rs_attrs}; + ($op, $bind, $ident, $bind_attrs, $select, $cond, $order, $rows, $offset) = $self->_select_args(@_); + } + + if ( + ($rows || $offset) + || + not scalar $sql_maker->_order_by_chunks ($order->{order_by}) + ) { + # either limited RS or no ordering, just short circuit + return $self->next::method (@_); + } + + my ($sql, $prep_bind, @rest) = $self->next::method (@_); + $sql =~ s/^ \s* SELECT \s/SELECT TOP 100 PERCENT /xi; + + return wantarray + ? ($sql, $prep_bind, @rest) + : \[ "($sql)", @$prep_bind ] + ; +} + + # savepoint syntax is the same as in Sybase ASE sub _svp_begin {