Beispiel #1
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}')
Beispiel #2
0
    def putCrawlerResponse(self, response):
        conn = DBController().getConnection()
        c = conn.cursor()

        try:
            c.execute("INSERT INTO {} ({}) VALUES ('{}', '{}', {}, '{}', '{}', '{}')".\
                    format(
                      self.table,
                      self.config.deals_columns,
                      response.start_airport,
                      response.end_airport,
                      response.price,
                      response.outbound,
                      response.inbound,
                      response.website
                    ))
        except Exception as e:
            print('ERROR: Failed to insert a crawler response:\n' + str(e))
        conn.commit()
        conn.close()
Beispiel #3
0
def create_table(db: DBController):
    with db.open():
        db.execute('create table users(name text, age integer)')
        db.commit()