X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FMSSQL.pm;h=178a0079698d8b39457b41978b7d4c78742104bb;hb=e74c68ce64d8fd3c4838ebd8de8d5b580167fa08;hp=dec843fb7ce5c8335b8e4f7280455fc3a0f57957;hpb=50772633b75596faaec4fc236682d028f2dc31bd;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/MSSQL.pm b/lib/DBIx/Class/Storage/DBI/MSSQL.pm index dec843f..178a007 100644 --- a/lib/DBIx/Class/Storage/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Storage/DBI/MSSQL.pm @@ -179,8 +179,9 @@ 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. +# MSSQL is retarded wrt ordered subselects. One needs to add a TOP +# to *all* subqueries, but one also can't use TOP 100 PERCENT +# http://sqladvice.com/forums/permalink/18496/22931/ShowThread.aspx#22931 # sub _select_args_to_query { my $self = shift; @@ -190,7 +191,8 @@ sub _select_args_to_query { # see if this is an ordered subquery my $attrs = $_[3]; if ( scalar $self->sql_maker->_order_by_chunks ($attrs->{order_by}) ) { - $sql =~ s/^ \s* SELECT \s/SELECT TOP 100 PERCENT /xi; + my $max = 2 ** 32; + $sql =~ s/^ \s* SELECT \s/SELECT TOP $max /xi; } return wantarray @@ -244,7 +246,7 @@ sub sql_maker { unless ($self->_sql_maker) { unless ($self->{_sql_maker_opts}{limit_dialect}) { - my $version = $self->_get_mssql_version; + my $version = eval { $self->_get_mssql_version; } || 0; $self->{_sql_maker_opts} = { limit_dialect => ($version >= 9 ? 'RowNumberOver' : 'Top'),