示例#1
0
def likeMsgDelete(msg_id, user_id):
    cursor.execute("DELETE FROM like_msg where msg_id = %s AND user_id = %s;",
                   (
                       msg_id,
                       user_id,
                   ))
    conn.commit()
示例#2
0
def userUnfollow(following_id, follower_id):
    cursor.execute(
        "DELETE FROM relation where following_id = %s AND follower_id = %s;",
        (following_id, follower_id))
    conn.commit()
    cursor.execute("SELECT nickname FROM users WHERE user_id = %s;",
                   (following_id, ))
    return ""
示例#3
0
def likeMsgCreate(msg_id, user_id, c_time):
    cursor.execute(
        "INSERT INTO like_msg(msg_id, user_id, c_time) VALUES(%s,%s,%s);", (
            msg_id,
            user_id,
            c_time,
        ))
    conn.commit()
示例#4
0
def userUpdatePasswordByEmail(password, email):
    cursor.execute(
        "UPDATE users SET password = crypt(%s, gen_salt('bf', 8)) where email = %s",
        (
            password,
            email,
        ))
    conn.commit()
示例#5
0
def messageCreate(user_id, content, c_time):
    cursor.execute(
        "INSERT INTO message(user_id,content,c_time) VALUES(%s,%s,%s);", (
            user_id,
            content,
            c_time,
        ))
    conn.commit()
示例#6
0
def userFollow(following_id, follower_id):
    cursor.execute(
        'SELECT * FROM relation WHERE following_id = %s AND follower_id = %s',
        (following_id, follower_id))
    if cursor.fetchone() is None and following_id != follower_id:
        c_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        cursor.execute(
            "INSERT INTO relation(following_id, follower_id, c_time) VALUES(%s,%s,%s);",
            (following_id, follower_id, c_time))
        conn.commit()
        cursor.execute("SELECT nickname FROM users WHERE user_id = %s;",
                       (following_id, ))
    return ""
示例#7
0
def userUpdateNicknameByEmail(nickname, email):
    cursor.execute("UPDATE users SET nickname = %s where email = %s", (
        nickname,
        email,
    ))
    conn.commit()
示例#8
0
def userDelete(email):
    cursor.execute("DELETE FROM users WHERE email = %s;", (email, ))
    conn.commit()
示例#9
0
def userCreate(email, nickname, password, c_time):
    cursor.execute(
        "INSERT INTO users(email,nickname,password,c_time) VALUES(%s,%s,crypt(%s, gen_salt('bf', 8)), %s);",
        (email, nickname, password, c_time))
    conn.commit()
示例#10
0
def messageUpdateContentById(content, msg_id):
    cursor.execute("UPDATE message SET content = %s where msg_id = %s;", (
        content,
        msg_id,
    ))
    conn.commit()
示例#11
0
def messageDeleteByUserId(user_id):
    cursor.execute("DELETE FROM message where user_id = %s;", (user_id, ))
    conn.commit()
示例#12
0
def likeCmtDelete(cmt_id, user_id):
    cursor.execute("DELETE FROM like_cmt where cmt_id = %s AND user_id = %s;",
                   (cmt_id, user_id))
    conn.commit()
示例#13
0
def likeCmtCreate(cmt_id, user_id, c_time):
    cursor.execute(
        "INSERT INTO like_cmt(cmt_id, user_id,c_time) VALUES(%s,%s,%s);",
        (cmt_id, user_id, c_time))
    conn.commit()
示例#14
0
def commentDeleteById(cmt_id):
    cursor.execute("DELETE FROM comment where cmt_id = %s;", (cmt_id, ))
    conn.commit()
示例#15
0
def commentUpdateById(content, cmt_id):
    cursor.execute("UPDATE comment SET content = %s where cmt_id = %s;",
                   (content, cmt_id))
    conn.commit()
示例#16
0
def commentCreate(msg_id, user_id, content, c_time):
    cursor.execute(
        "INSERT INTO comment(msg_id,user_id,content,c_time) VALUES(%s,%s,%s,%s);",
        (msg_id, user_id, content, c_time))
    conn.commit()
示例#17
0
def relationCreate(following_id, follower_id, c_time):
    cursor.execute(
        "INSERT INTO relation(following_id, follower_id, c_time) VALUES(%s,%s,%s);",
        (following_id, follower_id, c_time))
    conn.commit()
示例#18
0
def relationDelete(following_id, follower_id):
    cursor.execute(
        "DELETE FROM relation where following_id = %s AND follower_id = %s;",
        (following_id, follower_id))
    conn.commit()
示例#19
0
文件: sql.py 项目: ulyssetsd/bjtu-sql
# -*- coding: utf-8 -*-
from helpers import conn, cursor

sql = "DROP TABLE IF EXISTS users; " + \
      "CREATE TABLE users ( " + \
      "user_id serial primary key not null, " + \
      "email text, " + \
      "password text, " + \
      "nickname text, " + \
      "c_time timestamp );"
cursor.execute(sql)
conn.commit()

sql = "DROP TABLE IF EXISTS message; " + \
      "CREATE TABLE message ( " + \
      "msg_id serial primary key not null, " + \
      "user_id int not null, " + \
      "content text , " + \
      "c_time timestamp , " + \
      "status integer );"
cursor.execute(sql)
conn.commit()

sql = "DROP TABLE IF EXISTS comment; " + \
      "CREATE TABLE comment ( " + \
      "cmt_id serial primary key not null, " + \
      "msg_id int not null, " + \
      "user_id int not null, " + \
      "content text , " + \
      "c_time timestamp );"
cursor.execute(sql)
示例#20
0
def messageDeleteById(msg_id):
    cursor.execute("DELETE FROM message where msg_id = %s;", (msg_id, ))
    conn.commit()