Пример #1
0
def user_is_exist(db: DBController, user_name: str):
    sql = "select name from users where name = ?"
    with db.open():
        db.execute(sql, [user_name])
        result = db.fetchall()

    return len(result) != 0
Пример #2
0
def edit_user(db: DBController):
    user_name = input('User name > ')
    find_sql = 'select * from users where name = ?'
    edit_sql = 'update users set name = ?, age = ? where name = ?'
    with db.open():
        db.execute(find_sql, (user_name, ))
        user_records = db.fetchall()

        if len(user_records) == 0:
            print(f'Sorry, {user_name} is not found')
            return

        age = user_records[0][1]

    new_user_name = input_user_name(user_name)
    if new_user_name is None:
        return
    new_age = input_user_age(str(age))
    if new_age is None:
        return

    with db.open():
        db.execute(edit_sql, [new_user_name, new_age, user_name])
        db.commit()

    print(f'Update user: {new_user_name}')
Пример #3
0
def create_table(db: DBController):
    with db.open():
        db.execute('create table users(name text, age integer)')
        db.commit()