def log_and_execute(cursor, sql, *args):
    s = sql
if len(args) > 0:
    cursor.execute('SELECT ' + ', '.join(['quote(?)' for i in args]), args)
Python SQLite how to get SQL string statement being executed