0

ここで何が間違っていますか?

 i = 0
 cursor.execute("insert into core_room (order) values (%i)", (int(i))

エラー:

 int argument required

データベース フィールドは int(11) ですが、%i がエラーを生成していると思います。

アップデート:

より完全な例を次に示します。

time = datetime.datetime.now()
floor = 0
i = 0

試してください:booster_cursor.execute('insert into core_room (extern_id, name, order, unit_id, created, updated) values (%s, %s, %s, %s, %s, %s)', (row[0] 、row[0]、i、フロア、時間、時間、))例外、e: e を印刷

エラー:

  (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 'order, unit_id, created, updated) values ('99', '99', '235', '12', '2009-07-24 1' at line 1")
4

3 に答える 3

4

2つのこと。まず、%sand notを使用し%iます。次に、パラメーターはタプルに含まれている必要があります。そのため、 (i,)( の後にコンマを付けてi) 必要があります。

また、ORDERはキーワードであり、フィールド名として使用している場合はエスケープする必要があります。

于 2009-07-24T23:39:41.943 に答える
1

execute() の 2 番目の引数は iterable であると予想されます。この場合、変更する必要があります。

(int(i))

に:

(int(i),)

タプルにします。

于 2009-07-24T23:40:22.363 に答える
1

おそらく?の代わりに使用する必要があります。%iそして、括弧がありません。

cursor.execute("insert into core_room (order) values (?)", (int(i),))
于 2009-07-24T23:41:12.783 に答える