回答編集履歴
3
分割について追記
answer
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
```
|
27
27
|
|
28
28
|
|
29
|
-
実行するSQLを調べたい時は、以下の
|
29
|
+
実行するSQLを調べたい時は、print文を追加して以下のように分割できます。
|
30
30
|
```Python
|
31
31
|
sql = 'update virustotal_api_keys set use_time = now(),use_numbers += 1 where id = %d' % (m+1)
|
32
32
|
# print文で表示される内容が実際に実行されるSQLです。
|
2
追記
answer
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
> mysql.connector.errors.ProgrammingError: 1064 (42000): 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 '+= 1 where id = 1' at line 1
|
2
2
|
|
3
3
|
質問文からは列:idの型が分かりませんが、エラーメッセージを見る限りでは
|
4
|
+
|
4
5
|
```sql
|
5
6
|
use_numbers += 1
|
6
7
|
```
|
@@ -9,14 +10,22 @@
|
|
9
10
|
use_numbers = use_numbers + 1
|
10
11
|
```
|
11
12
|
|
13
|
+
|
12
14
|
■補足解説
|
13
|
-
Pythonプログラム上のSQL文字列と実際に実行されるSQLをご
|
15
|
+
Pythonプログラム上のSQL文字列と実際に実行されるSQLをごちゃ混ぜに認識している気がします。
|
14
|
-
質問文のSQLで+=を使っている箇所は以下の部分です。
|
16
|
+
質問文のSQL文字列で+=を使っている箇所は以下の部分です。
|
15
17
|
|
16
18
|
```Python
|
17
19
|
self.cursor.execute('update virustotal_api_keys set use_time = now(),use_numbers += 1 where id = %d' % (m+1))
|
18
20
|
```
|
19
21
|
|
22
|
+
エラーメッセージが以下のメッセージなので、SQL中の%dは変数展開されています。
|
23
|
+
|
24
|
+
```SQL
|
25
|
+
'+= 1 where id = 1'
|
26
|
+
```
|
27
|
+
|
28
|
+
|
20
29
|
実行するSQLを調べたい時は、以下の三行に展開できます。
|
21
30
|
```Python
|
22
31
|
sql = 'update virustotal_api_keys set use_time = now(),use_numbers += 1 where id = %d' % (m+1)
|
1
補足解説
answer
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
> mysql.connector.errors.ProgrammingError: 1064 (42000): 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 '+= 1 where id = 1' at line 1
|
2
2
|
|
3
|
-
エラーメッセージを見る限りでは
|
3
|
+
質問文からは列:idの型が分かりませんが、エラーメッセージを見る限りでは
|
4
4
|
```sql
|
5
5
|
use_numbers += 1
|
6
6
|
```
|
@@ -9,6 +9,23 @@
|
|
9
9
|
use_numbers = use_numbers + 1
|
10
10
|
```
|
11
11
|
|
12
|
+
■補足解説
|
13
|
+
Pythonプログラム上のSQL文字列と実際に実行されるSQLをごっちゃに認識している気がします。
|
14
|
+
質問文のSQLで+=を使っている箇所は以下の部分です。
|
15
|
+
|
16
|
+
```Python
|
17
|
+
self.cursor.execute('update virustotal_api_keys set use_time = now(),use_numbers += 1 where id = %d' % (m+1))
|
18
|
+
```
|
19
|
+
|
20
|
+
実行するSQLを調べたい時は、以下の三行に展開できます。
|
21
|
+
```Python
|
22
|
+
sql = 'update virustotal_api_keys set use_time = now(),use_numbers += 1 where id = %d' % (m+1)
|
23
|
+
# print文で表示される内容が実際に実行されるSQLです。
|
24
|
+
print(sql)
|
25
|
+
self.cursor.execute(sql)
|
26
|
+
```
|
27
|
+
|
12
28
|
■余談
|
13
29
|
1,commit文が質問文にはないのですが、適切なタイミングでcommitを忘れずにしてくださいな。
|
14
|
-
2,self.connectとself.cursorはAnalysisクラスにclose関数を追加して[contextlib.closing](https://docs.python.jp/3/library/contextlib.html#contextlib.closing)を使う形にするとclose忘れを防ぎやすくなります。
|
30
|
+
2,self.connectとself.cursorはAnalysisクラスにclose関数を追加して[contextlib.closing](https://docs.python.jp/3/library/contextlib.html#contextlib.closing)を使う形にするとclose忘れを防ぎやすくなります。
|
31
|
+
3,SQLインジェクション防止のためにSQLプレースフォルダを使う事を検討してくださいな。
|