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


Python DBconnect.update_query方法代碼示例

本文整理匯總了Python中API.tools.DBconnect.update_query方法的典型用法代碼示例。如果您正苦於以下問題:Python DBconnect.update_query方法的具體用法?Python DBconnect.update_query怎麽用?Python DBconnect.update_query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在API.tools.DBconnect的用法示例。


在下文中一共展示了DBconnect.update_query方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: vote

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def vote(vote_id, vote_type):
    DBconnect.exist(entity="Posts", identifier="id", value=vote_id)
    if vote_type == -1:
        DBconnect.update_query("UPDATE Posts SET dislikes=dislikes+1, points=points-1 where id = %s", (vote_id,))
    else:
        DBconnect.update_query("UPDATE Posts SET likes=likes+1, points=points+1  where id = %s", (vote_id,))
    return details(details_id=vote_id, related=[])
開發者ID:Warprobot,項目名稱:DBForums,代碼行數:9,代碼來源:posts.py

示例2: remove_restore

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def remove_restore(thread_id, status):
    DBconnect.exist(entity="Threads", identifier="id", value=thread_id)
    DBconnect.update_query("UPDATE Threads SET isDeleted = %s WHERE id = %s", (status, thread_id, ))

    response = {
        "thread": thread_id
    }
    return response
開發者ID:alexss8,項目名稱:db_api,代碼行數:10,代碼來源:threads.py

示例3: open_close_thread

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def open_close_thread(id, isClosed):
    DBconnect.exist(entity="Threads", identifier="id", value=id)
    DBconnect.update_query("UPDATE Threads SET isClosed = %s WHERE id = %s", (isClosed, id, ))

    response = {
        "thread": id
    }

    return response
開發者ID:alexss8,項目名稱:db_api,代碼行數:11,代碼來源:threads.py

示例4: vote

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def vote(id, vote):
    DBconnect.exist(entity="Threads", identifier="id", value=id)

    if vote == -1:
        DBconnect.update_query("UPDATE Threads SET dislikes=dislikes+1, points=points-1 where id = %s", (id, ))
    else:
        DBconnect.update_query("UPDATE Threads SET likes=likes+1, points=points+1  where id = %s", (id, ))

    return details(id=id, related=[])
開發者ID:alexss8,項目名稱:db_api,代碼行數:11,代碼來源:threads.py

示例5: remove_follow

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def remove_follow(email1, email2):
    follows = DBconnect.select_query(
        'SELECT id FROM Followers WHERE follower = %s AND followee = %s', (email1, email2, )
    )

    if len(follows) != 0:
        DBconnect.update_query('DELETE FROM Followers WHERE follower = %s AND followee = %s', (email1, email2, ))
    else:
        raise Exception("No such following")

    return users.details(email1)
開發者ID:Warprobot,項目名稱:DBForums,代碼行數:13,代碼來源:followers.py

示例6: save_forum

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def save_forum(name, short_name, user):
    DBconnect.exist(entity="Users", identifier="email", value=user)
    forum = DBconnect.select_query(
        'select id, name, short_name, user FROM Forums WHERE short_name = %s', (short_name, )
    )
    if len(forum) == 0:
        DBconnect.update_query('INSERT INTO Forums (name, short_name, user) VALUES (%s, %s, %s)',
                               (name, short_name, user, ))
        forum = DBconnect.select_query(
            'select id, name, short_name, user FROM Forums WHERE short_name = %s', (short_name, )
        )
    return forum_description(forum)
開發者ID:alexss8,項目名稱:db_api,代碼行數:14,代碼來源:forums.py

示例7: remove_subscription

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def remove_subscription(email, thread_id):
    DBconnect.exist(entity="Threads", identifier="id", value=thread_id)
    DBconnect.exist(entity="Users", identifier="email", value=email)
    subscription = DBconnect.select_query(
        'select thread, user FROM Subscriptions WHERE user = %s AND thread = %s', (email, thread_id, )
    )
    if len(subscription) == 0:
        raise Exception("user " + email + " does not subscribe thread #" + str(thread_id))
    DBconnect.update_query('DELETE FROM Subscriptions WHERE user = %s AND thread = %s', (email, thread_id, ))

    response = {
        "thread": subscription[0][0],
        "user": subscription[0][1]
    }
    return response
開發者ID:Warprobot,項目名稱:DBForums,代碼行數:17,代碼來源:subscriptions.py

示例8: add_follow

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def add_follow(email1, email2):
    DBconnect.exist(entity="Users", identifier="email", value=email1)
    DBconnect.exist(entity="Users", identifier="email", value=email2)

    if email1 == email2:
        raise Exception("User with email=" + email1 + " can't follow himself")

    follows = DBconnect.select_query(
        'SELECT id FROM Followers WHERE follower = %s AND followee = %s', (email1, email2, )
    )

    if len(follows) == 0:
        DBconnect.update_query('INSERT INTO Followers (follower, followee) VALUES (%s, %s)', (email1, email2, ))

    user = users.details(email1)
    return user
