0

I am rewriting source code from mysql to sqlite and don't know how to escape a sequence argument in APSW driver:

cur.execute("""
    select *
    from users
    where user_id in ?
""", [[1, 2, 3]])

It is definitely a very basic need and it works well in mysql driver but I cannot find any such example for sqlite (APSW) by searching internet.

tlama
  • 607
  • 1
  • 10
  • 17
  • Does this answer your question? [select from sqlite table where rowid in list using python sqlite3 — DB-API 2.0](https://stackoverflow.com/questions/5766230/select-from-sqlite-table-where-rowid-in-list-using-python-sqlite3-db-api-2-0) – Shawn Jan 27 '20 at 00:24
  • Unfortunately not. Because I am using different driver (APSW), see https://www.sqlitetutorial.net/sqlite-python/ – tlama Jan 27 '20 at 00:53
  • Did you try it? – Shawn Jan 27 '20 at 00:54
  • Every driver has it's own advantages and disadvantages - that is the reason why they exist. So even if it worked in a different driver it would not fix this problem. APSW provides many low-level features including the ability to create user-defined aggregate, function, and collations from Python. – tlama Jan 27 '20 at 01:01
  • So you didn't try the approach of creating a query string with the appropriate number of placeholders to bind the values of your list to? You really should give it a shot. – Shawn Jan 27 '20 at 01:04
  • I am definitely using that approach now (and it works). I just search for an elegant solution. It works well in pymysql (and asynchronically in aiomysql) so I thought it should work in APSW too. I thought that I just don't know the solution. But maybe it does not exist. I really don't know. – tlama Jan 27 '20 at 01:12

1 Answers1

0

This will work:

cur.execute("""
    select *
    from users
    where user_id in ?
""", ((1, 2, 3)))
Itai Sevitt
  • 140
  • 1
  • 7