>> ;-) how to put this...
>> I "feel" that this kind of method would need deprecation right after
>> introduction.
>
> I agree but how much code would that be? 4-5 lines? Also, it would be easy
> to keep around (it shouldn't break future versions or keep you from changing
> other important parts of the API)
Hmm, 4-5 lines of implementation is not the problem. The problem is an
API that is tricky to maintain, because the initial requirements are
fuzzy, so far. Already, the Select.getSelect() method shouldn't be
there.
> plus it's a singular, very useful feature
> since the "turn complete query into select found" is something many apps
> need to do.
I agree, it can be useful.
OK, let's think about this more generally, then. What users often need
is a way to "patch" the projection (<select list>) of an otherwise
"stable" SELECT statement. I.e. given that...
<query specification> ::=
SELECT [ <set quantifier> ] <select list> <table expression>
<table expression> ::=
<from clause>
[ <where clause> ]
[ <group by clause> ]
[ <having clause> ]
... then, in the short run, being able to modify the <select list>
adds most immediate value.
In the long run, I would like to expose all of these syntax elements
in a "Model" with a couple of nice foreseeable properties:
- Model is a QueryPart (can render, bind)
- Model is Serializable
- Model is Cloneable (in some way)
- Model is probably mutable
- Model exposes its component Models (<select list>, <table
expression>) in two modes:
1. "as-is", i.e. in a manipulable way
2. "as-will-be-rendered", i.e. in a non-manipulable way
This is registered as #2198:
https://github.com/jOOQ/jOOQ/issues/2198
In the short run, however, short of having Cloneable models, there is
only ever one <query specification> instance to operate on. No matter
how we want to express the <select list>, e.g.
- SELECT a, b, c
- SELECT *,
- SELECT count(*),
- SELECT 1
It cannot be done without modifying the original query, which is
already possible today, actually. This works for me:
------------------------------------------------
Select<?> select =
create().select(TBook_ID(), TBook_TITLE())
.from(TBook());
System.out.println(select);
select.getSelect().add(TBook_AUTHOR_ID());
select.getSelect().remove(TBook_ID());
System.out.println(select);
------------------------------------------------
The above prints:
select "PUBLIC"."T_BOOK"."ID", "PUBLIC"."T_BOOK"."TITLE" from "PUBLIC"."T_BOOK"
select "PUBLIC"."T_BOOK"."TITLE", "PUBLIC"."T_BOOK"."AUTHOR_ID" from
"PUBLIC"."T_BOOK"
The OP's problem resides in the fact that they have provided jOOQ with
an empty <select list>:
Select<?> query = jooq.select(<empty/unknown>).from(table)....<unknown>
Unfortunately, the getSelect() method is abused for two purposes:
1. Expose the internal <select list>
2. Provide a constant <select list> derived from the <table
expression>, in case there is no internal <select list> (i.e. it is
empty)
I think, with this in mind, there is no need for further action right now?
Cheers
Lukas