MySql cursors.execute () with only one parameter: why a string sliced ​​into a list?

Status Quo:

I have a working database with tables and can query, insert, update, etc. The cursor is also connected to the right database.

Table:

screenshot of query result

Problem:

When it comes to querying data from a table, I run into problems:

query     = 'SELECT Last_Request_Time FROM Products WHERE idProduct = %s'
idProduct = '106'
cursor.execute(query, (idProduct))

During debugging, I look at the cursor.execute (): function params = str: 106will be passed:

stmt = operation % self._process_params(params)

Where

res = params
# pylint: disable=W0141
res = map(self._connection.converter.to_mysql, res)

called with res = str: 106. I'm not sure what the converter does, but as a result . And these arguments will be passed to the execution function, which will be launched into the following error: res = list: ['1', '0', '6']

File "C:\Python27\lib\site-packages\mysql\connector\cursor.py", line 480, in execute
"Wrong number of arguments during string formatting")
mysql.connector.errors.ProgrammingError: Wrong number of arguments during string formatting

Bad workaround:

I have a dirty workaround, but I'm not happy with that. In some cases, this may not work:

query     = 'SELECT Last_Request_Time FROM Products WHERE idProduct = %s AND Edition != %s'
idProduct = '106'
cursor.execute(query, (idProduct, 'A'))
+4
1

, ('hello') , ('hello',) . ( ​​, ) . , , - - .

, 106 [1, 0, 6]. (106,), .

, :

>>> for i in '106':
...     print(i)
...
1
0
6
>>> for i in ('106',):
...    print(i)
...
106

, "" , :

q = 'SELECT Last_Request_Time FROM Products WHERE idProduct = %s'
cursor.execute(q, (idProduct,))
+7

All Articles