无转义字符的python peewee原始查询

ryhaxcpt  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(456)

在python peewee(peewee-2.8.8)orm中有没有什么方法可以防止反斜杠转义?
我想在mysql数据库中执行查询:

SHOW MASTER STATUS\G

“\g”部分是必不可少的!我需要把结果垂直排列。
问题是peewee总是转义反斜杠(\),所以它在mysql中的结尾是:

SHOW MASTER STATUS\\G

当然,mysql会发出一个错误:

"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 '\\G' at line 1"

我尝试使用普通的“execute\u sql”方法:

cursor = RaDatabase.execute_sql('SHOW MASTER STATUS\G')

以及“原始”方法:

query = BaseModel.raw('SHOW MASTER STATUS\G')
result = query.execute()

但都以转义字符结束。

p1iqtdky

p1iqtdky1#

你试过使用“原始”字符串吗?

cursor = RaDatabase.execute_sql(r'SHOW MASTER STATUS\G')

不管您传递给.execute_sql()的是什么,实际上都会被传递给mysql驱动程序(pymysql,或者您正在使用的任何驱动程序)。皮威本身并没有任何逃逸行为。

相关问题