def copy_sql_db(storage_connection, mysql_connection, date):
cursor = storage_connection.cursor()
mysql_cursor = mysql_connection.cursor()
if date == "ALL":
cursor.execute("""select name, test_time, id from test_table""")
else:
cursor.execute("""select name, test_time, id from test_table where test_time > (CURDATE() - INTERVAL date day)""")
...我不知道要搜索什么才能将变量 date 传递给我的函数copy_sql_db到there :运行创建的脚本的cursor.execute...when在test_time >date附近的SQL语法中有一个错误。
发布于 2018-06-05 13:58:29
您需要使用占位符
试试这个:
cursor.execute("""select name, test_time, id from test_table where test_time > (CURDATE() - INTERVAL {0} day)""".format(date))或安全
cursor.execute("""select name, test_time, id from test_table where test_time > (CURDATE() - INTERVAL %s day)""", (date,))https://stackoverflow.com/questions/50701902
复制相似问题