有没有办法防止在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_sql”方法:
cursor = RaDatabase.execute_sql('SHOW MASTER STATUS\G')
还有“原始”方法:
query = BaseModel.raw('SHOW MASTER STATUS\G')
result = query.execute()
但两人都以逃避角色结束。
你尝试过使用“原始”字符串吗?
cursor = RaDatabase.execute_sql(r'SHOW MASTER STATUS\G')
对于它的价值,无论你传入.execute_sql()的是什么,基本上都是移交给MySQL驱动程序(pymysql,或者你正在使用的任何东西)。 Peewee本身并没有做任何逃避。