我是Python的新用户MySLQdb。我有这个代码:
for row in csv_reader:
insert = """INSERT INTO %s
VALUES (DEFAULT, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """
cursor.execute(insert, (nome_tabela, row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13], row[14]))
但是当我执行时,我有以下错误: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 ''Aquecimento'\n\t\t\t\t\tVALUES (DEFAULT, 'c00010', 'Dorm1', '0.0', '0.0', '0.0', '3.4' at line 1")
我认为错误与表名有关,但我不确定。在
Afaik,
mysql-python
不处理表名替换:它盲目地在所有变量周围添加引号,并在SQL注入时转义数据。在您最好的运气是自己连接字符串,但是在本例中,您需要对
name_tabela
的内容格外小心:顺便说一下,您可以通过以下方式简化
^{pr2}$execute
第二个参数:相关问题 更多 >
编程相关推荐