How to create jOOQ quote table names that are reserved keywords?

When choosing from a table with a name userwith jOOQ, I get the following exception:

jOOQ; bad SQL grammar [insert into user (user_id, account_type) values (?, ?)]; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near "user"

My jOOQ settings:

private static final Settings jooqSettings = new Settings()
    .withRenderSchema(false)
    .withRenderNameStyle(RenderNameStyle.LOWER);

I create from it DSLContextand create a request in a transaction as follows:

ctx.insertInto(USER)
      .set(USER.USER_ID, userId)
      .set(USER.ACCOUNT_TYPE, "U")
      .execute()

userimported as <jooq-generated-package>.tables.USER.

Does jOOQ have a config property to delete table names (all or just reserved keywords)? I could not find anything in the documents or source.

+4
source share
1 answer

Well, you turned it off by installing RenderNameStyle.LOWER... The way it works :)

RenderNameStyle.QUOTED, jOOQ .

:

<simpleType name="RenderNameStyle">
  <restriction base="string">
    <!--
     Render object names quoted, as defined in the database. Use this
     to stay on the safe side with case-sensitivity and special
     characters. For instance:
     Oracle    : "SYS"."ALL_TAB_COLS"
     MySQL     : `information_schema`.`TABLES`
     SQL Server: [INFORMATION_SCHEMA].[TABLES] 
     -->
    <enumeration value="QUOTED"/>

    <!--
     Render object names, as defined in the database. For instance:
     Oracle    : SYS.ALL_TAB_COLS
     MySQL     : information_schema.TABLES
     SQL Server: INFORMATION_SCHEMA.TABLES 
     -->
    <enumeration value="AS_IS"/>

    <!--
     Force rendering object names in lower case. For instance:
     Oracle    : sys.all_tab_cols
     MySQL     : information_schema.tables
     SQL Server: information_schema.tables 
     -->
    <enumeration value="LOWER"/>

    <!--
     Force rendering object names in upper case. For instance:
     Oracle    : SYS.ALL_TAB_COLS
     MySQL     : INFORMATION_SCHEMA.TABLES
     SQL Server: INFORMATION_SCHEMA.TABLES 
     -->
    <enumeration value="UPPER"/>
  </restriction>
</simpleType>

, Javadoc (# 2830) (# 5231)

+2

Source: https://habr.com/ru/post/1670740/


All Articles