It seems like a typical issue in programming, but i didn’t find nothing usefull in google.
This is the code:
file=open('list.txt','r')
for line in file:
cursor.execute("CREATE TABLE IF NOT EXISTS \
%s(id INT(2) NOT NULL PRIMARY KEY AUTO_INCREMENT, \
entry TEXT NOT NULL)" % line)
file.close()
cursor.close()
db.close()
And this is the error when I try to create a table with single quotes:
Traceback (most recent call last):
File "test.py", line 104, in <module>
entry TEXT NOT NULL)" % line)
File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
_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 ''Hi 'Buddy!(id INT(2) NOT NULL PRIMARY KEY AUTO_INCREMENT, entry ' at line 1")
MySQLdb.escape_string(line) dont fix it by the way
I’m not sure why you’re doing that and I think I should suggest re-thinking your schema, but you can escape a table name with backticks
`.