summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-08-12 19:50:07 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-08-12 19:50:07 +0000
commit26efe4f6434ebd56851ed4e156f0d0d234b28729 (patch)
tree6a04114490d640fda36ee73230290587c3290a59 /lib/sqlalchemy
parentca84cbc8de85f97ed971ee4e3dc95138f297d76a (diff)
downloadsqlalchemy-26efe4f6434ebd56851ed4e156f0d0d234b28729.tar.gz
fixes to types so that database-specific types more easily used;
fixes to mysql text types to work with this methodology [ticket:269]
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/databases/mysql.py16
-rw-r--r--lib/sqlalchemy/types.py9
2 files changed, 12 insertions, 13 deletions
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py
index 56f2125ac..14e26438f 100644
--- a/lib/sqlalchemy/databases/mysql.py
+++ b/lib/sqlalchemy/databases/mysql.py
@@ -115,28 +115,19 @@ class MSText(sqltypes.TEXT):
super(MSText, self).__init__()
def get_col_spec(self):
return "TEXT"
-class MSTinyText(sqltypes.TEXT):
- def __init__(self, **kw):
- self.binary = 'binary' in kw
- super(MSTinyText, self).__init__()
+class MSTinyText(MSText):
def get_col_spec(self):
if self.binary:
return "TEXT BINARY"
else:
return "TEXT"
-class MSMediumText(sqltypes.TEXT):
- def __init__(self, **kw):
- self.binary = 'binary' in kw
- super(MSMediumText, self).__init__()
+class MSMediumText(MSText):
def get_col_spec(self):
if self.binary:
return "MEDIUMTEXT BINARY"
else:
return "MEDIUMTEXT"
-class MSLongText(sqltypes.TEXT):
- def __init__(self, **kw):
- self.binary = 'binary' in kw
- super(MSLongText, self).__init__()
+class MSLongText(MSText):
def get_col_spec(self):
if self.binary:
return "LONGTEXT BINARY"
@@ -431,6 +422,7 @@ class MySQLCompiler(ansisql.ANSICompiler):
class MySQLSchemaGenerator(ansisql.ANSISchemaGenerator):
def get_column_specification(self, column, override_pk=False, first_pk=False):
+ t = column.type.engine_impl(self.engine)
colspec = self.preparer.format_column(column) + " " + column.type.engine_impl(self.engine).get_col_spec()
default = self.get_column_default_string(column)
if default is not None:
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index 5fc75678d..709c77e5c 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -37,7 +37,7 @@ class TypeEngine(AbstractType):
def dialect_impl(self, dialect):
try:
return self.impl_dict[dialect]
- except:
+ except KeyError:
return self.impl_dict.setdefault(dialect, dialect.type_descriptor(self))
def _get_impl(self):
if hasattr(self, '_impl'):
@@ -96,6 +96,7 @@ def to_instance(typeobj):
def adapt_type(typeobj, colspecs):
if isinstance(typeobj, type):
typeobj = typeobj()
+
for t in typeobj.__class__.__mro__[0:-1]:
try:
impltype = colspecs[t]
@@ -105,6 +106,12 @@ def adapt_type(typeobj, colspecs):
else:
# couldnt adapt...raise exception ?
return typeobj
+ # if we adapted the given generic type to a database-specific type,
+ # but it turns out the originally given "generic" type
+ # is actually a subclass of our resulting type, then we were already
+ # were given a more specific type than that required; so use that.
+ if (issubclass(typeobj.__class__, impltype)):
+ return typeobj
return typeobj.adapt(impltype)
class NullTypeEngine(TypeEngine):