Cam*_*oyd 4 psycopg2 python-2.7
代码如下.当有删除记录时返回"DELETE 1",没有删除时返回"DELETE 0".但是当它有一个记录时,它实际上并没有删除记录.粘贴到pgAdmin III中的完全相同的SQL(%s替换为tournament_id)删除记录.我在木头/树木阶段.有任何想法吗?
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
Run Code Online (Sandbox Code Playgroud)
这与您的数据库大多无关.要在Python中调用没有参数的方法,请添加()到它的末尾.这将调用commit您的数据库:
DB.commit()
Run Code Online (Sandbox Code Playgroud)
虽然这只得到一个方法参考:
DB.commit
Run Code Online (Sandbox Code Playgroud)
所以在你的代码中,你实际上没有提交.(或者关闭,就此而言,但这不是必要的.)
| 归档时间: |
|
| 查看次数: |
3900 次 |
| 最近记录: |