]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add Sequence to StrSQLCompiler
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Nov 2018 02:10:51 +0000 (21:10 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Nov 2018 02:10:51 +0000 (21:10 -0500)
Added :class:`.Sequence` to the "string SQL" system that will render a
meaningful string expression (``"<next sequence value: my_sequence>"``)
when stringifying without a dialect a statement that includes a "sequence
nextvalue" expression, rather than raising a compilation error.

Fixes: #4144
Change-Id: Ia910f0e22008a7cde7597365954ede324101cf4d

doc/build/changelog/unreleased_13/4144.rst [new file with mode: 0644]
lib/sqlalchemy/sql/compiler.py
test/sql/test_compiler.py

diff --git a/doc/build/changelog/unreleased_13/4144.rst b/doc/build/changelog/unreleased_13/4144.rst
new file mode 100644 (file)
index 0000000..08fcb61
--- /dev/null
@@ -0,0 +1,10 @@
+.. change::
+   :tags: feature, sql
+   :tickets: 4144
+
+   Added :class:`.Sequence` to the "string SQL" system that will render a
+   meaningful string expression (``"<next sequence value: my_sequence>"``)
+   when stringifying without a dialect a statement that includes a "sequence
+   nextvalue" expression, rather than raising a compilation error.
+
+
index 27ee4afc68977d1449875a4e8e5e0a7e74308b44..87a9f859bb53e5b421d1198b9e592d6efe936633 100644 (file)
@@ -2407,6 +2407,9 @@ class StrSQLCompiler(SQLCompiler):
     def visit_json_path_getitem_op_binary(self, binary, operator, **kw):
         return self.visit_getitem_binary(binary, operator, **kw)
 
+    def visit_sequence(self, seq, **kw):
+        return "<next sequence value: %s>" % self.preparer.format_sequence(seq)
+
     def returning_clause(self, stmt, returning_cols):
         columns = [
             self._label_select_column(None, c, True, False, {})
index 993008c072351b9d72e9ba355fddcfe20729278d..22b46cc46bda1abf02316a7f45aa458f5e972ac3 100644 (file)
@@ -2898,6 +2898,18 @@ class StringifySpecialTest(fixtures.TestBase):
             "SELECT anon_1.myid FROM anon_1"
         )
 
+    def test_next_sequence_value(self):
+        # using descriptive text that is intentionally not compatible
+        # with any particular backend, since all backends have different
+        # syntax
+
+        seq = Sequence("my_sequence")
+
+        eq_ignore_whitespace(
+            str(seq.next_value()),
+            "<next sequence value: my_sequence>"
+        )
+
     def test_returning(self):
         stmt = table1.insert().returning(table1.c.myid)