Do not add TOP prefixes to queries already containing it
Peter Rabbitson [Mon, 3 May 2010 16:32:35 +0000 (16:32 +0000)]
lib/DBIx/Class/Storage/DBI/MSSQL.pm

index ef09d49..38c615b 100644 (file)
@@ -158,7 +158,11 @@ sub _select_args_to_query {
 
   # see if this is an ordered subquery
   my $attrs = $_[3];
-  if ( scalar $self->_parse_order_by ($attrs->{order_by}) ) {
+  if (
+    $sql !~ /^ \s* SELECT \s+ TOP \s+ \d+ \s+ /xi
+      &&
+    scalar $self->_parse_order_by ($attrs->{order_by}) 
+  ) {
     $self->throw_exception(
       'An ordered subselect encountered - this is not safe! Please see "Ordered Subselects" in DBIx::Class::Storage::DBI::MSSQL
     ') unless $attrs->{unsafe_subselect_ok};