Hello 2017-11-29 12:21 GMT+01:00 <[email protected]>:
> Also works fine for some reason, even though the mock returns a record > containing a state-field? Maybe I'm doing something wrong or have the wrong > expectations about how mocking works, but it looks like the > fetchOne-function doesn't care about the field name? > The fetchOne() method doesn't influence how the query is executed in any way, it simply specifies how the result should be processed, once it is available (i.e. it fetches at most one record and in your case, only one column from that record). So, the interesting part is the select() clause, which tells jOOQ that the query expects exactly one column of a given type. Now that the row type is known to jOOQ (and jOOQ expects JDBC drivers to produce something reasonable, and this includes your MockDataProvider), jOOQ doesn't have to rely on any column name but can access the result values by index - which is much faster in most JDBC drivers. If you didn't provide any columns in the select() clause and the from() clause also didn't provide the entirety of all columns (e.g. because there is plain SQL involved), then jOOQ would detect reported column names from the JDBC driver through ResultSetMetaData. > Like I said, the test can prove that the query itself is written wrong > (selecting state but fetching id), but it can't prove that you aren't > trying to correctly access a completely different column (selecting and > fetching id-column when mock returns state-column). > You got the "wrong" part wrong. The query isn't written wrong. It's just that your MockDataProvider will always return that particular 1x1 result and since jOOQ already knows the resulting rowtype in advance (you provided it), it doesn't check ResultSetMetaData for what the *actual* column names and types might be. I hope this helps, Lukas -- 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/d/optout.
