From: Arthur Axel "fREW" Schmidt Date: Tue, 8 Dec 2009 01:10:06 +0000 (+0000) Subject: add version check for mssql 2005 and greater X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e76e7b5c09dcc04d0d9c5cc0cb81fa50ebf304ae;p=dbsrgits%2FDBIx-Class-Historic.git add version check for mssql 2005 and greater --- diff --git a/lib/DBIx/Class/Storage/DBI/MSSQL.pm b/lib/DBIx/Class/Storage/DBI/MSSQL.pm index cddfc5e..e39871d 100644 --- a/lib/DBIx/Class/Storage/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Storage/DBI/MSSQL.pm @@ -227,6 +227,18 @@ sub build_datetime_parser { sub sqlt_type { 'SQLServer' } +sub _get_mssql_version { + my $self = shift; + + my $data = $self->_get_dbh->selectrow_hashref('xp_msver ProductVersion'); + + if ($data->{Character_Value} =~ /^(\d+)\./) { + return $1; + } else { + die q{wtf your server doesn't have a version!}; + } +} + sub _sql_maker_opts { my ( $self, $opts ) = @_; @@ -234,7 +246,12 @@ sub _sql_maker_opts { $self->{_sql_maker_opts} = { %$opts }; } - return { limit_dialect => 'RowNumberOver', %{$self->{_sql_maker_opts}||{}} }; + my $version = $self->_get_mssql_version; + + return { + limit_dialect => ($version >= 9 ? 'RowNumberOver' : 'Top'), + %{$self->{_sql_maker_opts}||{}} + }; } 1;