From 61016f17d1a5aff1224d6609d74952be1d6e09ad Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 20 Jan 2016 16:32:27 -0500 Subject: [PATCH] - The unsupported Sybase dialect now raises ``NotImplementedError`` when attempting to compile a query that includes "offset"; Sybase has no straightforward "offset" feature. fixes #2278 --- doc/build/changelog/changelog_11.rst | 8 ++++++++ lib/sqlalchemy/dialects/sybase/base.py | 6 +----- test/dialect/test_sybase.py | 14 +++++++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 80c8ece33b..23965818e0 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -21,6 +21,14 @@ .. changelog:: :version: 1.1.0b1 + .. change:: + :tags: bug, sybase + :tickets: 2278 + + The unsupported Sybase dialect now raises ``NotImplementedError`` + when attempting to compile a query that includes "offset"; Sybase + has no straightforward "offset" feature. + .. change:: :tags: feature, orm :tickets: 3631 diff --git a/lib/sqlalchemy/dialects/sybase/base.py b/lib/sqlalchemy/dialects/sybase/base.py index b3f8e307af..1875218315 100644 --- a/lib/sqlalchemy/dialects/sybase/base.py +++ b/lib/sqlalchemy/dialects/sybase/base.py @@ -336,11 +336,7 @@ class SybaseSQLCompiler(compiler.SQLCompiler): s += "TOP %s " % (limit,) offset = select._offset if offset: - if not limit: - # FIXME: sybase doesn't allow an offset without a limit - # so use a huge value for TOP here - s += "TOP 1000000 " - s += "START AT %s " % (offset + 1,) + raise NotImplementedError("Sybase ASE does not support OFFSET") return s def get_from_hint_text(self, table, text): diff --git a/test/dialect/test_sybase.py b/test/dialect/test_sybase.py index 1318a282bd..d8f7d3aaec 100644 --- a/test/dialect/test_sybase.py +++ b/test/dialect/test_sybase.py @@ -1,7 +1,8 @@ -from sqlalchemy import * +from sqlalchemy import extract, select from sqlalchemy import sql from sqlalchemy.databases import sybase -from sqlalchemy.testing import * +from sqlalchemy.testing import assert_raises_message, \ + fixtures, AssertsCompiledSQL class CompileTest(fixtures.TestBase, AssertsCompiledSQL): @@ -17,12 +18,19 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): 'milliseconds': 'millisecond', 'millisecond': 'millisecond', 'year': 'year', - } + } for field, subst in list(mapping.items()): self.assert_compile( select([extract(field, t.c.col1)]), 'SELECT DATEPART("%s", t.col1) AS anon_1 FROM t' % subst) + def test_offset_not_supported(self): + stmt = select([1]).offset(10) + assert_raises_message( + NotImplementedError, + "Sybase ASE does not support OFFSET", + stmt.compile, dialect=self.__dialect__ + ) -- 2.47.2