Hi Ben,

What comes to mind here would be

1. A VisitListener that replaces a top-level Field QueryPart in the
Clause.SELECT clause when some condition is matched. An example can be seen
here:
http://www.jooq.org/doc/latest/manual/sql-building/queryparts/custom-sql-transformation/transformation-bind-value-abbreviation/
2. An ExecuteListener that patches generated SQL using a regex. This might
be more difficult (not possible) to get right, generally.
3. Your solution works fine, too, of course.

Cheers
Lukas



2014-02-18 12:12 GMT+01:00 Ben Hood <[email protected]>:

> On Tue, Feb 18, 2014 at 10:37 AM, Ben Hood <[email protected]> wrote:
> > I forgot to mention that one of the ways you could emulate this is to
> > programmatically patch the fields from the object in this example
> > called ranked and then supply the patched list back to the fluent API:
> >
> > List<Field> patched = patchRanked(ranked); // custom function to patch a
> list
> >
> > ctx.select(patched).from(ranked).where(RANK.le(10));
> >
> > In this light, having some kind of lambda support would make this code
> > less verbose, but the main value add is that you could factor this in
> > Java as well.
>
> So I ended up hacking up something like this:
>
> ctx.select(patch(ranked.fields(),
> EXCEL_FIELD)).from(ranked).where(RANK.le(n));
>
> static Field[] patch(Field[] fields, Field ... fieldsToPatch) {
>
>     LinkedHashMap<String, Field> patched = new LinkedHashMap<String,
> Field>();
>
>     for (Field field : fields) {
>       patched.put(field.getName(), field);
>     }
>
>     for (Field patchField : fieldsToPatch) {
>       Field original = patched.get(patchField.getName());
>       patched.put(patchField.getName(),
> DSL.field("concat('=\"',{0},'\"')", String.class,
> original).as(patchField.getName()));
>     }
>
>     return patched.values().toArray(new Field[]{});
> }
>
> Not quite sure whether it's such a good idea though.
>
> --
> 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