In order to create queries to the database for security purposes, it is always recommended to use placeholder . In the sqlite3 module sqlite3 for this, instead of variables, characters of a question mark ( ? ) ? placed in the query text, or a named placeholder , and the execute method passes the second parameter with a list of substituted variables for the first case, or a dictionary for the second.
Question mark example:
cur.execute("INSERT INTO posts VALUES (NULL, ?, 'default', '', 'no', ?, '0')", (big, string))
Example using named placeholders
cur.execute("INSERT INTO posts VALUES (NULL, :big, 'default', '', 'no', :string, '0')", {"big": big, "string": string})
Updated from the @jfs comment
If in the second case the names of the variables coincide with the names of the named placeholder , then the second parameter can be passed to the vars dictionary
big = 'other' string = 'ok' cur.execute("INSERT INTO posts VALUES (NULL, :big, 'default', '', 'no', :string, '0')", vars())
cur.execute("INSERT INTO posts VALUES (NULL, ?, 'default', '', 'no', ?, '0')", (big, string))- Eduard Izmalkov