Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I wrap brackets around parameter values when using jOOq?

I am using jOOq to write queries except I am using a vendor specific type of SQL... to be specific flexible search. The main difference between SQL and flexiSearch is that parameter values are enclosed in a curly bracket. e.g.

SELECT * FROM {Product} WHERE {code} LIKE ‘%al%’

So what I'm trying to do is to get jOOq to automatically intercept the query building procedure to include the brackets.

Looking through the docs, it seems that I should implement some kind of execute listener? But I am not sure what to do after that. Thanks

like image 601
user1272052 Avatar asked Jul 16 '26 05:07

user1272052


1 Answers

You could indeed implement an ExecuteListener that replaces

  • every odd " by a { and every even " by a } using any dialect (be careful of syntactic ambiguities)
  • every odd ` by a { and every even ` by a } using MySQL dialect
  • every [ by a { and every ] by a } using SQL Server dialect

But from what I can tell, that won't be the only thing you'll be patching in generated SQL, so you might as well fork the jOOQ Open Source Edition and patch the relevant code yourself.

Beware, jOOQ doesn't really support this particular dialect. This will not be the only thing you'll run into. For example, you could try to pattern match subqueries in an ExecuteListener and wrap them in {{ ... }}, but that, too, would be much easier to achieve by patching jOOQ directly.

like image 154
Lukas Eder Avatar answered Jul 18 '26 19:07

Lukas Eder