def findsetsbetween(plyr1,plyr2) : setlist = [] with conn: cur = conn.cursor() cur.execute('SELECT * FROM Sets WHERE (id_p1 = ? AND id_p2 = ?) OR (id_p2 = ? AND id_p1 = ?)',(plyr1.pkey,plyr2.pkey,plyr1.pkey,plyr2.pkey,)) for row in cur.fetchall() : tour= binarysearch(alltournaments,row["tournament_id"]) if (row["id_p1"]==plyr1.pkey) : setlist.append(player.Set(row["id"],plyr1,plyr2, tour, row["score1"], row["score2"],row["description"])) else : setlist.append(player.Set(row["id"],plyr2,plyr1,tour, row["score1"], row["score2"],row["description"])) return setlist
def findallsetsfortournament(tournament) : setlist = [] with conn: cur = conn.cursor() cur.execute('SELECT * FROM Sets WHERE tournament_id = ?', (tournament.pkey,)) for row in cur.fetchall(): p1 = binarysearch(allplayers, row["id_p1"]) p2 = binarysearch(allplayers, row["id_p2"]) setlist.append(player.Set(row["id"], p1, p2, tournament, row["score1"], row["score2"], row["description"])) return setlist
def findsetsforplayer(pkey) : setlist = [] with conn: cur = conn.cursor() cur.execute('SELECT * FROM Sets WHERE id_p1 = pkey OR id_p2 = pkey') for row in cur.fetchall() : p1 = binarysearch(allplayers, row["id_p1"]) p2 = binarysearch(allplayers, row["id_p2"]) tour = binarysearch(alltournaments, row["tournament_id"]) setlist.append(player.Set(row["id"], p1, p2, tour, row["score1"], row["score2"],row["description"])) return setlist
def findset(setti) : with conn: cur = conn.cursor() cur.execute('SELECT * FROM Sets WHERE ((id_p1=? AND id_p2=? AND score1=? AND score2=?) OR (id_p2=? AND id_p1=? AND score2=? AND score1 = ?)) AND tournament_id=? AND description = ?',(setti.player1.pkey,setti.player2.pkey,setti.score1,setti.score2,setti.player1.pkey,setti.player2.pkey,setti.score1,setti.score2,setti.tournament.pkey,setti.description,)) row = cur.fetchone() if (row is None) : return None p1 = findplayerbyid(row["id_p1"]) p2 = findplayerbyid(row["id_p2"]) return player.Set(row["id"],p1,p2,setti.tournament,row["score1"],row["score2"],row["description"]) return None
def findallsets() : global allsets setlist=[] with conn: cur = conn.cursor() cur.execute('SELECT * FROM Sets ORDER BY id ASC') for row in cur.fetchall() : p1 = binarysearch(allplayers, row["id_p1"]) p2 = binarysearch(allplayers, row["id_p2"]) tour = binarysearch(alltournaments, row["tournament_id"]) setiter = player.Set(row["id"],p1,p2,tour, row["score1"], row["score2"], row["description"]) setlist.append(setiter) allsets = setlist.copy() return setlist