The code is below. It returns "DELETE 1" when there is a record to delete and "DELETE 0" when there isn't. But it doesn't actually delete the record when there is one there. The exact same SQL (with %s
replaced with tournament_id
) pasted into pgAdmin III deletes the record. I'm at the wood/trees stage. Any ideas?
def deletePlayers(tournamentId):
# takes tournamentId and deletes all records from tournament_player
# with that tournamentId
# but not an error if no records to delete
# check tournamentId set if not return
if tournamentId < 1:
returnStr = "ERROR - tournamentId not set"
return returnStr
DB = connect()
cur = DB.cursor()
# delete data
SQL = "DELETE from tournament_player where tournament_id = %s;"
data = (tournamentId,)
cur.execute(SQL, data )
returnStr = cur.statusmessage
DB.commit
# tidy up
cur.close
DB.close
return returnStr
This is mostly unrelated to your database. To call a method in Python that has no arguments, add ()
to the end of it. This will call commit
on your database:
DB.commit()
while this only gets a method reference:
DB.commit
So in your code, you didn't actually commit. (Or close, for that matter, but that's not necessary.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With