From f2622c0c53e761759da89c784c5105d2a38dcab9 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 10 Sep 2012 17:02:31 -0400 Subject: [PATCH] - [bug] CompileError is raised when VARCHAR with no length is attempted to be emitted, same way as MySQL. [ticket:2505] --- CHANGES | 4 +++ lib/sqlalchemy/dialects/firebird/base.py | 4 +++ lib/sqlalchemy/sql/expression.py | 2 +- test/dialect/test_firebird.py | 40 +++++++++++++++++++++--- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index c68278436f..860057db2f 100644 --- 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, diff --git a/lib/sqlalchemy/dialects/firebird/base.py b/lib/sqlalchemy/dialects/firebird/base.py index b4b856804e..e8e60da2b1 100644 --- a/lib/sqlalchemy/dialects/firebird/base.py +++ b/lib/sqlalchemy/dialects/firebird/base.py @@ -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) diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index a817a2e5b0..6b80106018 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -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. diff --git a/test/dialect/test_firebird.py b/test/dialect/test_firebird.py index 41533dbbdc..aa57711e4f 100644 --- a/test/dialect/test_firebird.py +++ b/test/dialect/test_firebird.py @@ -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') -- 2.47.3