Commit 3b41d9bb authored by Vincent Pelletier's avatar Vincent Pelletier

ERP5Type.patches.sqltest: Add support for type="datetime".

parent b700cece
......@@ -11,6 +11,7 @@
#
##############################################################################
from Shared.DC.ZRDB.sqltest import *
from Shared.DC.ZRDB import sqltest
list_type_list = list, tuple, set, frozenset, dict
......@@ -61,6 +62,16 @@ if 1: # For easy diff with original
except ValueError:
raise ValueError, (
'Invalid floating-point value for <em>%s</em>' % name)
elif t.startswith('datetime'):
# For subsecond precision, use 'datetime(N)' MySQL type,
# where N is the number of digits after the decimal point.
n = 0 if t == 'datetime' else int(t[9])
try:
v = (v if isinstance(v, DateTime) else DateTime(v)).toZone('UTC')
return "'%s%s'" % (v.ISO(),
('.%06u' % (v.micros() % 1000000))[:1+n] if n else '')
except Exception:
t = 'datetime'
else:
if not isinstance(v, (str, unicode)):
......@@ -94,3 +105,5 @@ if 1: # For easy diff with original
return "%s in (%s)" % (self.column, vs)
return "%s %s %s" % (self.column, self.op, vs[0])
SQLTest.render = SQLTest.__call__ = render
sqltest.valid_type = (('int', 'float', 'string', 'nb', 'datetime') + tuple('datetime(%s)' % x for x in xrange(7))).__contains__
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment