mysql-connector-python で、
datetime フィールド1つだけinsertしようとすると
prepareエラーで登録できません。
- mysql-connector-python VERSION
grep VERSION /usr/local/lib/python3.8/dist-packages/mysql/connector/version.py
VERSION = (8, 0, 20, '', 1)
- MySQLテーブル
create table t(
id int primary key auto_increment,
dt datetime
) engine = InnoDB"
- python
# これは成功する
s1 = "insert into t(id, dt) values (%s, %s)"
v1 = (1, datetime.datetime.strptime('2000-01-01', "%Y-%m-%d"))
cursor.execute(s1, v1)
# こっちは失敗する
s2 = "insert into t(dt) values (%s)"
v2 = (datetime.datetime.strptime('2000-01-01', "%Y-%m-%d"))
cursor.execute(s2, v2)
- エラー内容
Traceback (most recent call last):
File ".../t.py", line 17, in <module>
cursor.execute(s2, v2)
File "/usr/local/lib/python3.8/dist-packages/mysql/connector/cursor_cext.py", line 248, in execute
prepared = self._cnx.prepare_for_mysql(params)
File "/usr/local/lib/python3.8/dist-packages/mysql/connector/connection_cext.py", line 632, in prepare_for_mysql
raise ValueError("Could not process parameters")
ValueError: Could not process parameters
- 暫定対応
# prepare辞める
s2 = "insert into t(dt) values ('%s')" % ('2000-01-01')
cursor.execute(s2)