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'):
- cur = db.cursor()
- if (coach == '0' and location == '0'):
- print('Хотя бы один из необязательных параметров должен быть заполнен!')
- return -1
- 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))
- db.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement