【问题标题】:Full text search and variable binding using postgres and jOOQ not working使用 postgres 和 jOOQ 的全文搜索和变量绑定不起作用
【发布时间】:2016-10-15 03:54:50
【问题描述】:

我正在尝试使用 jOOQ 在 postgres 数据库中进行全文搜索。以下行有效:

Result res = pgContext.select()
                      .from(products.PRODUCTS)
                      .where("to_tsvector(title || ' ' || description || ' ' || tags) @@ to_tsquery('" + query + "')")
                      .fetch();

但是当我添加变量绑定以防止 SQL 注入时,我不再得到结果:

Result res = pgContext.select()
                      .from(products.PRODUCTS)
                      .where("to_tsvector(title || ' ' || description || ' ' || tags) @@ to_tsquery('?')", query)
                      .fetch();

有什么想法吗?

谢谢你,美好的一天

【问题讨论】:

  • 试试... to_tsquery(?) ...——绑定标记?在文字中不起作用。
  • 谢谢,就是这样。如此简单的修复。
  • @pozs:你应该从中创建一个答案!

标签: java sql postgresql jooq


【解决方案1】:

由于@posz 没有发布他的评论作为答案,而且已经有一段时间了,为了清楚起见,我将自己发布他的回复作为答案。

尝试 ... to_tsquery(?) ... -- 绑定标记?不会在里面工作 字面意思。

【讨论】:

    猜你喜欢
    • 2017-03-31
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多