0
Iは、UDPメッセージおよび更新MySQLデータベースを受け取るパイソン(ツイスト)でのUDPサーバを書いた:err_logでSQL構文エラー:1064、それを修正する方法?
sql = "update `device` set `msg`='%s', `d_addr`='%s', `d_port`=%d where `did`=%d" %(msg, host, port, r[0])
try:
txn.execute(sql)
except Exception, e:
f = open('./err_log', 'a')
f.write('%s\n' % e)
f.write('%s\n' % sql)
f.close()
エラー情報がある:そう
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '220.168.13.132', `d_port`=14058 where `did`=2' at line 1")
update `device` set `msg`='.?F/.ddd?', `d_addr`='220.168.13.132', `d_port`=14058 where `did`=2
、私は手動でSQLを実行するが、エラーがなかった。
MariaDB [kj]> update `device` set `msg`='.?F/.ddd?',
`d_addr`='220.168.13.132', `d_port`=14058 where `did`=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MSGがリモートクライアントによって送信された文字列(18バイト)で、文字列のASCIIコードである。
0x86 0xAC 0xCF 0x23 0x29 ... 0xE3
d_port接続を、int型のアールタイプをした、それは正しいです:%dの? – liuhui
@liuhuiクエリをパラメータ化すると、ドライバは自動的に型を検出し、型変換を処理します。答えに記載されているコードを試しましたか? – alecxe
私はテストしました、それはうまく行く、ありがとう! – liuhui