Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- db=sqlite3.connect('chinook.db', timeout=10)
- def update_team(name, coach = '0', location = '0'):
- try:
- cur = db.cursor()
- if (coach == '0' and location == '0'):
- raise Exception('Хотя бы один из необязательных параметров должен быть заполнен!')
- elif(coach != '0' and location != '0'):
- sql = "SELECT ID FROM Coaches WHERE Name=?"
- cur.execute(sql, (coach,))
- ID_coach = cur.fetchone()[0]
- sql = """
- UPDATE Teams
- SET Coach_id = ?, Location = ?
- WHERE Name = ?
- """
- cur.execute(sql, (ID_coach,location, name))
- elif(coach != '0'):
- sql = "SELECT ID FROM Coaches WHERE Name=?"
- cur.execute(sql, (coach,))
- ID_coach = cur.fetchone()[0]
- sql = """
- UPDATE Teams
- SET Coach_id = ?
- WHERE Name = ?
- """
- cur.execute(sql, (ID_coach, name))
- elif(location != '0'):
- sql = """
- UPDATE Teams
- SET Location = ?
- WHERE Name = ?
- """
- cur.execute(sql, (location, name))
- except Exception as error:
- print(repr(error));
- return 1;
- db.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement