简体   繁体   English

SQLAlchemy是否清理原始SQL?

[英]Does SQLAlchemy sanitize raw SQL?

Simply put. 简单的说。 If i did something like 如果我做了类似的事情

Conn.execute(RAW_SQL) 

would sqlalchemy sanitize this to prevent sql injection or does it literally just execute it? sqlalchemy会清理这个以防止sql注入,还是只是执行它? Thanks 谢谢

No, if you pass in raw SQL with values interpolated, SQL Alchemy will not sanitise it. 不,如果使用插值的值传入原始SQL,SQL Alchemy将不会对其进行清理。 It'll just be executed. 它只会被执行。

Always use query parameters, at the very least. 始终使用查询参数,至少。

A string object is passed straight to the underlying database connection implementation; 字符串对象直接传递给底层数据库连接实现; it does support query parameters but you'll have to use the parameter style specific to the library that handles the database communication. 确实支持查询参数,但您必须使用特定于处理数据库通信的库的参数样式。

You can use sqlalchemy.sql.expression.text() to generate SQL with implementation agnostic query parameter syntax. 您可以使用sqlalchemy.sql.expression.text()生成具有实现不可知查询参数语法的SQL。

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

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