0

I'd like to convert a python list [1,2,3] to a structure like ((1),(2),(3)) for a MYSQL execution.

My current version looks like

mySQLconnection = connectMyDatabase() #def connectMyDatabase() has been tested and works
cursor = mySQLconnection.cursor()

list = [...]
sql_query = "DELETE FROM multiusingfuncs WHERE muf_id IN (%s) " % ','.join(['?'] * len(list))
cursor.execute(sql_query, list)

which produces error message

ValueError: Could not process parameters

Thank's for any advice.

  • 1
    Try `print(sql_query)` after creating it, and see what is wrong with it. – CristiFati May 26 '20 at 10:33
  • 1
    You need to replace the `?` with `%s`. – Booboo May 26 '20 at 10:38
  • print(sql_query) gives DELETE FROM multiusingfuncs WHERE muf_id IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) – Oskar Neumann May 26 '20 at 10:39
  • 1
    See my comment above. `?` is not the parameter place holder to be used for prepared statements with MySql. ` ... join(['%s'] ...` – Booboo May 26 '20 at 10:43
  • Thank's, did work with your proposal. – Oskar Neumann May 26 '20 at 11:44

0 Answers0