Reputation: 7600
I am using sqlite3 but I am encountering some problems as I need to add strings containing the |
symbol
I have a table with just one column, and i do this:
s.execute('INSERT INTO mytable (col_name) VALUES (?);',"a|b")
But as a result i get this:
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 3 supplied.
I've also tried quoting, like this:
s.execute('INSERT INTO mytable (col_name) VALUES (?);',"'a|b'")
And the error is kind of different but still doesn't work
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 5 supplied.
How can I convince sqlite3 to accept my string as a single string?
Upvotes: 0
Views: 964
Reputation: 1121594
The parameter argument must be a sequence, so use a tuple here:
s.execute('INSERT INTO mytable (col_name) VALUES (?);', ("a|b",))
This has nothing to do with the pipe symbol, btw, but everything with the fact that strings are sequences too. A string of 3 characters is a sequence of 3 elements.
Upvotes: 3