From: Rick Morrison Date: Tue, 6 Feb 2007 20:04:09 +0000 (+0000) Subject: ticket 298 plus transaction fixes for pymssql X-Git-Tag: rel_0_3_5~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fac73b6998c5ebf4e8aa76194fff19273ea4c9d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git ticket 298 plus transaction fixes for pymssql --- diff --git a/CHANGES b/CHANGES index 9aab59481e..2aa1ff2281 100644 --- a/CHANGES +++ b/CHANGES @@ -44,6 +44,9 @@ - ext: - added distinct() method to SelectResults. generally should only make a difference when using count(). +- mssql: + - better support for NVARCHAR types added [ticket:298] + - fix for commit logic on pymssql 0.3.4 - general: diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index fbb89de1ab..04b949d6ad 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -146,13 +146,28 @@ class MSText(sqltypes.TEXT): class MSString(sqltypes.String): def get_col_spec(self): return "VARCHAR(%(length)s)" % {'length' : self.length} + + class MSNVarchar(MSString): """NVARCHAR string, does unicode conversion if dialect.convert_encoding is true""" + impl = sqltypes.Unicode def get_col_spec(self): return "NVARCHAR(%(length)s)" % {'length' : self.length} + if dbmodule and dbmodule.__name__ == 'adodbapi': + def convert_bind_param(self, value, dialect): + return value + def convert_result_value(self, value, dialect): + return value + class MSUnicode(sqltypes.Unicode): """Unicode subclass, does unicode conversion in all cases, uses NVARCHAR impl""" impl = MSNVarchar + if dbmodule and dbmodule.__name__ == 'adodbapi': + def convert_bind_param(self, value, dialect): + return value + def convert_result_value(self, value, dialect): + return value + class MSChar(sqltypes.CHAR): def get_col_spec(self): return "CHAR(%(length)s)" % {'length' : self.length} @@ -264,10 +279,10 @@ class MSSQLExecutionContext(default.DefaultExecutionContext): class MSSQLDialect(ansisql.ANSIDialect): - def __init__(self, module=None, auto_identity_insert=False, **params): + def __init__(self, module=None, auto_identity_insert=False, encoding=None, **params): self.module = module or dbmodule self.auto_identity_insert = auto_identity_insert - ansisql.ANSIDialect.__init__(self, **params) + ansisql.ANSIDialect.__init__(self, encoding=encoding, **params) self.set_default_schema_name("dbo") def create_connect_args(self, url): @@ -468,8 +483,7 @@ class MSSQLDialect(ansisql.ANSIDialect): class PyMSSQLDialect(MSSQLDialect): def do_begin(self, connection): """implementations might want to put logic here for turning autocommit on/off, etc.""" - if do_commit: - pass + pass def do_rollback(self, connection): """implementations might want to put logic here for turning autocommit on/off, etc.""" @@ -497,7 +511,6 @@ class PyMSSQLDialect(MSSQLDialect): r.query("begin tran") r.fetch_array() - class MSSQLCompiler(ansisql.ANSICompiler): def __init__(self, dialect, statement, parameters, **kwargs): super(MSSQLCompiler, self).__init__(dialect, statement, parameters, **kwargs) @@ -544,7 +557,6 @@ class MSSQLCompiler(ansisql.ANSICompiler): self.strings[column] = \ self.strings[self.tablealiases[column.table].corresponding_column(column)] - class MSSQLSchemaGenerator(ansisql.ANSISchemaGenerator): def get_column_specification(self, column, **kwargs): colspec = self.preparer.format_column(column) + " " + column.type.engine_impl(self.engine).get_col_spec() diff --git a/lib/sqlalchemy/exceptions.py b/lib/sqlalchemy/exceptions.py index 930aa8ea36..1caee06494 100644 --- a/lib/sqlalchemy/exceptions.py +++ b/lib/sqlalchemy/exceptions.py @@ -60,3 +60,8 @@ class DBAPIError(SQLAlchemyError): def __init__(self, message, orig): SQLAlchemyError.__init__(self, "(%s) (%s) %s"% (message, orig.__class__.__name__, str(orig))) self.orig = orig + +class MissingTypeError(SQLAlchemyError): + """no database type is available for the sa type""" + pass +