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

BatchUpdateStatement expects set(..) calls in alphabetical order and fails when given more than 2 batches #388

Closed
jon-mey opened this issue Sep 12, 2018 · 1 comment
Assignees
Labels

Comments

@jon-mey
Copy link

jon-mey commented Sep 12, 2018

BatchUpdateStatement produces wrong SQL when the set(..) calls are not in alphabetical order for columns:

object Test : IntIdTable() {
    val a = integer("a")
    val b = float("b")
    val c = text("c")
}

...

transaction {
    addLogger(StdOutSqlLogger)

    BatchUpdateStatement(Test).apply {
        listOf(1).forEach {
            addBatch(EntityID(it, Test))
            this[Test.c] = "3"
            this[Test.a] = 1
            this[Test.b] = 2.0f

        }
    }.execute(this)
}

This produces:
SQL: UPDATE TEST SET C=1, A=2.0, B='3' WHERE ID = 1

If the order is changed like this it works correctly:

transaction {
    addLogger(StdOutSqlLogger)

    BatchUpdateStatement(Test).apply {
        listOf(1).forEach {
            addBatch(EntityID(it, Test))
            this[Test.a] = 1
            this[Test.b] = 2.0f
            this[Test.c] = "3"
        }
    }.execute(this)
}
@jon-mey
Copy link
Author

jon-mey commented Sep 12, 2018

It also fails if you add more than 2 batches to the statement:

transaction {
    addLogger(StdOutSqlLogger)

    BatchUpdateStatement(Test).apply {
        listOf(1, 2, 3).forEach {
            addBatch(EntityID(it, Test))
            this[Test.a] = 1
            this[Test.b] = 2.0f
            this[Test.c] = "3"
        }
    }.execute(this)
}

org.jetbrains.exposed.sql.statements.BatchDataInconsistentException: Some values missing for batch update. Different columns: [Test.a, Test.b, Test.c]

Looking at the source code:

val different by lazy {  data.first().second.keys.intersect(lastBatch!!.second.keys) }

This will make 'different' contain all keys on the third iteration.

@jon-mey jon-mey changed the title BatchUpdateStatement expects set(..) calls in alphabetical order BatchUpdateStatement expects set(..) calls in alphabetical order and fails when given more than 2 batches Sep 12, 2018
@Tapac Tapac self-assigned this Sep 12, 2018
@Tapac Tapac added the bug label Sep 12, 2018
Tapac added a commit that referenced this issue Sep 12, 2018
@Tapac Tapac closed this as completed Sep 12, 2018
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