简体   繁体   English

python peewee原始查询,不转义字符

[英]python peewee raw query without escaping characters

Is there any way to prevent escaping backslash in python peewee (peewee-2.8.8) ORM? 有什么方法可以防止在python peewee(peewee-2.8.8)ORM中转义反斜杠吗?

I would like to execute query in MySQL database: 我想在MySQL数据库中执行查询:

SHOW MASTER STATUS\G

The "\\G" part is essential! “ \\ G”部分必不可少! I need to the results in vertical form. 我需要以垂直形式显示结果。

The problem is that peewee always escapes backslash (\\) so it ends in MySQL as: 问题在于,peewee总是转义反斜杠(\\),因此在MySQL中以以下形式结束:

SHOW MASTER STATUS\\G

and of course MySQL issues an error: 当然,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"

I tried to use plain "execute_sql" method: 我尝试使用简单的“ execute_sql”方法:

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

and also "raw" method: 还有“原始”方法:

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

but both ended with escaping characters. 但两者都以转义字符结尾。

Have you tried using a "raw" string? 您是否尝试过使用“原始”字符串?

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

For what it's worth, whatever you pass in to .execute_sql() is essentially handed over to the MySQL driver (pymysql, or whatever you're using). 对于它的价值,您传递给.execute_sql()的所有内容实际上都将移交给MySQL驱动程序(pymysql,或您使用的任何内容)。 Peewee itself does not do any escaping. Peewee本身不会进行任何转义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM