1 package # Hide from PAUSE
2 DBIx::Class::SQLAHacks::MSSQL;
4 use base qw( DBIx::Class::SQLAHacks );
5 use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/;
8 # MSSQL is retarded wrt TOP (crappy limit) and ordering.
9 # One needs to add a TOP to *all* ordered subqueries, if
10 # TOP has been used in the statement at least once.
16 my ($sql, @bind) = $self->SUPER::select (@_);
18 # ordering was requested and there are at least 2 SELECT/FROM pairs
19 # (thus subquery), and there is no TOP specified
21 $sql =~ /\bSELECT\b .+? \bFROM\b .+? \bSELECT\b .+? \bFROM\b/isx
23 $sql !~ /^ \s* SELECT \s+ TOP \s+ \d+ /xi
25 scalar $self->_order_by_chunks ($_[3]->{order_by})
27 $sql =~ s/^ \s* SELECT \s/SELECT TOP 100 PERCENT /xi;
30 return wantarray ? ($sql, @bind) : $sql;