本文整理汇总了Python中sqlite3.Connection.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.rollback方法的具体用法?Python Connection.rollback怎么用?Python Connection.rollback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlite3.Connection
的用法示例。
在下文中一共展示了Connection.rollback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_max_id
# 需要导入模块: from sqlite3 import Connection [as 别名]
# 或者: from sqlite3.Connection import rollback [as 别名]
def load_max_id(db: sqlite3.Connection):
cur = db.cursor()
cur.execute('select min(id) from fav_tweets')
r = cur.fetchone()
db.rollback()
cur.close()
if r:
return r[0]
pass
示例2: SimpleBot
# 需要导入模块: from sqlite3 import Connection [as 别名]
# 或者: from sqlite3.Connection import rollback [as 别名]
#.........这里部分代码省略.........
]
if arg_dict:
query.append("WHERE")
query_conditions = list()
placeholders = list()
parsed = parse_data(arg_dict)
#print parsed
for attr, value in parsed:
query_conditions.append("%s %s"% (attr, value[0]))
placeholders.append(value[1])
query.append(" AND ".join(query_conditions))
query.append("LIMIT ?")
placeholders.append(has_limit)
query.append(") ORDER BY id ASC")
self.print_debug("querying: %s" % " ".join(query))
cur = self.db.execute(" ".join(query), placeholders)
message = ["chan\tnick\tmessage"]
for row in cur.fetchall():
datime = datetime.datetime.fromtimestamp(row['date'])
row['date'] = datime.strftime("%Y.%m.%d %H:%M:%S")
message.append("%(date)s\t%(channel)s\t%(nick)s\t%(message)s" % row)
if not message:
self.say_to(nick, "Nothing found :[")
return
resp = requests.post("https://clbin.com", dict(clbin="\n".join(message)))
if resp.status_code == 200:
self.say_to(nick, resp.text, channel)
else:
self.say_to(nick, "Post failed. Code %d" % resp.status_code,channel)
def acmd_nick(self, nick, ident, host, channel, args):
self.sendMessage("NICK :%s" % args)
def acmd_telki_loadf(self, nick, ident, host, channel, args):
self.print_debug("Loading telki from plain file %s" % args)
duplicated_rows = 0
added_rows = 0
processed_rows = 0
incorrect_urls = 0
if os.path.exists(args):
args = open(args)
elif "," in args:
args = args.split(",")
elif args.startswith("http"):
args = [args]
for line in args:
clean_url = line.strip()
if not clean_url.startswith("http"):
incorrect_urls +=1
continue
cur = self.db.execute("SELECT COUNT(*) count FROM social_telki WHERE URL=?", (clean_url, ))
count = cur.fetchone()
if int(count['count']) <=0:
self.db.execute("""INSERT INTO social_telki (
rating,
displayed_times,
url,
who_added,
date_added
)
VALUES
(?,?,?,?,?)""", (0, 0, clean_url, nick, self.get_unix_timestamp()))
added_rows +=1
else:
duplicated_rows += 1
processed_rows+=1
self.db.commit()
self.say_to(nick, "File loaded; total rows: %d; added: %s; doubles ignored: %s; incorrect urls: %d" % (processed_rows, added_rows, duplicated_rows, incorrect_urls), channel)
def cmd_telka(self, nick, ident, host, channel, args):
cur = self.db.execute("""
SELECT id, url FROM social_telki
WHERE displayed_times<= (SELECT MIN(displayed_times) FROM social_telki)
ORDER BY RANDOM()
LIMIT 1
""")
row = cur.fetchone()
if row:
cur.execute("UPDATE social_telki SET displayed_times=displayed_times+1 WHERE id=?", (row['id'], ))
url = row['url']
resp = requests.get(url)
if resp.status_code == 200:
self.say_to(args or nick, row['url'], channel)
self.db.commit()
else:
self.say_to(nick, "Еще разок попробуй, ссыль битая :(", channel)
self.db.rollback()
return
self.say_to(nick, "Nothing found O_o", channel)