gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 17:01:40 25 4
gpt4 key购买 nike

有什么方法可以防止在 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')

就其值(value)而言,您传递给 .execute_sql() 的任何内容本质上都会移交给 MySQL 驱动程序(pymysql 或您正在使用的任何内容)。 Peewee 本身不进行任何转义。

关于python peewee 原始查询,不转义字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52183057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com