From: Arthur Axel 'fREW' Schmidt Date: Tue, 29 May 2012 02:19:20 +0000 (-0500) Subject: Add OffsetFetchNext limit dialect X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bf34f6f8af02cc4fea55e6f3cdb459124c0efab4;p=dbsrgits%2FData-Query.git Add OffsetFetchNext limit dialect 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 --- diff --git a/lib/Data/Query/Renderer/SQL/Slice/OffsetFetchNext.pm b/lib/Data/Query/Renderer/SQL/Slice/OffsetFetchNext.pm new file mode 100644 index 0000000..b800d92 --- /dev/null +++ b/lib/Data/Query/Renderer/SQL/Slice/OffsetFetchNext.pm @@ -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;