I am trying to insert the string received as an argument in sqlite db using python:
def addUser(self, name): cursor=self.conn.cursor() t = (name) cursor.execute("INSERT INTO users ( unique_key, name, is_online, translate) VALUES (NULL, ?, 1, 0);", t) self.conn.commit()
I do not want to use string concatenation, because http://docs.python.org/library/sqlite3.html advises against it.
However, when I run the code, I get an exception
cursor.execute("INSERT INTO users ( unique_key, name, is_online, translate) VALUES (NULL, ?, 1, 0);", t) pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 7 supplied
Why is Python splitting a string into characters, and is there a way to prevent this?
EDIT:
changing to t = (name,) gives the following exception
print "INSERT INTO users ( unique_key, name, is_online, translate) VALUES (NULL, ?, 1, 0)" + t exceptions.TypeError: cannot concatenate 'str' and 'tuple' objects