解决sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1064, "You have an error in your

报错如下:
sqlalchemy.exc.ProgrammingError: (pymysql.err.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 'system taskName from tasks where id=4392' at line 1")
[SQL: SELECT  system taskName from tasks where id=4392]

语法错误?什么鬼?这么简单的sql语句我能写错,开玩笑!

百度了一下,有网友说是字符串转义的问题。
好吧,虽然也不是很清楚,就找了几个方法试了一下,结果可以了。

原代码:

ha = db.session.query(" system taskName from tasks where id="+id).all()

改后:

ha = db.session.query('" system taskName from tasks where id=%s"' %id).all()

1、在原来的双引号外又加了单引号;
2、把原来 “+” 拼接的形式改成 “%s” 占位。

ps:有人说使用pymysql.escape_string(),反正我的不行,可以试下哦!!

你可能感兴趣的:(Flask)