コード例 #1
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
def userGetAll():
    cursor.execute("SELECT * FROM users")
    users = cursor.fetchall()
    return users
コード例 #10
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
def userUpdateNicknameByEmail(nickname, email):
    cursor.execute("UPDATE users SET nickname = %s where email = %s", (
        nickname,
        email,
    ))
    conn.commit()
コード例 #11
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
def userByUserId(user_id):
    cursor.execute("SELECT * FROM users where user_id = %s;", (user_id, ))
    u = cursor.fetchone()
    return u
コード例 #13
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
def userDelete(email):
    cursor.execute("DELETE FROM users WHERE email = %s;", (email, ))
    conn.commit()
コード例 #14
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
def likeMsgDeleteAll():
    cursor.execute("truncate table like_msg")
コード例 #17
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
def userByEmail(email):
    cursor.execute("SELECT * FROM users where email = %s;", (email, ))
    u = cursor.fetchone()
    return u
コード例 #18
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
def relationByFollowerId(follower_id):
    cursor.execute('SELECT * FROM relation where follower_id = %s',
                   (follower_id, ))
    rs = cursor.fetchall()
    return rs
コード例 #21
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
def messageDeleteAll():
    cursor.execute("truncate table message")
コード例 #24
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
def messageGetAll():
    cursor.execute('SELECT * FROM message')
    message = cursor.fetchall()
    return message
コード例 #26
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
def userByNickname(nickname):
    cursor.execute("SELECT * FROM users where nickname = %s;", (nickname, ))
    u = cursor.fetchone()
    return u
コード例 #27
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
def messageDeleteByUserId(user_id):
    cursor.execute("DELETE FROM message where user_id = %s;", (user_id, ))
    conn.commit()
コード例 #28
0
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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
ファイル: requete.py プロジェクト: ulyssetsd/bjtu-sql
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()