- server_version_info becomes a static attribute.
- create_engine() now establishes an initial connection immediately upon
creation, which is passed to the dialect to determine connection properties.
-
+ - cached TypeEngine classes are cached per-dialect class instead of per-dialect.
+
- mysql
- all the _detect_XXX() functions now run once underneath dialect.initialize()
raise NotImplementedError()
- def type_descriptor(self, typeobj):
- """Transform a generic type to a database-specific type.
+ @classmethod
+ def type_descriptor(cls, typeobj):
+ """Transform a generic type to a dialect-specific type.
- Transforms the given :class:`~sqlalchemy.types.TypeEngine` instance
- from generic to database-specific.
-
- Subclasses will usually use the
+ Dialect classes will usually use the
:func:`~sqlalchemy.types.adapt_type` method in the types module to
make this job easy.
+
+ The returned result is cached *per dialect class* so can
+ contain no dialect-instance state.
+
"""
raise NotImplementedError()
self.label_length = label_length
self.description_encoding = getattr(self, 'description_encoding', encoding)
- def type_descriptor(self, typeobj):
+ @classmethod
+ def type_descriptor(cls, typeobj):
"""Provide a database-specific ``TypeEngine`` object, given
the generic object which comes from the types module.
and passes on to ``types.adapt_type()``.
"""
- return sqltypes.adapt_type(typeobj, self.colspecs)
+ return sqltypes.adapt_type(typeobj, cls.colspecs)
def validate_identifier(self, ident):
if len(ident) > self.max_identifier_length:
def dialect_impl(self, dialect, **kwargs):
try:
- return self._impl_dict[dialect]
+ return self._impl_dict[dialect.__class__]
except AttributeError:
self._impl_dict = {}
- return self._impl_dict.setdefault(dialect, dialect.type_descriptor(self))
+ return self._impl_dict.setdefault(dialect.__class__, dialect.__class__.type_descriptor(self))
except KeyError:
- return self._impl_dict.setdefault(dialect, dialect.type_descriptor(self))
+ return self._impl_dict.setdefault(dialect.__class__, dialect.__class__.type_descriptor(self))
def __getstate__(self):
d = self.__dict__.copy()
def dialect_impl(self, dialect):
try:
- return self._impl_dict[dialect]
+ return self._impl_dict[dialect.__class__]
except AttributeError:
self._impl_dict = {}
except KeyError:
# adapt the TypeDecorator first, in
# the case that the dialect maps the TD
# to one of its native types (i.e. PGInterval)
- adapted = dialect.type_descriptor(self)
+ adapted = dialect.__class__.type_descriptor(self)
if adapted is not self:
self._impl_dict[dialect] = adapted
return adapted
if isinstance(self.impl, TypeDecorator):
return self.impl.dialect_impl(dialect)
else:
- return dialect.type_descriptor(self.impl)
+ return dialect.__class__.type_descriptor(self.impl)
def __getattr__(self, key):
"""Proxy all other undefined accessors to the underlying implementation."""
from testlib import testing
from testlib.sa import MetaData, Table, Column, Integer, String, ForeignKey, PickleType
from orm import _base
+import sqlalchemy as sa
+from sqlalchemy.sql import column
class A(_base.ComparableEntity):
go()
finally:
metadata.drop_all()
+
+ def test_type_compile(self):
+ from sqlalchemy.dialects.sqlite.base import dialect as SQLiteDialect
+ cast = sa.cast(column('x'), sa.Integer)
+ @profile_memory
+ def go():
+ dialect = SQLiteDialect()
+ cast.compile(dialect=dialect)
+ go()
if __name__ == '__main__':
testenv.main()
class AdaptTest(TestBase):
- def testadapt(self):
- e1 = url.URL('postgres').get_dialect()()
- e2 = url.URL('mysql').get_dialect()()
- e3 = url.URL('sqlite').get_dialect()()
- e4 = url.URL('firebird').get_dialect()()
-
- type = String(40)
-
- t1 = type.dialect_impl(e1)
- t2 = type.dialect_impl(e2)
- t3 = type.dialect_impl(e3)
- t4 = type.dialect_impl(e4)
-
- impls = [t1, t2, t3, t4]
- for i,ta in enumerate(impls):
- for j,tb in enumerate(impls):
- if i == j:
- assert ta == tb # call me paranoid... :)
- else:
- assert ta != tb
-
def testmsnvarchar(self):
dialect = mssql.dialect()
# run the test twice to ensure the caching step works too
(postgres_dialect, Unicode(), String),
(postgres_dialect, UnicodeText(), Text),
(postgres_dialect, NCHAR(), String),
- (firebird_dialect, String(), firebird.FBString),
- (firebird_dialect, VARCHAR(), firebird.FBString),
- (firebird_dialect, String(50), firebird.FBString),
- (firebird_dialect, Unicode(), firebird.FBString),
- (firebird_dialect, UnicodeText(), firebird.FBText),
- (firebird_dialect, NCHAR(), firebird.FBString),
+# (firebird_dialect, String(), firebird.FBString),
+# (firebird_dialect, VARCHAR(), firebird.FBString),
+# (firebird_dialect, String(50), firebird.FBString),
+# (firebird_dialect, Unicode(), firebird.FBString),
+# (firebird_dialect, UnicodeText(), firebird.FBText),
+# (firebird_dialect, NCHAR(), firebird.FBString),
]:
assert isinstance(start.dialect_impl(dialect), test), "wanted %r got %r" % (test, start.dialect_impl(dialect))