Skip to content

[BUG] JSQLParser 4.7-SNAPSHOT(+4.6) PostgreSQL(+others) Enum error on ReferentialAction.Type.valueOf() when delete/update keyword is lowercase #1779

Description

@daredevil2033

Failing SQL Feature:

Parsing CreateTable statement fails if the "delete/update" keyword in outline foreign key constraint is lowercase.
Technically not supported but in practice everything except this works in either case.

SQL Example:

CREATE TABLE DATABASES
(
NAME VARCHAR(50) NOT NULL,
OWNER VARCHAR(50) NOT NULL,
PRIMARY KEY (NAME),
FOREIGN KEY(OWNER) REFERENCES USERS (USERNAME) ON delete CASCADE
);

Software Information:

  • JSqlParser version 4.6 and 4.7-SNAPSHOT
  • Database PostgreSQL (and probably most others)

Problem

CCJSqlParser.java lines 17281, 17302, 20970, 20991 in 4.7-SNAPSHOT:
fkIndex.setReferentialAction(ReferentialAction.Type.valueOf(tk.image), action);
Lines 20900 and 20921 are affected as well:
alterExp.setReferentialAction(ReferentialAction.Type.valueOf(tk.image), action);

Solution

changing tk.image to tk.image.toUpperCase() should work

Activity

  1. manticore-projects commented on May 1, 2023

    @manticore-projects
    Contributor

    Thanks, I will fix that tomorrow.

  2. manticore-projects commented on May 2, 2023

    @manticore-projects
    Contributor

    Thank you again, there were quite a number of similar problematic calls to other Enum.
    I have refactored all of them into Enum.from(...) with an implementation like:

    public static Type from(String name) {
        return Enum.valueOf(Type.class, name.toUpperCase());
    }
  3. added 2 commits that reference this issue on May 3, 2023
    fc577ca
    86d0ace
  4. added a commit that references this issue on Jun 15, 2023
    a815f5f
  5. added a commit that references this issue on Jun 27, 2023
    c79dfff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions