예제 #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 relationByFollowingIdAndFollowerId(following_id, follower_id):
    cursor.execute(
        'SELECT * FROM relation WHERE following_id = %s AND follower_id = %s',
        (
            following_id,
            follower_id,
        ))
    r = cursor.fetchone()
    return r
예제 #7
0
def userIdByEmailPassword(email, password):
    cursor.execute(
        "SELECT user_id FROM users WHERE email = %s AND password = crypt(%s, password);",
        (
            email,
            password,
        ))
    u = cursor.fetchone()
    if u is None:
        return None
    return u
예제 #8
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 ""
예제 #9
0
def userGetAll():
    cursor.execute("SELECT * FROM users")
    users = cursor.fetchall()
    return users
예제 #10
0
def userUpdateNicknameByEmail(nickname, email):
    cursor.execute("UPDATE users SET nickname = %s where email = %s", (
        nickname,
        email,
    ))
    conn.commit()
예제 #11
0
def likeMsgGetOne(msg_id, user_id):
    cursor.execute("SELECT * FROM like_msg where msg_id = %s AND user_id = %s",
                   (msg_id, user_id))
    like = cursor.fetchone()
    return like
예제 #12
0
def userByUserId(user_id):
    cursor.execute("SELECT * FROM users where user_id = %s;", (user_id, ))
    u = cursor.fetchone()
    return u
예제 #13
0
def userDelete(email):
    cursor.execute("DELETE FROM users WHERE email = %s;", (email, ))
    conn.commit()
예제 #14
0
def likeMsgGetAll():
    cursor.execute('SELECT * FROM like_msg')
    message = cursor.fetchall()
    return message
예제 #15
0
def countcmt(msg_id):
    cursor.execute("SELECT COUNT(*) FROM comment where msg_id = %s;",
                   (msg_id, ))
    like_num = cursor.fetchone()
    return like_num[0]
예제 #16
0
def likeMsgDeleteAll():
    cursor.execute("truncate table like_msg")
예제 #17
0
def userByEmail(email):
    cursor.execute("SELECT * FROM users where email = %s;", (email, ))
    u = cursor.fetchone()
    return u
예제 #18
0
def relationGetFollowingUserByFollowerId(follower_id):
    cursor.execute(
        "SELECT * FROM relation, users WHERE user_id = following_id AND follower_id = %s;",
        (follower_id, ))
    followings = cursor.fetchall()
    return followings
예제 #19
0
def searchGetUserResults(search, user_id):
    cursor.execute(
        "SELECT * FROM users WHERE (nickname LIKE %s OR email LIKE %s) AND user_id != %s;",
        (search, search, user_id))
    users = cursor.fetchall()
    return users
예제 #20
0
def relationByFollowerId(follower_id):
    cursor.execute('SELECT * FROM relation where follower_id = %s',
                   (follower_id, ))
    rs = cursor.fetchall()
    return rs
예제 #21
0
def likeMsgCountLike(msg_id):
    cursor.execute("SELECT COUNT(*) AS count FROM like_msg where msg_id = %s;",
                   (msg_id, ))
    like_num = cursor.fetchone()
    return like_num['count']
예제 #22
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()
예제 #23
0
def messageDeleteAll():
    cursor.execute("truncate table message")
예제 #24
0
def likeMsgCount():
    cursor.execute("SELECT COUNT(*) AS count FROM like_msg")
    nb = cursor.fetchone()
    if nb is None:
        return 0
    return nb['count']
예제 #25
0
def messageGetAll():
    cursor.execute('SELECT * FROM message')
    message = cursor.fetchall()
    return message
예제 #26
0
def userByNickname(nickname):
    cursor.execute("SELECT * FROM users where nickname = %s;", (nickname, ))
    u = cursor.fetchone()
    return u
예제 #27
0
def messageDeleteByUserId(user_id):
    cursor.execute("DELETE FROM message where user_id = %s;", (user_id, ))
    conn.commit()
예제 #28
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()
예제 #29
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)
예제 #30
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()