Mike Bayer committed 70a6865

- [bug] CompileError is raised when VARCHAR with
no length is attempted to be emitted, same
way as MySQL. [ticket:2505]

Comments (0)

Files changed (4)

     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,


         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" %
         basic = super(FBTypeCompiler, self).visit_VARCHAR(type_)
         return self._extend_string(type_, basic)


 import itertools
 import re
 from operator import attrgetter
     ctest = _literal_as_binds(ctest)
     return ctest.between(cleft, cright)
 def case(whens, value=None, else_=None):
     """Produce a ``CASE`` statement.


-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"
                             'FROM sometable sometable_1',
+    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(, 2), 'foo(:foo_1, :foo_2)')
         self.assert_compile(func.current_time(), 'CURRENT_TIME')