Following the advice on this thread, I am storing my list
as string
type in MySQL database
, but, I'm facing this error:
_mysql_exceptions.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'foo_bar" but I can\\\'t bar.\', u\'high\', 0]]")\' at line 1')
on some list entries like this one:
var1 = 'Name'
var2 = 'Surname'
var3 = 15
var4 = [u'The Meter', [[u'Black', u'foo foo bar bar "foo_bar" but I can\'t bar', u'high', 0]]]
I figured that's because there's a double quote at the beginning of foo_bar
and I am using the following code to make entries in the database:
SQL = 'INSERT INTO test_table (col1, col2, col3, col4) VALUES ("{}", "{}", "{}", "{}")'.format(var1, var2, var3, var4)
cursor.execute(SQL)
And the double quotes are not being escaped.
If i remove the double quotes from:
("{}", "{}", "{}", "{}")
, I get the same error,
I tried using a different string formatting, (using %s
) but that didn't work either.
Any ideas?