Hi Adriana,

When performing dynamic SQL, you do not necessarily have to operate on
Select or SelectQuery objects. You can of course generate conditions
dynamically, as well:

Condition c = DSL.falseCondition();
if (filterByName) {

    c = c.or(NAME.eq(name));

}

if (filterByAge) {

    c = c.or(AGE.eq(age));

}


With a little more code, you can also avoid the falseCondition...

Note, there's a small subsection in the manual explaining which parts of
the jOOQ API are mutable, and which ones are immutable:
http://www.jooq.org/doc/3.1/manual/sql-building/sql-statements/dsl-and-non-dsl/#N10947

Cheers
Lukas



2013/8/29 Adriana Gomez <[email protected]>

> Hi All,
>
> I 'm trying to figure out how to solve this, and I didn't find any post
> related. Let's see if I can explain good:
>
> I have the following code:
>
> //Select count from a table
> SelectQuery query = DSL.
>
>                     selectCount().
>
>                     from(TABLE).getQuery();
>
>
> //If we need to filter by type, add an AND condition for it
> if (criteria.filterByType()) {
>
> query.addConditions(CONTACT_TYPE.in(type));
>
> }
>
> //Now, I need to add other OR conditions grouped:
> if(criteria.filterByName()){
>
> //What should I do here?
>
> }
> if(criteria.filterByAge()){
>
> //What should I do here?
>
> }
>
>
> So, I want to do something like:
> SELECT COUNT(*)
> FROM TABLE
> WHERE CONTACT_TYPE = type
> AND ( NAME = name OR AGE = age )
>
> How do I add those grouped OR conditions dynamically between ( ) ?
>
>  --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to