Rails find_by_sql 像转义%
我正在尝试执行 find_by_sql 语句,其中涉及带有 LIKE 运算符的 SELECT 语句。为了简洁起见,我们假设语句是“SQL * FROM posts where lower(name) LIKE '%hello%'”
看起来rails抛出了一个关于“%是格式错误的字符串”的异常。我尝试使用“SQL * FROM posts where lower(name) LIKE '\%hello\%'”来转义 sql 语句,
但仍然显示相同的错误消息。有什么想法吗?
I am trying to execute a find_by_sql statement which involves a SELECT statement with a LIKE operator. For sake of brevity, let's assume the statement is "SQL * FROM posts where lower(name) LIKE '%hello%'"
Seems like rails throws an exception about "% being a malformed format string". I have tried to escape the sql statement using "SQL * FROM posts where lower(name) LIKE '\%hello\%'"
Still the same error message shows up. Any ideas ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论