def add_book(_id, book_name, tags, intro, rating, url): book_name = escape_str(book_name) tags = escape_str(tags) connection = get_con() cursor = connection.cursor() sql = """insert into books(id, book_name, tags, intro, rating, url) values (%s, "%s", "%s", "%s", %s, "%s")""" \ % (_id, book_name, tags, intro, rating, url) try: cursor.execute(sql) connection.commit() except Exception as e: # log("sql执行异常:", e) connection.rollback() connection.close()
def has_tag(tag): tag = escape_str(tag) connection = get_con() cursor = connection.cursor() sql = """select id from tags where name = "%s" """ % tag cursor.execute(sql) data = cursor.fetchall() connection.close() return len(data) > 0
def update_tag_doing(name): name = escape_str(name) connection = get_con() cursor = connection.cursor() sql = """update tags set done = %s where name = "%s" """ % (-1, name) try: cursor.execute(sql) connection.commit() except Exception as e: # log("sql执行异常:", e) connection.rollback() connection.close()
def add_tag(name): name = escape_str(name) connection = get_con() cursor = connection.cursor() sql = """insert into tags(name, done, page_start) values ("%s", 0, 0)""" % name try: cursor.execute(sql) connection.commit() except Exception as e: # log("sql执行异常:", e) connection.rollback() connection.close()