I want to take a user input from an html form, and do a SELECT by matching a column to the user input, and be safe for injection. BUT I want the user input to be a comma separated list. For example, if the column is called "name" and user_input is "Alice,Bob,Carrol" I wan to execute the query
SELECT FROM table WHERE name IN ("Alice","Bob","Carrol");
Which means I have the same problem as in this question select from sqlite table where rowid in list using python sqlite3 — DB-API 2.0. But of course I do not want to do string concatenation myself to avoid injections. At the same time, because there could be any number of commas in user_input, I cannot do this:
db.execute('SELECT FROM table WHERE name IN (?,?,?)', user_input_splited)
I looked for a way to sanitize or escape the input by hand, to be able to do something like that:
db.execute('SELECT FROM table WHERE name IN ?', user_input_sanitized)
But I didn't find it. What's the best approach here?