def save_data(self, items): if not items: return with db.transaction(): for item in items: sql = "replace into des_entities (" + db.format_with_separator( item.iterkeys()) + ") values (" l = [] for i in range(0, len(item.keys())): l.append('?') sql = sql + db.format_with_separator(l) + ")" db.update(sql, *item.values())
# -*- coding: utf-8 -*- import web import sys sys.path.append('..') from utils import db t=db.transaction() # 根据reminderid获取提醒 def getReminderById(id): data=db.select('reminder',where='reminderid=$id',vars=locals())[0] return dict(data) # 根据createuserid获取提醒 def getRemindersByCreateuserid(createuserid): data=db.select('reminder',where='createuserid=$createuserid',vars=locals()) return list(data) # 新增提醒 def postReminder(prop): try: insertid=db.insert('reminder',**prop) except: t.rollback() raise else: t.commit() return insertid
def setUp(self): self._transaction = db.transaction() self._transaction.__enter__()