X Tutup
The Wayback Machine - https://web.archive.org/web/20201011183121/https://github.com/JSQLParser/JSqlParser/issues/1060
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect index type for indices parsed from create table statement #1060

Open
reboot opened this issue Oct 2, 2020 · 0 comments
Open

Incorrect index type for indices parsed from create table statement #1060

reboot opened this issue Oct 2, 2020 · 0 comments

Comments

@reboot
Copy link

@reboot reboot commented Oct 2, 2020

I notice that the parser seems to create incorrect index types from create table statements when multiple constraints are defined. The index type then depends on the order of constraints. For example:

CREATE TABLE EXAMPLE (
  ...
  CONSTRAINT EXAMPLE_UK UNIQUE (COLUMN1, COLUMN2)
  CONSTRAINT EXAMPLEPK PRIMARY KEY (ID),
)

The index EXAMPLE_UK will have the type UNIQUE and EXAMPLEPK will have the type PRIMARY KEY. But if you change the order of statemets like this

CREATE TABLE EXAMPLE (
  ...
  CONSTRAINT EXAMPLEPK PRIMARY KEY (ID),
  CONSTRAINT EXAMPLE_UK UNIQUE (COLUMN1, COLUMN2)
)

then EXAMPLEPK will have the type PRIMARY KEY and EXAMPLE_UK will have the type UNIQUE KEY.

I believe this is caused by the parsing of the unique key tokens. The KEY-Keyword is optional for UNIQUE constraints, but the token variable is never cleared.

In JSqlParser:4099 the code

                    (tk=<K_PRIMARY> tk2=<K_KEY> {index.setType(tk.image + " " + tk2.image);}
                     | tk=<K_UNIQUE> [ tk2=<K_KEY> ] {index.setType(tk.image + (tk2!=null?" " + tk2.image:""));}

is adding the tk2.image to the index type, if it is not null. But if a primary key has been parsed before the unique constraint, then tk2 still contains the old token and is added the index type.

@reboot reboot changed the title Incorrect index yype for indices parsed from create table statement Incorrect index type for indices parsed from create table statement Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.
X Tutup