Author: phd
Date: 2007-07-12 09:24:47 -0600 (Thu, 12 Jul 2007)
New Revision: 2738
Modified:
SQLObject/trunk/sqlobject/col.py
SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
Log:
A patch by Claudio Martinez <cla...@gm...>:
MySQLConnection now recognizes Enum and Double columns
when drawing the database scheme from DB.
Modified: SQLObject/trunk/sqlobject/col.py
===================================================================
--- SQLObject/trunk/sqlobject/col.py 2007-07-12 15:24:24 UTC (rev 2737)
+++ SQLObject/trunk/sqlobject/col.py 2007-07-12 15:24:47 UTC (rev 2738)
@@ -930,7 +930,8 @@
return [consts.isString, consts.InList(self.enumValues)]
def createValidators(self):
- return [EnumValidator(name = self.name, enumValues = self.enumValues)] + \
+ return [EnumValidator(name = self.name, enumValues = self.enumValues,
+ notNone = self.notNone)] + \
super(SOEnumCol, self).createValidators()
def _mysqlType(self):
@@ -980,6 +981,8 @@
def to_python(self, value, state):
if value in self.enumValues:
return value
+ elif not self.notNone and value is None:
+ return None
else:
raise validators.Invalid("expected a member of %r in the EnumCol '%s', got %r instead" % \
(self.enumValues, self.name, value), value, state)
Modified: SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2007-07-12 15:24:24 UTC (rev 2737)
+++ SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2007-07-12 15:24:47 UTC (rev 2738)
@@ -221,9 +221,18 @@
if self.dbEncoding: kw['dbEncoding'] = self.dbEncoding
kw['name'] = soClass.sqlmeta.style.dbColumnToPythonAttr(field)
kw['dbName'] = field
- kw['notNone'] = not nullAllowed
+
+ # Since MySQL 5.0, 'NO' is returned in the NULL column (SQLObject expected '')
+ kw['notNone'] = (nullAllowed.upper() != 'YES' and True or False)
+
if default and t.startswith('int'):
kw['default'] = int(default)
+ elif default and t.startswith('float'):
+ kw['default'] = float(default)
+ elif default == 'CURRENT_TIMESTAMP' and t == 'timestamp':
+ kw['default'] = None
+ elif default and colClass is col.BoolCol:
+ kw['default'] = int(default) and True or False
else:
kw['default'] = default
# @@ skip key...
@@ -234,12 +243,22 @@
def guessClass(self, t):
if t.startswith('int'):
return col.IntCol, {}
+ elif t.startswith('enum'):
+ values = []
+ for i in t[5:-1].split(','): # take the enum() off and split
+ values.append(i[1:-1]) # remove the surrounding \'
+ return col.EnumCol, {'enumValues': values}
+ elif t.startswith('double'):
+ return col.FloatCol, {}
elif t.startswith('varchar'):
+ colType = col.StringCol
+ if self.kw.get('use_unicode', False):
+ colType = col.UnicodeCol
if t.endswith('binary'):
- return col.StringCol, {'length': int(t[8:-8]),
+ return colType, {'length': int(t[8:-8]),
'char_binary': True}
else:
- return col.StringCol, {'length': int(t[8:-1])}
+ return colType, {'length': int(t[8:-1])}
elif t.startswith('char'):
if t.endswith('binary'):
return col.StringCol, {'length': int(t[5:-8]),
|