diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-01-14 20:21:36 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-01-14 20:21:36 +0000 |
commit | 437f1ce670e84964dc701488ac09af565ba807f7 (patch) | |
tree | e6a92d2850af4695d3651e29cd8b72cc10872c26 /lib/sqlalchemy | |
parent | 5b4871f4364c7b93de010097aa8f4008f69bddd4 (diff) | |
download | sqlalchemy-437f1ce670e84964dc701488ac09af565ba807f7.tar.gz |
- postgres cursor option is now server_side_cursors=False; some users get bad results using them
so theyre off by default
- type system slightly modified to support TypeDecorators that can be overridden by the dialect
- added an NVarchar type to mssql (produces NVARCHAR), also MSUnicode which provides Unicode-translation
for the NVarchar regardless of dialect convert_unicode setting.
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/databases/mssql.py | 12 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/postgres.py | 11 | ||||
-rw-r--r-- | lib/sqlalchemy/types.py | 9 |
3 files changed, 20 insertions, 12 deletions
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 2028ab48f..6d351d0fb 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -146,9 +146,13 @@ class MSText(sqltypes.TEXT): class MSString(sqltypes.String): def get_col_spec(self): return "VARCHAR(%(length)s)" % {'length' : self.length} -class MSUnicode(sqltypes.Unicode): +class MSNVarchar(MSString): + """NVARCHAR string, does unicode conversion if dialect.convert_encoding is true""" def get_col_spec(self): return "NVARCHAR(%(length)s)" % {'length' : self.length} +class MSUnicode(sqltypes.Unicode): + """Unicode subclass, does unicode conversion in all cases, uses NVARCHAR impl""" + impl = MSNVarchar class MSChar(sqltypes.CHAR): def get_col_spec(self): return "CHAR(%(length)s)" % {'length' : self.length} @@ -259,8 +263,6 @@ class MSSQLExecutionContext(default.DefaultExecutionContext): self.HASIDENT = False - - class MSSQLDialect(ansisql.ANSIDialect): def __init__(self, module=None, auto_identity_insert=False, **params): self.module = module or dbmodule @@ -546,7 +548,7 @@ class MSSQLCompiler(ansisql.ANSICompiler): 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() - + # install a IDENTITY Sequence if we have an implicit IDENTITY column if column.primary_key and column.autoincrement and isinstance(column.type, sqltypes.Integer) and not column.foreign_key: if column.default is None or (isinstance(column.default, schema.Sequence) and column.default.optional): @@ -583,7 +585,7 @@ class MSSQLIdentifierPreparer(ansisql.ANSIIdentifierPreparer): #TODO: determin MSSQL's case folding rules return value -if dbmodule.__name__ == 'adodbapi': +if dbmodule and dbmodule.__name__ == 'adodbapi': dialect = MSSQLDialect else: dialect = PyMSSQLDialect diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 79db8716c..94519a5ac 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -207,9 +207,9 @@ class PGExecutionContext(default.DefaultExecutionContext): self._last_inserted_ids = [v for v in row] class PGDialect(ansisql.ANSIDialect): - def __init__(self, module=None, use_oids=False, use_information_schema=False, client_side_cursors=False, **params): + def __init__(self, module=None, use_oids=False, use_information_schema=False, server_side_cursors=False, **params): self.use_oids = use_oids - self.client_side_cursors = client_side_cursors + self.server_side_cursors = server_side_cursors if module is None: #if psycopg is None: # raise exceptions.ArgumentError("Couldnt locate psycopg1 or psycopg2: specify postgres module argument") @@ -241,13 +241,12 @@ class PGDialect(ansisql.ANSIDialect): return ([], opts) def create_cursor(self, connection): - if self.client_side_cursors: - return connection.cursor() - else: + if self.server_side_cursors: # use server-side cursors: # http://lists.initd.org/pipermail/psycopg/2007-January/005251.html return connection.cursor('x') - + else: + return connection.cursor() def create_execution_context(self): return PGExecutionContext(self) diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 336231242..726044270 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -82,6 +82,12 @@ class TypeDecorator(AbstractType): try: return self.impl_dict[dialect] except: + # see if the dialect has an adaptation of the TypeDecorator itself + adapted_decorator = dialect.type_descriptor(self) + if adapted_decorator is not self: + result = adapted_decorator.dialect_impl(dialect) + self.impl_dict[dialect] = result + return result typedesc = dialect.type_descriptor(self.impl) tt = self.copy() if not isinstance(tt, self.__class__): @@ -138,7 +144,8 @@ def adapt_type(typeobj, colspecs): except KeyError: pass else: - # couldnt adapt...raise exception ? + # couldnt adapt - so just return the type itself + # (it may be a user-defined type) return typeobj # if we adapted the given generic type to a database-specific type, # but it turns out the originally given "generic" type |