Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

CreateTableTest 单元测试报错 #15

Description

@fengsmith

建表语句报错了:

CREATE TABLE IF NOT EXISTS mytable
(
    f2  IDENTITY(1, 10)
        CONSTRAINT pk PRIMARY KEY HASH AUTO_INCREMENT,
    f5  int NOT NULL UNIQUE NOT NULL,
    f6  int NULL CHECK f6 > 10,
    f7  int
        CONSTRAINT c8 NOT NULL REFERENCES mytable (f2) ON DELETE CASCADE,
    f99 int
)

报错信息:

Exception in thread "main" org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS MYTABLE (F2 IDENTITY(1, 10) CONSTRAINT PK PRIMARY KEY HASH AUTO_INCREMENT[*], F5 INT NOT NULL UNIQUE NOT NULL, F6 INT NULL CHECK F6>10, F7 INT CONSTRAINT C8 NOT NULL REFERENCES MYTABLE(F2) ON DELETE CASCADE, F99 INT)"; expected "CONSTRAINT, COMMENT, UNIQUE, NOT, NULL, CHECK, REFERENCES, ., )"; SQL statement:
CREATE TABLE IF NOT EXISTS mytable (f2 IDENTITY(1, 10) CONSTRAINT pk PRIMARY KEY HASH AUTO_INCREMENT, f5 int NOT NULL UNIQUE NOT NULL, f6 int NULL CHECK f6>10, f7 int CONSTRAINT c8 NOT NULL REFERENCES mytable(f2) ON DELETE CASCADE, f99 int) [42001-201]

解析完 AUTO_INCREMENT 之后就报错了,根据 debug 发现第 11668 行后

                if (column.getIdentityOptions() != null || !parseCompatibilityIdentity(column, mode)) {
                    return;
                }

由于 column.getIdentityOptions() != null 为真,导致 parseCompatibilityIdentity(column, mode) 没有执行,从而没有解析下一个 token ‘,’ ,等到处理下一次循环,读取更多的时候

    private boolean readIfMore() {
        if (readIf(COMMA)) {
            return true;
        }
        read(CLOSE_PAREN);
        return false;
    }

尝试读取 逗号 失败,下次读取比括号的时候就报错了。好像是 h2 的一个 bug 。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions