I am using sqlite3 which requires us to put trailing comma after the last item of tuple (of values). The example below should return an expected output of (2, 3,)
. Is there a builtin function that can handle this?
args = 2, 3
print(args)
# (2, 3)
print((args,))
# ((2, 3),)
sqlite3 without trailing comma after 'John'
import sqlite3
conn = sqlite3.connect('test.db')
c = conn.cursor()
c.execute("SELECT * FROM stocks WHERE first_name = ?", ('John'))
print(c.fetchall())
conn.close()
# sqlite3.ProgrammingError: Incorrect number of bindings supplied. The
# current statement uses 1, and there are 4 supplied.
sqlite3 with trailing comma after 'John'
import sqlite3
conn = sqlite3.connect('test.db')
c = conn.cursor()
c.execute("SELECT * FROM stocks WHERE first_name = ?", ('John',))
print(c.fetchall())
conn.close()
# [(1, 'John')]
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 3 supplied
. The way I solve the problem is to add a trailing comma on the last part of the tuple.(2,3)
and(2,3,)
are completely identical; no code, sqlite included, can tell them apart.