Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot set quote stye in JOOQ (RenderNameStyle.QUOTED)

Tags:

java

jooq

I'd like to get JOOQ to render column names with quotes. This is what I tried, reading the docs and StackOverflow:

    DSLContext sql = DSL.using( SQLDialect.SQL99, 
            new Settings()
                .withRenderNameStyle(RenderNameStyle.QUOTED)
                .withRenderFormatted(true)
                .withRenderKeywordStyle(RenderKeywordStyle.UPPER)
        );

    System.out.println( "Quoted: " + (sql.settings().getRenderNameStyle()==RenderNameStyle.QUOTED) );

    Table<Record> table = table("MyTable");
    Field<Long> lid = field("id",Long.class);

    String sqlStr = sql.renderInlined(
            sql.select( lid, field("type"), field("request.id"), field("UPPERCASE"), field("lowercase") )
            .from(table)
            .limit(1000) 
        );

    System.out.println(sqlStr);

The generated statement is:

SELECT 
   id, 
   type, 
   request.id, 
   UPPERCASE, 
   lowercase
FROM MyTable
LIMIT 1000

It outputs Quoted: true, so the flag seems to be set. While renderFormatted and renderKeywordStyle seem to be respected, `renderNameStyle`` appears to be ignored.

I'm experimenting with an unsupported database, therefore the SQL99. Side question: Why is SQL99 deprecated in JOOQ?

like image 989
DCS Avatar asked Sep 30 '22 07:09

DCS


1 Answers

The DSL.field(String) methods are used to embed "plain SQL" into jOOQ. jOOQ doesn't parse your SQL strings, and thus doesn't know which parts you considered to be "names", such as type, or request and id.

If you don't want to use the code generator, you should use DSL.field(Name) to create fields whose names is affected by the RenderNameStyle setting. Name can be created using DSL.name(String...)

I'm experimenting with an unsupported database, therefore the SQL99. Side question: Why is SQL99 deprecated in JOOQ?

Because the name is misleading. jOOQ isn't really generating SQL99 as there are no integration tests verifying that the output is really correct or meaningful according to the standard. In a future version of jOOQ, SQL99 will be replaced by a DEFAULT dialect, which probably won't work on any database.

like image 98
Lukas Eder Avatar answered Oct 30 '22 22:10

Lukas Eder