What is the most used way to create a Sqlite query in Python?
query = 'insert into events (date, title, col3, col4, int5, int6) values("%s", "%s", "%s", "%s", %s, %s)' % (date, title, col3, col4, int5, int6) print query c.execute(query)Problem: it won't work for example if
titlecontains a quote".query = 'insert into events (date, title, col3, col4, int5, int6) values(?, ?, ?, ?, ?, ?)' c.execute(query, (date, title, col3, col4, int5, int6))Problem: in solution 1., we could display/print the
query(to log it); here in solution 2. we can't log the query string anymore because the "replace" of each?by a variable is done during theexecute.Another cleaner way to do it? Can we avoid to repeat
?, ?, ?, ..., ?and have one singlevalues(?)and still have it replaced by all the parameters in the tuple?