Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.25 KB | None | 0 0
  1. import sqlite3
  2. db=sqlite3.connect('chinook.db', timeout=10)
  3. def update_team(name, coach = '0', location = '0'):
  4.     cur = db.cursor()
  5.     if (coach == '0' and location == '0'):
  6.         print('Хотя бы один из необязательных параметров должен быть заполнен!')
  7.         return -1
  8.     elif(coach != '0' and location != '0'):
  9.         sql = "SELECT ID FROM Coaches WHERE Name=?"
  10.         cur.execute(sql, (coach,))
  11.         ID_coach = cur.fetchone()[0]
  12.         sql =   """
  13.                UPDATE Teams
  14.                SET Coach_id = ?, Location = ?
  15.                WHERE Name = ?
  16.                """
  17.         cur.execute(sql, (ID_coach,location, name))
  18.     elif(coach != '0'):
  19.         sql = "SELECT ID FROM Coaches WHERE Name=?"
  20.         cur.execute(sql, (coach,))
  21.         ID_coach = cur.fetchone()[0]
  22.         sql =   """
  23.                UPDATE Teams
  24.                SET Coach_id = ?
  25.                WHERE Name = ?
  26.                """
  27.         cur.execute(sql, (ID_coach, name))
  28.     elif(location != '0'):
  29.         sql =   """
  30.                UPDATE Teams
  31.                SET Location = ?
  32.                WHERE Name = ?
  33.                """
  34.         cur.execute(sql, (location, name))
  35.     db.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement