Correction des requetes SQL

This commit is contained in:
guimoz 2017-01-31 17:13:19 +01:00
parent 9eb47a7c26
commit 81f7838d17

View file

@ -73,7 +73,7 @@ def get_player(player_id):
cur = con.cursor() cur = con.cursor()
cur.execute("""select id,firstname,name,ban_end from players cur.execute("""select id,firstname,name,ban_end from players
where id=(?)""", [player_id]) where id=%i"""% [player_id])
row = cur.fetchone() row = cur.fetchone()
con.close() con.close()
@ -88,7 +88,7 @@ def get_player_from_ip(ip):
machines.id,machines.ip,players.ban_end machines.id,machines.ip,players.ban_end
from players from players
inner join machines on players.id=machines.player_id inner join machines on players.id=machines.player_id
where machines.ip=(?)""", [ip]) where machines.ip=%s"""% [ip])
row = cur.fetchone() row = cur.fetchone()
con.close() con.close()
@ -109,7 +109,7 @@ def get_player_from_full_name(firstname, name):
machines.id,machines.ip,players.ban_end machines.id,machines.ip,players.ban_end
from players from players
inner join machines on players.id=machines.player_id inner join machines on players.id=machines.player_id
where players.firstname=(?) and players.name=(?)""", [firstname, name]) where players.firstname=%s and players.name=%s"""% [firstname, name])
row = cur.fetchone() row = cur.fetchone()
con.close() con.close()
@ -125,7 +125,7 @@ def is_banned(user_id):
con = connect_sql() con = connect_sql()
cur = con.cursor() cur = con.cursor()
cur.execute("""select ban_end from players where id=(?)""", [user_id]) cur.execute("""select ban_end from players where id=%i"""% [user_id])
ban_end = cur.fetchone()[0] ban_end = cur.fetchone()[0]
con.close() con.close()
@ -153,7 +153,7 @@ def get_players_not_banned():
cur = con.cursor() cur = con.cursor()
cur.execute("""select id,firstname,name from players cur.execute("""select id,firstname,name from players
where (?) > ban_end """, [time()]) where %f > ban_end """% [time()])
rows = cur.fetchall() rows = cur.fetchall()
con.close() con.close()
@ -201,7 +201,7 @@ def ban(player_id, target_id, success):
cur = con.cursor() cur = con.cursor()
cur.execute("""select id,ban_end from players cur.execute("""select id,ban_end from players
where id=(?)""", [banned_player['id']]) where id=%i"""% [banned_player['id']])
con.commit() con.commit()
con.close() con.close()
@ -211,8 +211,8 @@ def ban(player_id, target_id, success):
ban_end = cur.fetchone()[0] ban_end = cur.fetchone()[0]
ban_end = time() + BAN_DURATION ban_end = time() + BAN_DURATION
cur.execute("""update players set ban_end=(?) cur.execute("""update players set ban_end=%f
where id=(?)""", [ban_end, banned_player['id']]) where id=%i"""% [ban_end, banned_player['id']])
con.commit() con.commit()
@ -220,7 +220,7 @@ def ban(player_id, target_id, success):
con = connect_sql() con = connect_sql()
cur = con.cursor() cur = con.cursor()
cur.execute("""insert into bans (player_id,target_id,success,time) cur.execute("""insert into bans (player_id,target_id,success,time)
values (?,?,?,?)""", [player['id'], target['id'], \ values %i,%i,%i,%f"""% [player['id'], target['id'], \
success and 1 or 0, time()]) success and 1 or 0, time()])
con.commit() con.commit()
con.close() con.close()
@ -230,8 +230,8 @@ def unban(player_id):
con = connect_sql() con = connect_sql()
cur = con.cursor() cur = con.cursor()
cur.execute("""update players set ban_end=(?) cur.execute("""update players set ban_end=%f
where id=(?)""", [time() - BAN_DURATION, player_id]) where id=%i"""% [time() - BAN_DURATION, player_id])
con.commit() con.commit()
con.close() con.close()
@ -241,9 +241,7 @@ def get_bans(player_id):
cur = con.cursor() cur = con.cursor()
# Bannissements concernant le joueur : # Bannissements concernant le joueur :
cur.execute("""select player_id,target_id,success,time from bans cur.execute("""select player_id,target_id,success,time from bans where target_id=%i or player_id=%i""" % (player_id, player_id))
where target_id=(?)
or player_id=(?)""", [player_id, player_id])
rows = cur.fetchall() rows = cur.fetchall()
con.close() con.close()
@ -312,7 +310,7 @@ def banned_ip():
cur.execute("""select machines.ip from players cur.execute("""select machines.ip from players
inner join machines on players.id=machines.player_id inner join machines on players.id=machines.player_id
where players.ban_end>(?)""", [time()]) where players.ban_end>%f"""% [time()])
rows = cur.fetchall() rows = cur.fetchall()
con.close() con.close()