From 77c3bb26c29c491c1094427345ca51f309938572 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 19 Jun 2010 13:51:55 -0400 Subject: - Firebird dialect adds CHAR, VARCHAR types which accept a "charset" flag, to support Firebird "CHARACTER SET" clause. [ticket:1813] --- lib/sqlalchemy/dialects/firebird/base.py | 41 ++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/dialects/firebird/base.py b/lib/sqlalchemy/dialects/firebird/base.py index 0d3143b3b..d6e0f95bd 100644 --- a/lib/sqlalchemy/dialects/firebird/base.py +++ b/lib/sqlalchemy/dialects/firebird/base.py @@ -78,9 +78,9 @@ from sqlalchemy.engine import base, default, reflection from sqlalchemy.sql import compiler -from sqlalchemy.types import (BIGINT, BLOB, BOOLEAN, CHAR, DATE, +from sqlalchemy.types import (BIGINT, BLOB, BOOLEAN, DATE, FLOAT, INTEGER, NUMERIC, SMALLINT, - TEXT, TIME, TIMESTAMP, VARCHAR) + TEXT, TIME, TIMESTAMP) RESERVED_WORDS = set([ @@ -123,6 +123,27 @@ RESERVED_WORDS = set([ ]) +class _StringType(sqltypes.String): + """Base for Firebird string types.""" + + def __init__(self, charset = None, **kw): + self.charset = charset + super(_StringType, self).__init__(**kw) + +class VARCHAR(_StringType, sqltypes.VARCHAR): + """Firebird VARCHAR type""" + __visit_name__ = 'VARCHAR' + + def __init__(self, length = None, **kwargs): + super(VARCHAR, self).__init__(length=length, **kwargs) + +class CHAR(_StringType, sqltypes.CHAR): + """Firebird CHAR type""" + __visit_name__ = 'CHAR' + + def __init__(self, length = None, **kwargs): + super(CHAR, self).__init__(length=length, **kwargs) + colspecs = { } @@ -159,6 +180,22 @@ class FBTypeCompiler(compiler.GenericTypeCompiler): def visit_BLOB(self, type_): return "BLOB SUB_TYPE 0" + def _extend_string(self, type_, basic): + charset = getattr(type_, 'charset', None) + if charset is None: + return basic + else: + return '%s CHARACTER SET %s' % (basic, charset) + + def visit_CHAR(self, type_): + basic = super(FBTypeCompiler, self).visit_CHAR(type_) + return self._extend_string(type_, basic) + + def visit_VARCHAR(self, type_): + basic = super(FBTypeCompiler, self).visit_VARCHAR(type_) + return self._extend_string(type_, basic) + + class FBCompiler(sql.compiler.SQLCompiler): """Firebird specific idiosincrasies""" -- cgit v1.2.1