Author: phd
Date: 2007-07-12 09:22:33 -0600 (Thu, 12 Jul 2007)
New Revision: 2735
Modified:
SQLObject/branches/0.7/docs/News.txt
SQLObject/branches/0.7/sqlobject/col.py
SQLObject/branches/0.7/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/branches/0.7/docs/News.txt
===================================================================
--- SQLObject/branches/0.7/docs/News.txt 2007-07-11 16:04:53 UTC (rev 2734)
+++ SQLObject/branches/0.7/docs/News.txt 2007-07-12 15:22:33 UTC (rev 2735)
@@ -7,14 +7,17 @@
.. _start:
-SQLObject 0.7
-=============
+SQLObject 0.7.8
+===============
* Replaced calls to style.dbColumnToPythonAttr() in joins.py by name/dbName
lookup in case the user named columns differently using dbName.
* Minor correction in the tests: we fully support EnumCol in Postgres.
+* MySQLConnection now recognizes Enum and Double columns when drawing the
+ database scheme from DB.
+
SQLObject 0.7.7
===============
Modified: SQLObject/branches/0.7/sqlobject/col.py
===================================================================
--- SQLObject/branches/0.7/sqlobject/col.py 2007-07-11 16:04:53 UTC (rev 2734)
+++ SQLObject/branches/0.7/sqlobject/col.py 2007-07-12 15:22:33 UTC (rev 2735)
@@ -866,7 +866,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):
@@ -916,6 +917,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/branches/0.7/sqlobject/mysql/mysqlconnection.py
===================================================================
--- SQLObject/branches/0.7/sqlobject/mysql/mysqlconnection.py 2007-07-11 16:04:53 UTC (rev 2734)
+++ SQLObject/branches/0.7/sqlobject/mysql/mysqlconnection.py 2007-07-12 15:22:33 UTC (rev 2735)
@@ -171,9 +171,18 @@
colClass = col.UnicodeCol
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...
@@ -184,12 +193,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]),
|