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

Irregular order of operands in generated CHECK constraint #920

Closed
Ktlo opened this issue May 21, 2020 · 1 comment
Closed

Irregular order of operands in generated CHECK constraint #920

Ktlo opened this issue May 21, 2020 · 1 comment
Labels

Comments

@Ktlo
Copy link

Ktlo commented May 21, 2020

The small example below causes an error

object AccessTable : IntIdTable() {
    val user = integer("user").nullable()
    val group = integer("group").nullable()

    init {
        check { user.isNotNull() neq group.isNotNull() }
    }
}

fun main() {
    Database.connect("jdbc:h2:mem:regular")
    transaction {
        SchemaUtils.create(AccessTable)
        AccessTable.insert {
            it[user] = 23
            it[group] = null
        }
    }
}

It can be seen from the log output that the following statement was used to create the table.

CREATE TABLE IF NOT EXISTS ACCESS (ID INT AUTO_INCREMENT PRIMARY KEY, "USER" INT NULL, "GROUP" INT NULL, CONSTRAINT check_Access_0 CHECK ("USER" IS NOT NULL <> "GROUP" IS NOT NULL))

On insert the folowing exception was thrown.

Exception in thread "main" org.jetbrains.exposed.exceptions.ExposedSQLException: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Нарушение ограничения: "CHECK_ACCESS_0: (((USER IS NOT NULL) <> ""GROUP"") IS NOT NULL)"
Check constraint violation: "CHECK_ACCESS_0: (((USER IS NOT NULL) <> ""GROUP"") IS NOT NULL)"; SQL statement:
INSERT INTO ACCESS ("GROUP", "USER") VALUES (?, ?) [23513-200]
SQL: [INSERT INTO Access ("GROUP", "USER") VALUES (?, ?)]

It seems that the order of the operands was not checked when creating the table.

@Tapac
Copy link
Contributor

Tapac commented Jun 12, 2020

Should be fixed in the next release.

@Tapac Tapac closed this as completed Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants