diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-13 20:23:24 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-13 20:23:24 -0500 |
| commit | bfaa97dbce7e4f4c8d7eddc49c164945701bbe00 (patch) | |
| tree | 3c4bc9f33703a089b6e28c3727bb6b038326b6cf /lib/sqlalchemy | |
| parent | 68fb34ba57aa5820dd4e175fe942dabf4ee62999 (diff) | |
| download | sqlalchemy-bfaa97dbce7e4f4c8d7eddc49c164945701bbe00.tar.gz | |
some tests, should be OK
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 8 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/types.py | 47 |
3 files changed, 31 insertions, 26 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 7dd7400ea..4c0a00890 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -175,8 +175,9 @@ class REAL(sqltypes.Float): __visit_name__ = 'REAL' - def __init__(self): - super(REAL, self).__init__(precision=24) + def __init__(self, **kw): + kw.setdefault('precision', 24) + super(REAL, self).__init__(**kw) class TINYINT(sqltypes.Integer): __visit_name__ = 'TINYINT' @@ -258,7 +259,8 @@ class SMALLDATETIME(_DateTimeBase, sqltypes.DateTime): class DATETIME2(_DateTimeBase, sqltypes.DateTime): __visit_name__ = 'DATETIME2' - def __init__(self, precision=None, **kwargs): + def __init__(self, precision=None, **kw): + super(DATETIME2, self).__init__(**kw) self.precision = precision diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index deeebf0f9..fd99a16b5 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -771,7 +771,7 @@ class CHAR(_StringType, sqltypes.CHAR): __visit_name__ = 'CHAR' - def __init__(self, length, **kwargs): + def __init__(self, length=None, **kwargs): """Construct a CHAR. :param length: Maximum data length, in characters. diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 85ac3192f..447938461 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -131,7 +131,7 @@ class TypeEngine(AbstractType): else: return self.__class__ - def dialect_impl(self, dialect, **kwargs): + def dialect_impl(self, dialect): """Return a dialect-specific implementation for this type.""" try: @@ -149,22 +149,6 @@ class TypeEngine(AbstractType): d['bind'] = bp = d['impl'].bind_processor(dialect) return bp - def _dialect_info(self, dialect): - """Return a dialect-specific registry containing bind/result processors.""" - - if self in dialect._type_memos: - return dialect._type_memos[self] - else: - impl = self._gen_dialect_impl(dialect) - # the impl we put in here - # must not have any references to self. - if impl is self: - impl = self.adapt(type(self)) - dialect._type_memos[self] = d = { - 'impl':impl, - } - return d - def _cached_result_processor(self, dialect, coltype): """Return a dialect-specific result processor for this type.""" @@ -172,11 +156,28 @@ class TypeEngine(AbstractType): return dialect._type_memos[self][coltype] except KeyError: d = self._dialect_info(dialect) - # another key assumption. DBAPI type codes are - # constants. + # key assumption: DBAPI type codes are + # constants. Else this dictionary would + # grow unbounded. d[coltype] = rp = d['impl'].result_processor(dialect, coltype) return rp + def _dialect_info(self, dialect): + """Return a dialect-specific registry which + caches a dialect-specific implementation, bind processing + function, and one or more result processing functions.""" + + if self in dialect._type_memos: + return dialect._type_memos[self] + else: + impl = self._gen_dialect_impl(dialect) + if impl is self: + impl = self.adapt(type(self)) + # this can't be self, else we create a cycle + assert impl is not self + dialect._type_memos[self] = d = {'impl':impl} + return d + def _gen_dialect_impl(self, dialect): return dialect.type_descriptor(self) @@ -792,7 +793,7 @@ class String(Concatenable, TypeEngine): length=self.length, convert_unicode=self.convert_unicode, unicode_error=self.unicode_error, - _warn_on_bytestring=True, + _warn_on_bytestring=self._warn_on_bytestring, **kw ) @@ -1171,7 +1172,9 @@ class Float(Numeric): """ __visit_name__ = 'float' - + + scale = None + def __init__(self, precision=None, asdecimal=False, **kwargs): """ Construct a Float. @@ -1787,7 +1790,7 @@ class Interval(_DateAffinity, TypeDecorator): self.day_precision = day_precision def adapt(self, cls, **kw): - if self.native: + if self.native and hasattr(cls, '_adapt_from_generic_interval'): return cls._adapt_from_generic_interval(self, **kw) else: return cls(**kw) |
