Exemple #1
0
def register(username, userpwd, usersex, usertel):
    """
    注册操作功能
    :param username: 用户名
    :param userpwd:  密码
    :param usersex:  性别
    :param usertel:  手机号
    :return:
    """

    # conn  = DbUtil.get_conn()
    # stu = (username, userpwd, usertel, usersex)
    # try:
    #     cur = conn.cursor()
    #     sql = 'INSERT INTO login (username, userpwd, usertel, usersex) VALUES (%s, %s, %s, %s)'
    #     cur.execute(sql, stu)
    #     conn.commit()
    #     return  stu[0]
    # finally:
    #     if conn:
    #         conn.close()

    sql2 = "select * from login where username = %s"
    key_list = ["id", "username", "userpwd", "usertel", "usersex"]
    rs = DbUtil.get_excute_select(sql2, (username,), key_list)
    if len(rs) == 0:
        obj = (username, userpwd, usersex, usertel)
        sql = "insert into login (username, userpwd, usersex, usertel) values (%s, %s, %s, %s)"
        DbUtil.get_excute_dml(sql, obj)
        return None
    else:
        return rs[0]
Exemple #2
0
def update_users(name, province, city, address, zip, date, id):
    sql = "select * from user where id = %s"
    obj = (id, )
    key_list = ["id", "name", "province", "city", "address", "zip", "date"]
    rs = DbUtil.get_excute_select(sql, obj, key_list)
    if len(rs) == 0:
        return None
    else:
        obj = (name, province, city, address, zip, date, id)
        sql = "update user set name=%s,province=%s,city=%s,address=%s,zip=%s,date=%s where id=%s"
        DbUtil.get_excute_dml(sql, obj)
        return rs[0]
Exemple #3
0
def add_users(name, province, city, address, zip, date):

    sql = "select * from user where name = %s"
    key_list = ["id", "name", "province", "city", "address", "zip", "date"]
    rs = DbUtil.get_excute_select(sql, (name,), key_list)

    if len(rs) == 0:
        obj = (name, province, city, address, zip, date)
        sql = "insert into user (name, province, city, address, zip, date) values (%s, %s, %s, %s, %s, %s)"
        DbUtil.get_excute_dml(sql, obj)
        return None
    else:
        return rs[0]
Exemple #4
0
def delete_user(id):
    """
    实现 id 删除用户
    :param id:
    :return:
    """
    key_list = ["id", "name", "province", "city", "address", "zip", "date"]
    sql = "select * from user where id = %s"
    obj = (id, )
    rs = DbUtil.get_excute_select(sql, obj, key_list)
    if len(rs) == 0:
        return None
    else:
        sql = "delete from user where id = %s"
        obj = (id, )
        DbUtil.get_excute_dml(sql, obj)
        return rs[0]
Exemple #5
0
def search():
    """
    实现所有数据查询
    :return:
    """
    key_list = ["id", "name", "province", "city", "address", "zip", "date"]
    # obj = (address,)
    sql = "select * from user"
    rs = DbUtil.get_excute_select(sql, None, key_list)
    if len(rs) == 0:
        return None
    else:
        return rs
Exemple #6
0
def login(username, userpwd):
    """
    登录 操作功能
    :param username: 用户名
    :param userpwd:  密 码
    :return:  查询不到返回None,否则返回字典对象
    """
    key_list = ["id", "username", "userpwd", "usertel", "usersex"]
    obj = (username, userpwd)
    sql = "select * from login where username = %s and userpwd = %s"
    rs = DbUtil.get_excute_select(sql, obj, key_list)
    if len(rs) == 0:
        return None
    else:
        return rs[0]
Exemple #7
0
def search(id):
    """
    实现id准确查询
    :param id:
    :return:
    """
    key_list = ["id", "name", "province", "city", "address", "zip", "date"]
    sql = "select * from user where id = %s"
    obj = (id, )
    rs = DbUtil.get_excute_select(sql, obj, key_list)
    if len(rs) == 0:
        return None
    else:
        return rs


# print(search("1"))