In mysql-connector-python,
Attempting to insert only one datetime field
Unable to register with prepare error.
grep VERSION/usr/local/lib/python 3.8/dist-packages/mysql/connector/version.py
VERSION=(8,0,20,',1)
create table(
id int primary key auto_increment,
dt datetime
engine=InnoDB"
#This will succeed
s1 = "insert into (id, dt) values(%s, %s)"
v1 = (1, datetime.datetime.strptime('2000-01-01', '%Y-%m-%d')))
cursor.execute(s1,v1)
# I will fail-failure.
s2 = "insert into(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/python 3.8/dist-packages/mysql/connector/cursor_cext.py", line 248, in execute
prepared=self._cnx.prepare_for_mysql(params)
File"/usr/local/lib/python 3.8/dist-packages/mysql/connector/connection_cext.py", line 632, prepare_for_mysql
raise ValueError ("Could not process parameters")
ValueError: Could not process parameters
#prepare quit
s2 = "insert into(dt) values('%s')"%('2000-01-01')
cursor.execute(s2)
Self-Solving
When there was one parameter, adding a comma was required.
v2=(datetime.datetime.strptime('2000-01-01', '%Y-%m-%d'), )
© 2024 OneMinuteCode. All rights reserved.