diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt index f1dd871e04..512a4502d2 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt @@ -148,7 +148,7 @@ open class Transaction(private val transactionImpl: TransactionInterface) : User } } - if (delta > warnLongQueriesDuration ?: Long.MAX_VALUE) { + if (delta > (warnLongQueriesDuration ?: Long.MAX_VALUE)) { exposedLogger.warn("Long query: ${describeStatement(delta, lazySQL.value)}", RuntimeException()) } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/InsertStatement.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/InsertStatement.kt index b1556eeff6..f0baaf313c 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/InsertStatement.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/InsertStatement.kt @@ -7,8 +7,12 @@ import org.jetbrains.exposed.sql.vendors.currentDialect import org.jetbrains.exposed.sql.vendors.inProperCase import java.sql.ResultSet import java.sql.SQLException +import kotlin.properties.Delegates open class InsertStatement(val table: Table, val isIgnore: Boolean = false) : UpdateBuilder(StatementType.INSERT, listOf(table)) { + + var insertedCount: Int by Delegates.notNull() + var resultedValues: List? = null private set @@ -116,6 +120,7 @@ open class InsertStatement(val table: Table, val isIgnore: Boolean = override fun PreparedStatementApi.executeInternal(transaction: Transaction): Int { val (inserted, rs) = execInsertFunction() return inserted.apply { + insertedCount = this resultedValues = processResults(rs, this) } } diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/InsertTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/InsertTests.kt index 56ecb66b97..c6c5744112 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/InsertTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/InsertTests.kt @@ -123,12 +123,22 @@ class InsertTests : DatabaseTestsBase() { val insertIgnoreSupportedDB = TestDB.values().toList() - listOf(TestDB.SQLITE, TestDB.MYSQL, TestDB.H2_MYSQL, TestDB.POSTGRESQL, TestDB.POSTGRESQLNG) + withTables(insertIgnoreSupportedDB, idTable) { - val id = idTable.insertIgnore { + val insertedStatement = idTable.insertIgnore { it[idTable.id] = EntityID(1, idTable) it[idTable.name] = "1" - } get idTable.id - assertEquals(1, id.value) + } + assertEquals(1, insertedStatement[idTable.id].value) + assertEquals(1, insertedStatement.insertedCount) + + val notInsertedStatement = idTable.insertIgnore { + it[idTable.id] = EntityID(1, idTable) + it[idTable.name] = "2" + } + + assertEquals(1, notInsertedStatement[idTable.id].value) + assertEquals(0, notInsertedStatement.insertedCount) } }