使用 postgres 和 jOOQ 的全文搜索和变量绑定不起作用
Full text search and variable binding using postgres and jOOQ not working
我正在尝试使用 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();
有什么想法吗?
谢谢,美好的一天
由于@posz 没有post他的评论作为答案,而且已经有一段时间了,为了清楚起见,我会post他自己的回复作为答案。
Try ... to_tsquery(?) ... -- the binding mark ? won't work inside a
literal.
我正在尝试使用 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();
有什么想法吗?
谢谢,美好的一天
由于@posz 没有post他的评论作为答案,而且已经有一段时间了,为了清楚起见,我会post他自己的回复作为答案。
Try ... to_tsquery(?) ... -- the binding mark ? won't work inside a literal.