I'm trying to dynamicly create and edit tables, and i haven't had much luck getting it to work. The most intuitive way I could think to try this is to do some thing like:
newtablename='a_table_name'
conn.execute("""CREATE TABLE %s (x int, y int)""",(name,))
but this does not work, giving a error like:
error num: 1064, "You have an error in your SQL syntax near ''a_table_name' (x int,y int)'
I also tried using MySQL's built in variables but that didn't work either, any suggestions?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to dynamicly create and edit tables, and i haven't had much luck getting it to work. The most intuitive way I could think to try this is to do some thing like:
newtablename='a_table_name'
conn.execute("""CREATE TABLE %s (x int, y int)""",(name,))
but this does not work, giving a error like:
error num: 1064, "You have an error in your SQL syntax near ''a_table_name' (x int,y int)'
I also tried using MySQL's built in variables but that didn't work either, any suggestions?
The quoting mechanism only works for parameter values. Use To substitute for table or column names use Python's % operator instead:
conn.execute("""CREATE TABLE %s (x int, y int)""" % name)