本文整理汇总了Python中DBUtil.int_to_ctime方法的典型用法代码示例。如果您正苦于以下问题:Python DBUtil.int_to_ctime方法的具体用法?Python DBUtil.int_to_ctime怎么用?Python DBUtil.int_to_ctime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBUtil
的用法示例。
在下文中一共展示了DBUtil.int_to_ctime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _insert_row
# 需要导入模块: import DBUtil [as 别名]
# 或者: from DBUtil import int_to_ctime [as 别名]
def _insert_row(self, cur, forcedTime=None):
sql = "INSERT INTO %s" % (self._get_table_name())
keys = []
values = []
for key, value in self.__dict__.iteritems():
if _isCallable(value):
continue
if key == "eventName":
continue
if key == "eventTime":
if forcedTime:
value = forcedTime
else:
value = DBUtil.int_to_ctime(value)
keys.append(key)
values.append(value)
sql = sql + " (%s) VALUES (%s)" % (", ".join(keys), ", ".join(["%s"]*len(keys)))
return cur.execute(sql, values)
示例2: insert
# 需要导入模块: import DBUtil [as 别名]
# 或者: from DBUtil import int_to_ctime [as 别名]
def insert(self, cur):
#figure out what hour this event supposedly happened in:
assert type(self.eventTime) == types.IntType, "eventTime must be an integer number of seconds!"
exactTime = self.eventTime - (self.eventTime % _AGGREGATE_INTERVAL)
exactTime = DBUtil.int_to_ctime(exactTime)
#check if there is an existing row for this time and source:
sql = "SELECT COUNT(*) FROM %s" % (self._get_table_name())
sql += " WHERE eventTime = %s and source = %s;"
cur.execute(sql, (exactTime, self.source))
numRows = cur.fetchone()[0]
if numRows > 0:
assert numRows == 1, "Should never be multiple rows for the same time and source!"
#update that row with the new count:
sql = "UPDATE %s" % (self._get_table_name())
sql += " SET amount = amount + %s WHERE eventTime = %s and source = %s;"
return cur.execute(sql, (self.amount, exactTime, self.source))
else:
#insert a new row:
return self._insert_row(cur, exactTime)