使用CFQUERYPARAM在SQL中指定表/列名
我需要动态构造一组 JOIN 语句,其中表名和列名是从另一个 ColdFusion 查询传入的。 将字符串值传递到语句中时,CFQUERYPARAM 在其周围添加单引号 - 这是 CFQUERYPARAM 要点的一部分。 鉴于这会破坏 SQL 语句,在这种情况下不使用 CFQUERYPARAM 而是确保传入的查询被清理是否可以接受,或者是否有办法允许使用 CFQUERYPARAM? (我可以使用 Fusebox 中的电路/熔丝权限锁定这些代码。)
谢谢。
I need to dynamically construct a set of JOIN statements where the table and column names are passed in from another ColdFusion query. When passing the string values to into the statement, CFQUERYPARAM adds single quotes around it - that's part of the point of CFQUERYPARAM. Given that this breaks the SQL statement, is it acceptable not to use CFQUERYPARAM in this case and instead ensure that the incoming query is cleansed, or is there a way round which allows CFQUERYPARAM to be used? (I can lock down these pieces of code using circuit/fuse permissions in Fusebox.)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
cfqueryparam
不添加单引号 - 它使用绑定变量。我立即对“动态构造一组 JOIN 语句”这一说法表示怀疑 - 听起来如果您动态加入,您不一定会正确地做事。
但是,对于表/列名称,一旦您确实完全清理 - 如果
cfqueryparam
不起作用并且您需要 cf 变量 - 那么是 ,可以直接使用CF变量。注意:为了安全地进行清理,您可以使用
rereplacenocase(table_name,'[^a-z_]','','all')
删除除 az 和下划线之外的所有内容。cfqueryparam
does not add single quotes - it uses bind variables.I am instantly suspicious of the statement "dynamically construct a set of JOIN statements" - it doesn't sound like you're necessarily doing things properly if you're dynamically joining.
However, for table/column names, once you are definitely sanitizing fully - if
cfqueryparam
doesn't work and you need cf variables - then yes, you can use CF variables directly.Note: To sanitize safely, you can use
rereplacenocase(table_name,'[^a-z_]','','all')
to remove everything other than a-z and underscore.您可以使用其中两个来转义单引号。 您还可以使用preserveSingleQuotes 函数。
You can escape the single quotes by using two of them. You can also use the preserveSingleQuotes function.