python - Pass SQL column name as attribute of cursor.execute() -
i want pass column name attribute of function cursor.execute()
conn = sqlite3.connect(db) cursor = conn.cursor() cursor.execute("insert table (?) values (?)", (column, value)) is possible?
in current form receive error syntaxerror: invalid syntax
this work, assuming column not user defined input.
cursor.execute( "insert table ({column}) values (?)".format(column=column), (value,) )
Comments
Post a Comment