Add OffsetFetchNext limit dialect sql-server-2012
Arthur Axel 'fREW' Schmidt [Tue, 29 May 2012 02:19:20 +0000 (21:19 -0500)]
This dialect supports SQL Server 2012.  It renders like this:

 SELECT me.id, me.source, me.owner, me.price, owner.id, owner.name
   FROM books me
   JOIN owners owner ON owner.id = me.owner
   WHERE ( source = ? )
   ORDER BY me.id
   OFFSET ? ROWS
   FETCH NEXT ? ROWS ONLY

http://msdn.microsoft.com/en-us/library/gg699618%28v=SQL.110%29.aspx

Note that it REQUIRES an ORDER BY clause

lib/Data/Query/Renderer/SQL/Slice/OffsetFetchNext.pm [new file with mode: 0644]

diff --git a/lib/Data/Query/Renderer/SQL/Slice/OffsetFetchNext.pm b/lib/Data/Query/Renderer/SQL/Slice/OffsetFetchNext.pm
new file mode 100644 (file)
index 0000000..b800d92
--- /dev/null
@@ -0,0 +1,21 @@
+package Data::Query::Renderer::SQL::Slice::OffsetFetchNext;
+
+use Moo::Role;
+
+sub _render_slice {
+  my ($self, $dq) = @_;
+  [ ($dq->{from} ? $self->_render($dq->{from}) : ()),
+    (
+       $dq->{offset} ? (
+          $self->_format_keyword('OFFSET'),
+          $self->_render($dq->{offset}),
+          $self->_format_keyword('ROWS'),
+       ) : ()
+    ),
+    $self->_format_keyword('FETCH NEXT'),
+    $self->_render($dq->{limit}),
+    $self->_format_keyword('ROWS ONLY'),
+  ];
+}
+
+1;