From e69afcc59a5667480bc64f142f88aa92dbafee71 Mon Sep 17 00:00:00 2001 From: schlatterbeck Date: Mon, 21 Mar 2011 20:49:56 +0000 Subject: [PATCH] - optimisation for date: if the database provides us with a datetime object, use that for creation of the roundup Date object -- don't convert to string first git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4582 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/backends/rdbms_common.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/roundup/backends/rdbms_common.py b/roundup/backends/rdbms_common.py index 9c7d721..eb1b7c9 100644 --- a/roundup/backends/rdbms_common.py +++ b/roundup/backends/rdbms_common.py @@ -52,7 +52,7 @@ the same name. __docformat__ = 'restructuredtext' # standard python modules -import sys, os, time, re, errno, weakref, copy, logging +import sys, os, time, re, errno, weakref, copy, logging, datetime # roundup modules from roundup import hyperdb, date, password, roundupdb, security, support @@ -62,6 +62,7 @@ from roundup.backends import locking from roundup.support import reversed from roundup.i18n import _ + # support from roundup.backends.blobfiles import FileStorage try: @@ -90,6 +91,13 @@ def _bool_cvt(value): # assume it's a number returned from the db API return int(value) +def date_to_hyperdb_value(d): + """ convert date d to a roundup date """ + if isinstance (d, datetime.datetime): + return date.Date(d) + return date.Date (str(d).replace(' ', '.')) + + def connection_dict(config, dbnamestr=None): """ Used by Postgresql and MySQL to detemine the keyword args for opening the database connection.""" @@ -1039,7 +1047,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): sql_to_hyperdb_value = { hyperdb.String : str, - hyperdb.Date : lambda x:date.Date(str(x).replace(' ', '.')), + hyperdb.Date : date_to_hyperdb_value, # hyperdb.Link : int, # XXX numeric ids hyperdb.Link : str, hyperdb.Interval : date.Interval, @@ -2660,6 +2668,7 @@ class Class(hyperdb.Class): name = p.name assert (name) classes[key][name] = p + p.to_hyperdb = self.db.to_hyperdb_value(p.propclass.__class__) while True: row = cursor.fetchone() if not row: break @@ -2674,8 +2683,7 @@ class Class(hyperdb.Class): for propname, p in pt.iteritems(): value = row[p.sql_idx] if value is not None: - cls = p.propclass.__class__ - value = self.db.to_hyperdb_value(cls)(value) + value = p.to_hyperdb(value) node[propname] = value self.db._cache_save(key, node) yield str(row[0]) -- 2.30.2