データベースに実行文がない更新文があります。私が知っている限り、それは構文的に正しいです。私はthis appを使って構文を検証しました。 except
ブロックが実行されているだけであり、その理由を理解できません。ここでPython CGIでSQL文が実行されない
はコードです:
for res_posts in list_of_response_ids:
temp_str = res_posts[0] # first element of res_posts tuple is string
temp_str += ":" + str(output[0])
try:
sql = "UPDATE POST SET res_post_id = %s WHERE post_id = %d;" % (str(temp_str), int(res_posts[1]))
cursor.execute(sql)
except:
print "uh oh"
、これは十分な情報ではない場合、私はより多くのコードを投稿することができます。
EDIT:ヤコブの助言に続いて、私はraise
を使用して、次のエラーを得た:
Traceback (most recent call last):
File "post.cgi", line 93, in <module>
cursor.execute(sql)
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 173, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':37 WHERE post_id = 8' at line 1")
はありがとうございました!
は、Pythonが提供する例外の詳細を捨てる必要です。 print文の後ろに 'raise'を追加して、完全なスタックトレースを確認することをお勧めします。このトレースの意味を理解する助けが必要な場合は、ここに貼り付けてください。 – JacobIRR
投稿を投稿に追加しました。構文に何が問題なのか? – Azhraam