From: Rafael Kitover Date: Wed, 2 Jun 2010 07:03:33 +0000 (+0000) Subject: use SET ROWCOUNT for Sybase ASE limits without an offset X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3f52831919a64ea6fb3269e41c547bc42e8db2fd;p=dbsrgits%2FDBIx-Class-Historic.git use SET ROWCOUNT for Sybase ASE limits without an offset --- diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index cd086c4..e6df357 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -392,6 +392,21 @@ sub _Top { return $sql; } +# This for Sybase ASE, to use SET ROWCOUNT when there is no offset, and +# GenericSubQ otherwise. +sub _RowCountOrGenericSubQ { + my $self = shift; + my ($sql, $rs_attrs, $rows, $offset) = @_; + + return $self->_GenericSubQ(@_) if $offset; + + return sprintf <<"EOF", $rows, $sql; +SET ROWCOUNT %d +%s +SET ROWCOUNT 0 +EOF +} + # This is the most evil limit "dialect" (more of a hack) for *really* # stupid databases. It works by ordering the set by some unique column, # and calculating amount of rows that have a less-er value (thus diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm index 80d7913..1022cc2 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm @@ -152,6 +152,16 @@ for my $method (@also_proxy_to_extra_storages) { }; } +sub _sql_maker_opts { + my ( $self, $opts ) = @_; + + if ( $opts ) { + $self->{_sql_maker_opts} = { %$opts }; + } + + return { limit_dialect => 'RowCountOrGenericSubQ', %{$self->{_sql_maker_opts}||{}} }; +} + sub disconnect { my $self = shift;