當前位置: 首頁>>代碼示例>>Python>>正文


Python Connection.rollback方法代碼示例

本文整理匯總了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
開發者ID:yaroot,項目名稱:scripts,代碼行數:11,代碼來源:fav.py

示例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)
開發者ID:nolka,項目名稱:ircbot,代碼行數:104,代碼來源:bot.py


注:本文中的sqlite3.Connection.rollback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。