全文搜索和变量绑定使用postgres和jOOQ不起作用
问题描述:
我想在使用jOOQ的postgres数据库中进行全文搜索。下面这行工作:全文搜索和变量绑定使用postgres和jOOQ不起作用
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没有张贴作为回答他的评论,它已经相当长一段时间,我会后他自己为清楚起见回复作为答案。
尝试... to_tsquery(?)... - 绑定标记?将不会在 文字内工作。
尝试'... to_tsquery(?)...' - 绑定标记'?'在文字中不起作用。 – pozs
啊谢谢,就是这样。这样一个简单的修复。 –
@pozs:你应该从中创建一个答案! –