4
代碼如下。當有記錄要刪除時,它返回「DELETE 1」,沒有時記錄「DELETE 0」。但是,如果有記錄,它實際上並不刪除記錄。粘貼到pgAdmin III中的完全相同的SQL(用%s
替換爲tournament_id
)刪除記錄。我在木材/樹木階段。有任何想法嗎?python Psycopg刪除不起作用
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
非常感謝,這固定它 - 我會得到一個鋰充值。 – 2015-03-02 16:38:02