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

Identification of PRIMARY KEY depends on order #337

Open
Gared opened this issue Apr 26, 2021 · 2 comments
Open

Identification of PRIMARY KEY depends on order #337

Gared opened this issue Apr 26, 2021 · 2 comments

Comments

@Gared
Copy link

Gared commented Apr 26, 2021

Hey, first of all thanks for providing this extremely useful library.
Unfortunately I have noticed this weird behaviour.

If i want to get the primary key of this sql statement:

CREATE TABLE IF NOT EXISTS `testabc` (
    `from` INT UNSIGNED NOT NULL,
    `to` INT UNSIGNED NOT NULL,
    INDEX `index_cccrange_from` (`from` ASC),
    INDEX `index_to` (`to` ASC),
    PRIMARY KEY (`from`, `to`)
);

This will return 3 indexes, but no primary key.

If I change the order to this statement it all works fine:

CREATE TABLE IF NOT EXISTS `testabc` (
    `from` INT UNSIGNED NOT NULL,
    `to` INT UNSIGNED NOT NULL,
    PRIMARY KEY (`from`, `to`),
    INDEX `index_cccrange_from` (`from` ASC),
    INDEX `index_to` (`to` ASC)
);

I don't know exactly why but the difference seems to be that when it is not working $prevCategory is "INDEX_COL_LIST" in

if ($prevCategory === '' || $prevCategory === 'CONSTRAINT') {
.
In the second (working) case $prevCategory is just an empty string.

@greenlion
Copy link
Owner

Probably just needs || $prevCategory == INDEX_COL_LIST - will take a look as soon as I can.

@xsist10
Copy link
Contributor

xsist10 commented Nov 30, 2023

I just encountered this bug myself. I created a quick tests to demonstrate it: https://gist.github.com/xsist10/9502ce318dc39ff25c24940f1378767c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants