add OffsetFetch support
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / SQLMaker / LimitDialects.pm
index da65b7c..8ea77bd 100644 (file)
@@ -153,6 +153,30 @@ sub _rno_default_order {
   return undef;
 }
 
+=head2 OffsetFetchNext
+
+ SELECT * FROM ... OFFSET 10 ROWS FETCH NEXT 5 ROWS ONLY
+
+Suported by B<SQL Server 2012>, purported to be more efficient than L</RowNumberOver>.
+
+=cut
+sub _OffsetFetchNext {
+  my ($self, $sql, $rs_attrs, $rows, $offset ) = @_;
+
+  my $requested_order = (delete $rs_attrs->{order_by}) || \'1';
+
+  my $ord = $self->_order_by ($requested_order) || ' ORDER BY 1';
+
+  $sql .= $self->_parse_rs_attrs( $rs_attrs )
+       . $ord
+       . ' OFFSET ? ROWS FETCH NEXT ? ROWS ONLY';
+  push @{$self->{limit_bind}},
+    [ $self->__offset_bindtype => $offset || 0],
+    [ $self->__rows_bindtype => $rows];
+
+  return $sql;
+}
+
 =head2 SkipFirst
 
  SELECT SKIP $offset FIRST $limit * FROM ...