開發者ID:Warprobot,項目名稱:DBForums,代碼行數:18,代碼來源:followers.py

示例9: save_subscription

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def save_subscription(email, thread_id):
    DBconnect.exist(entity="Threads", identifier="id", value=thread_id)
    DBconnect.exist(entity="Users", identifier="email", value=email)
    subscription = DBconnect.select_query(
        'select thread, user FROM Subscriptions WHERE user = %s AND thread = %s', (email, thread_id, )
    )
    if len(subscription) == 0:
        DBconnect.update_query('INSERT INTO Subscriptions (thread, user) VALUES (%s, %s)', (thread_id, email, ))
        subscription = DBconnect.select_query(
            'select thread, user FROM Subscriptions WHERE user = %s AND thread = %s', (email, thread_id, )
        )

    response = {
        "thread": subscription[0][0],
        "user": subscription[0][1]
    }
    return response
開發者ID:Warprobot,項目名稱:DBForums,代碼行數:19,代碼來源:subscriptions.py

示例10: save_user

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def save_user(email, username, about, name, optional):
    isAnonymous = 0
    if "isAnonymous" in optional:
        isAnonymous = optional["isAnonymous"]
    try:
        user = DBconnect.select_query('select email, about, isAnonymous, id, name, username FROM Users WHERE email = %s',
                           (email, ))
        if len(user) == 0:
            DBconnect.update_query(
                'INSERT INTO Users (email, about, name, username, isAnonymous) VALUES (%s, %s, %s, %s, %s)',
                (email, about, name, username, isAnonymous, ))
        user = DBconnect.select_query('select email, about, isAnonymous, id, name, username FROM Users WHERE email = %s',
                           (email, ))
    except Exception as e:
        raise Exception(e.message)

    return user_format(user)
開發者ID:Warprobot,項目名稱:DBForums,代碼行數:19,代碼來源:users.py

示例11: save_thread

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def save_thread(forum, title, isClosed, user, date, message, slug, optional):
    DBconnect.exist(entity="Users", identifier="email", value=user)
    DBconnect.exist(entity="Forums", identifier="short_name", value=forum)

    isDeleted = 0
    if "isDeleted" in optional:
        isDeleted = optional["isDeleted"]
    thread = DBconnect.select_query(
        'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '
        'FROM Threads WHERE slug = %s', (slug, )
    )
    if len(thread) == 0:
        DBconnect.update_query('INSERT INTO Threads (forum, title, isClosed, user, date, message, slug, isDeleted) '
                               'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',
                               (forum, title, isClosed, user, date, message, slug, isDeleted, ))
        thread = DBconnect.select_query(
            'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '
            'FROM Threads WHERE slug = %s', (slug, )
        )
    thread = thread[0]
    response = {
        'date': str(thread[0]),
        'forum': thread[1],
        'id': thread[2],
        'isClosed': bool(thread[3]),
        'isDeleted': bool(thread[4]),
        'message': thread[5],
        'slug': thread[6],
        'title': thread[7],
        'user': thread[8],
        'dislikes': thread[9],
        'likes': thread[10],
        'points': thread[11],
        'posts': thread[12],
    }

    # Delete few extra elements
    del response["dislikes"]
    del response["likes"]
    del response["points"]
    del response["posts"]

    return response
開發者ID:Warprobot,項目名稱:DBForums,代碼行數:45,代碼來源:threads.py

示例12: update_user

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def update_user(email, about, name):
    DBconnect.exist(entity="Users", identifier="email", value=email)
    DBconnect.update_query('UPDATE Users SET email = %s, about = %s, name = %s WHERE email = %s',
                           (email, about, name, email, ))
    return details(email)
開發者ID:Warprobot,項目名稱:DBForums,代碼行數:7,代碼來源:users.py

示例13: update_thread

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def update_thread(id, slug, message):
    DBconnect.exist(entity="Threads", identifier="id", value=id)
    DBconnect.update_query('UPDATE Threads SET slug = %s, message = %s WHERE id = %s', (slug, message, id, ))

    return details(id=id, related=[])
開發者ID:alexss8,項目名稱:db_api,代碼行數:7,代碼來源:threads.py

示例14: update

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def update(update_id, message):
    DBconnect.exist(entity="Posts", identifier="id", value=update_id)
    DBconnect.update_query("UPDATE Posts SET message = %s WHERE id = %s", (message, update_id))
    return details(details_id=update_id, related=[])
開發者ID:Warprobot,項目名稱:DBForums,代碼行數:6,代碼來源:posts.py

示例15: remove_restore

# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import update_query [as 別名]
def remove_restore(post_id, status):
    DBconnect.exist(entity="Posts", identifier="id", value=post_id)
    DBconnect.update_query("UPDATE Posts SET isDeleted = %s WHERE Posts.id = %s", (status, post_id))
    return {"post": post_id}
開發者ID:Warprobot,項目名稱:DBForums,代碼行數:6,代碼來源:posts.py


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