summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f68a850)
raw | patch | inline | side by side (parent: f68a850)
author | stefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 20 Feb 2009 04:50:39 +0000 (04:50 +0000) | ||
committer | stefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 20 Feb 2009 04:50:39 +0000 (04:50 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4152 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/backends/back_mysql.py | patch | blob | history | |
roundup/backends/rdbms_common.py | patch | blob | history |
index bb233ffea862551ad9cf5a79fa2c395222369b98..b83db400468147f6830cc2b64302ea128c71a99c 100644 (file)
# convert to new MySQL data type
prop = properties[name]
if v is not None:
- e = self.hyperdb_to_sql_value[prop.__class__](v)
+ e = self.to_sql_value(prop.__class__)(v)
else:
e = None
l.append(e)
# re-create journal table
self.create_journal_table(klass)
- dc = self.hyperdb_to_sql_value[hyperdb.Date]
+ dc = self.to_sql_value(hyperdb.Date)
for nodeid, journaldate, journaltag, action, params in olddata:
self.save_journal(cn, cols, nodeid, dc(journaldate),
journaltag, action, params)
index 02a5d7e6e6b98399373ff0cc7d8e8e05a3798ade..dc7264830decd4e27accf113555305c8632536d2 100644 (file)
hyperdb.Boolean : 'BOOLEAN',
hyperdb.Number : 'REAL',
}
+
+ def hyperdb_to_sql_datatype(self, propclass):
+
+ datatype = self.hyperdb_to_sql_datatypes.get(propclass)
+ if datatype:
+ return datatype
+
+ for k, v in self.hyperdb_to_sql_datatypes.iteritems():
+ if issubclass(propclass, k):
+ return v
+
+ raise ValueError, '%r is not a hyperdb property class' % propclass
+
def determine_columns(self, properties):
""" Figure the column names and multilink properties from the spec
instance of a hyperdb "type" _or_ a string repr of that type.
"""
cols = [
- ('_actor', self.hyperdb_to_sql_datatypes[hyperdb.Link]),
- ('_activity', self.hyperdb_to_sql_datatypes[hyperdb.Date]),
- ('_creator', self.hyperdb_to_sql_datatypes[hyperdb.Link]),
- ('_creation', self.hyperdb_to_sql_datatypes[hyperdb.Date]),
+ ('_actor', self.hyperdb_to_sql_datatype(hyperdb.Link)),
+ ('_activity', self.hyperdb_to_sql_datatype(hyperdb.Date)),
+ ('_creator', self.hyperdb_to_sql_datatype(hyperdb.Link)),
+ ('_creation', self.hyperdb_to_sql_datatype(hyperdb.Date)),
]
mls = []
# add the multilinks separately
#and prop.find('Multilink') != -1:
#mls.append(col)
- datatype = self.hyperdb_to_sql_datatypes[prop.__class__]
+ datatype = self.hyperdb_to_sql_datatype(prop.__class__)
cols.append(('_'+col, datatype))
# Intervals stored as two columns
self.create_multilink_table(spec, propname)
else:
# add the column
- coltype = self.hyperdb_to_sql_datatypes[prop.__class__]
+ coltype = self.hyperdb_to_sql_datatype(prop.__class__)
sql = 'alter table _%s add column _%s %s'%(
spec.classname, propname, coltype)
self.sql(sql)
sql = """create table %s__journal (
nodeid integer, date %s, tag varchar(255),
action varchar(255), params text)""" % (spec.classname,
- self.hyperdb_to_sql_datatypes[hyperdb.Date])
+ self.hyperdb_to_sql_datatype(hyperdb.Date))
self.sql(sql)
self.create_journal_table_indexes(spec)
hyperdb.Number : lambda x: x,
hyperdb.Multilink : lambda x: x, # used in journal marshalling
}
+
+ def to_sql_value(self, propklass):
+
+ fn = self.hyperdb_to_sql_value.get(propklass)
+ if fn:
+ return fn
+
+ for k, v in self.hyperdb_to_sql_value.iteritems():
+ if issubclass(propklass, k):
+ return v
+
+ raise ValueError, '%r is not a hyperdb property class' % propklass
+
def addnode(self, classname, nodeid, node):
""" Add the specified node to its class's db.
"""
prop = props[col[1:]]
value = values[col[1:]]
if value is not None:
- value = self.hyperdb_to_sql_value[prop.__class__](value)
+ value = self.to_sql_value(prop.__class__)(value)
vals.append(value)
vals.append(nodeid)
vals = tuple(vals)
if value is None:
e = None
else:
- e = self.hyperdb_to_sql_value[prop.__class__](value)
+ e = self.to_sql_value(prop.__class__)(value)
vals.append(e)
vals.append(int(nodeid))
hyperdb.Number : _num_cvt,
hyperdb.Multilink : lambda x: x, # used in journal marshalling
}
+
+ def to_hyperdb_value(self, propklass):
+
+ fn = self.sql_to_hyperdb_value.get(propklass)
+ if fn:
+ return fn
+
+ for k, v in self.sql_to_hyperdb_value.iteritems():
+ if issubclass(propklass, k):
+ return v
+
+ raise ValueError, '%r is not a hyperdb property class' % propklass
+
def getnode(self, classname, nodeid):
""" Get a node from the database.
"""
continue
value = values[col]
if value is not None:
- value = self.sql_to_hyperdb_value[props[name].__class__](value)
+ value = self.to_hyperdb_value(props[name].__class__)(value)
node[name] = value
params = repr(params)
- dc = self.hyperdb_to_sql_value[hyperdb.Date]
+ dc = self.to_sql_value(hyperdb.Date)
journaldate = dc(journaldate)
self.save_journal(classname, cols, nodeid, journaldate,
# create the journal entry
cols = 'nodeid,date,tag,action,params'
- dc = self.hyperdb_to_sql_value[hyperdb.Date]
+ dc = self.to_sql_value(hyperdb.Date)
for nodeid, journaldate, journaltag, action, params in journal:
self.log_debug('addjournal %s%s %r %s %s %r'%(
classname, nodeid, journaldate, journaltag, action,
if not value:
continue
property = properties[param]
- cvt = self.hyperdb_to_sql_value[property.__class__]
+ cvt = self.to_sql_value(property.__class__)
if isinstance(property, Password):
params[param] = cvt(value)
elif isinstance(property, Date):
journal = self.load_journal(classname, cols, nodeid)
# now unmarshal the data
- dc = self.sql_to_hyperdb_value[hyperdb.Date]
+ dc = self.to_hyperdb_value(hyperdb.Date)
res = []
properties = self.getclass(classname).getprops()
for nodeid, date_stamp, user, action, params in journal:
if property is None:
# deleted property
continue
- cvt = self.sql_to_hyperdb_value[property.__class__]
+ cvt = self.to_hyperdb_value(property.__class__)
if isinstance(property, Password):
params[param] = cvt(value)
elif isinstance(property, Date):
def pack(self, pack_before):
""" Delete all journal entries except "create" before 'pack_before'.
"""
- date_stamp = self.hyperdb_to_sql_value[Date](pack_before)
+ date_stamp = self.to_sql_value(Date)(pack_before)
# do the delete
for classname in self.classes.keys():
cn, ln, pln, k, ln))
oc = '_%s._%s'%(ln, lp)
elif isinstance(propclass, Date) and p.sort_type < 2:
- dc = self.db.hyperdb_to_sql_value[hyperdb.Date]
+ dc = self.db.to_sql_value(hyperdb.Date)
if isinstance(v, type([])):
s = ','.join([a for x in v])
where.append('_%s._%s in (%s)'%(pln, k, s))