]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] CompileError is raised when VARCHAR with
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 10 Sep 2012 21:02:31 +0000 (17:02 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 10 Sep 2012 21:02:31 +0000 (17:02 -0400)
no length is attempted to be emitted, same
way as MySQL. [ticket:2505]

CHANGES
lib/sqlalchemy/dialects/firebird/base.py
lib/sqlalchemy/sql/expression.py
test/dialect/test_firebird.py

diff --git a/CHANGES b/CHANGES
index c68278436f780f193cc7d670634336558b439a57..860057db2f9eb9b9af09c484c0f990c2c6ff00df 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -629,6 +629,10 @@ underneath "0.7.xx".
     as "NOT STARTING WITH", using FB's more efficient
     operator.  [ticket:2470]
 
+  - [bug] CompileError is raised when VARCHAR with
+    no length is attempted to be emitted, same
+    way as MySQL. [ticket:2505]
+
 - mysql
   - [bug] Dialect no longer emits expensive server
     collations query, as well as server casing,
index b4b856804e8fa4a775ecd9f224e7c32ca3b7b5a8..e8e60da2b175a6083719fc0a56f0b63c9d437b6b 100644 (file)
@@ -192,6 +192,10 @@ class FBTypeCompiler(compiler.GenericTypeCompiler):
         return self._extend_string(type_, basic)
 
     def visit_VARCHAR(self, type_):
+        if not type_.length:
+            raise exc.CompileError(
+                    "VARCHAR requires a length on dialect %s" %
+                    self.dialect.name)
         basic = super(FBTypeCompiler, self).visit_VARCHAR(type_)
         return self._extend_string(type_, basic)
 
index a817a2e5b0198c6cecacf1fee8be2daeea460e3b..6b80106018f3ba4d171cdd1b6126374cb6a4c62e 100644 (file)
@@ -26,6 +26,7 @@ to stay the same in future releases.
 
 """
 
+
 import itertools
 import re
 from operator import attrgetter
@@ -553,7 +554,6 @@ def between(ctest, cleft, cright):
     ctest = _literal_as_binds(ctest)
     return ctest.between(cleft, cright)
 
-
 def case(whens, value=None, else_=None):
     """Produce a ``CASE`` statement.
 
index 41533dbbdc5b302d40527237c6f2801e6497d6d1..aa57711e4ff2312a4411956ade100e0831bb35ac 100644 (file)
@@ -1,10 +1,15 @@
-from test.lib.testing import eq_, assert_raises
-from sqlalchemy import *
+from test.lib.testing import eq_, assert_raises_message
+from sqlalchemy import exc
 from sqlalchemy.databases import firebird
 from sqlalchemy.exc import ProgrammingError
 from sqlalchemy.sql import table, column
-from test.lib import *
-
+from sqlalchemy import types as sqltypes
+from test.lib import fixtures, AssertsExecutionResults, AssertsCompiledSQL
+from test.lib import testing, engines
+from sqlalchemy import String, VARCHAR, NVARCHAR, Unicode, Integer,\
+    func, insert, update, MetaData, select, Table, Column, text,\
+    Sequence, Float
+from sqlalchemy import schema
 
 class DomainReflectionTest(fixtures.TestBase, AssertsExecutionResults):
     "Test Firebird domains"
@@ -248,6 +253,33 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
                             'FROM sometable sometable_1',
                             dialect=dialect)
 
+    def test_varchar_raise(self):
+        for type_ in (
+            String,
+            VARCHAR,
+            String(),
+            VARCHAR(),
+            Unicode,
+            Unicode(),
+        ):
+            type_ = sqltypes.to_instance(type_)
+            assert_raises_message(
+                exc.CompileError,
+                "VARCHAR requires a length on dialect firebird",
+                type_.compile,
+            dialect=firebird.dialect())
+
+            t1 = Table('sometable', MetaData(),
+                Column('somecolumn', type_)
+            )
+            assert_raises_message(
+                exc.CompileError,
+                r"\(in table 'sometable', column 'somecolumn'\)\: "
+                r"(?:N)?VARCHAR requires a length on dialect firebird",
+                schema.CreateTable(t1).compile,
+                dialect=firebird.dialect()
+            )
+
     def test_function(self):
         self.assert_compile(func.foo(1, 2), 'foo(:foo_1, :foo_2)')
         self.assert_compile(func.current_time(), 'CURRENT_TIME')