From 0439932d938b4a913e0b2bf74013faf9355826d1 Mon Sep 17 00:00:00 2001 From: Chantal Loncle <82039410+bog-walk@users.noreply.github.com> Date: Fri, 23 Feb 2024 09:17:11 -0500 Subject: [PATCH] feat: EXPOSED-258 Enhance upsert to allow exclusion of columns set on conflict - Change order of private batchInsert() vararg parameter - Change onExcludeUpdate parameter to be a List instead of Set --- .../Writerside/topics/Deep-Dive-into-DSL.md | 4 +-- exposed-core/api/exposed-core.api | 26 +++++++++---------- .../org/jetbrains/exposed/sql/Queries.kt | 24 ++++++++--------- .../sql/statements/BatchUpsertStatement.kt | 4 +-- .../exposed/sql/statements/UpsertStatement.kt | 4 +-- .../exposed/sql/vendors/FunctionProvider.kt | 8 +++--- .../exposed/sql/vendors/MysqlDialect.kt | 2 +- .../exposed/sql/vendors/OracleDialect.kt | 2 +- .../exposed/sql/vendors/PostgreSQL.kt | 2 +- .../exposed/sql/vendors/SQLServerDialect.kt | 2 +- .../exposed/sql/vendors/SQLiteDialect.kt | 2 +- .../sql/tests/shared/dml/UpsertTests.kt | 2 +- 12 files changed, 41 insertions(+), 41 deletions(-) diff --git a/documentation-website/Writerside/topics/Deep-Dive-into-DSL.md b/documentation-website/Writerside/topics/Deep-Dive-into-DSL.md index 93f41adf33..b85accd6e9 100644 --- a/documentation-website/Writerside/topics/Deep-Dive-into-DSL.md +++ b/documentation-website/Writerside/topics/Deep-Dive-into-DSL.md @@ -668,7 +668,7 @@ then `onUpdateExclude` should be provided an argument with the specific columns This parameter could also be used for the reverse case when only a small subset of columns should be updated but duplicating the insert values is tedious: ```kotlin // on conflict, all columns EXCEPT [director] are updated with values from the lambda block -StarWarsFilms.upsert(onUpdateExclude = setOf(StarWarsFilms.director)) { +StarWarsFilms.upsert(onUpdateExclude = listOf(StarWarsFilms.director)) { it[sequelId] = 9 it[name] = "The Rise of Skywalker" it[director] = "JJ Abrams" @@ -676,7 +676,7 @@ StarWarsFilms.upsert(onUpdateExclude = setOf(StarWarsFilms.director)) { // on conflict, ONLY column [director] is updated with value from the lambda block StarWarsFilms.upsert( - onUpdateExclude = StarWarsFilms.columns.toSet() - StarWarsFilms.director + onUpdateExclude = StarWarsFilms.columns - setOf(StarWarsFilms.director) ) { it[sequelId] = 9 it[name] = "The Rise of Skywalker" diff --git a/exposed-core/api/exposed-core.api b/exposed-core/api/exposed-core.api index 2aec6431cf..eae323069d 100644 --- a/exposed-core/api/exposed-core.api +++ b/exposed-core/api/exposed-core.api @@ -1615,10 +1615,10 @@ public final class org/jetbrains/exposed/sql/QueriesKt { public static final fun batchReplace (Lorg/jetbrains/exposed/sql/Table;Lkotlin/sequences/Sequence;ZLkotlin/jvm/functions/Function2;)Ljava/util/List; public static synthetic fun batchReplace$default (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljava/util/List; public static synthetic fun batchReplace$default (Lorg/jetbrains/exposed/sql/Table;Lkotlin/sequences/Sequence;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljava/util/List; - public static final fun batchUpsert (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/Set;ZLkotlin/jvm/functions/Function2;)Ljava/util/List; - public static final fun batchUpsert (Lorg/jetbrains/exposed/sql/Table;Lkotlin/sequences/Sequence;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/Set;ZLkotlin/jvm/functions/Function2;)Ljava/util/List; - public static synthetic fun batchUpsert$default (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/Set;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljava/util/List; - public static synthetic fun batchUpsert$default (Lorg/jetbrains/exposed/sql/Table;Lkotlin/sequences/Sequence;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/Set;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljava/util/List; + public static final fun batchUpsert (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;ZLkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun batchUpsert (Lorg/jetbrains/exposed/sql/Table;Lkotlin/sequences/Sequence;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;ZLkotlin/jvm/functions/Function2;)Ljava/util/List; + public static synthetic fun batchUpsert$default (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljava/util/List; + public static synthetic fun batchUpsert$default (Lorg/jetbrains/exposed/sql/Table;Lkotlin/sequences/Sequence;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljava/util/List; public static final fun deleteAll (Lorg/jetbrains/exposed/sql/Table;)I public static final fun deleteIgnoreWhere (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;)I public static synthetic fun deleteIgnoreWhere$default (Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)I @@ -1651,8 +1651,8 @@ public final class org/jetbrains/exposed/sql/QueriesKt { public static final fun update (Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;)I public static synthetic fun update$default (Lorg/jetbrains/exposed/sql/Join;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)I public static synthetic fun update$default (Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)I - public static final fun upsert (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/Set;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/exposed/sql/statements/UpsertStatement; - public static synthetic fun upsert$default (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/Set;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/statements/UpsertStatement; + public static final fun upsert (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/exposed/sql/statements/UpsertStatement; + public static synthetic fun upsert$default (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/statements/UpsertStatement; } public class org/jetbrains/exposed/sql/Query : org/jetbrains/exposed/sql/AbstractQuery { @@ -2807,11 +2807,11 @@ public class org/jetbrains/exposed/sql/statements/BatchUpdateStatement : org/jet } public class org/jetbrains/exposed/sql/statements/BatchUpsertStatement : org/jetbrains/exposed/sql/statements/BaseBatchInsertStatement { - public fun (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/Set;Z)V - public synthetic fun (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/Set;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;Z)V + public synthetic fun (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun getKeys ()[Lorg/jetbrains/exposed/sql/Column; public final fun getOnUpdate ()Ljava/util/List; - public final fun getOnUpdateExclude ()Ljava/util/Set; + public final fun getOnUpdateExclude ()Ljava/util/List; public fun prepareSQL (Lorg/jetbrains/exposed/sql/Transaction;Z)Ljava/lang/String; } @@ -3034,12 +3034,12 @@ public class org/jetbrains/exposed/sql/statements/UpdateStatement : org/jetbrain } public class org/jetbrains/exposed/sql/statements/UpsertStatement : org/jetbrains/exposed/sql/statements/InsertStatement { - public fun (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/Set;Lorg/jetbrains/exposed/sql/Op;)V + public fun (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;Ljava/util/List;Ljava/util/List;Lorg/jetbrains/exposed/sql/Op;)V public synthetic fun arguments ()Ljava/lang/Iterable; public fun arguments ()Ljava/util/List; public final fun getKeys ()[Lorg/jetbrains/exposed/sql/Column; public final fun getOnUpdate ()Ljava/util/List; - public final fun getOnUpdateExclude ()Ljava/util/Set; + public final fun getOnUpdateExclude ()Ljava/util/List; public final fun getWhere ()Lorg/jetbrains/exposed/sql/Op; public fun prepareSQL (Lorg/jetbrains/exposed/sql/Transaction;Z)Ljava/lang/String; } @@ -3525,7 +3525,7 @@ public abstract class org/jetbrains/exposed/sql/vendors/FunctionProvider { public fun delete (ZLorg/jetbrains/exposed/sql/Table;Ljava/lang/String;Ljava/lang/Integer;Lorg/jetbrains/exposed/sql/Transaction;)Ljava/lang/String; public fun getDEFAULT_VALUE_EXPRESSION ()Ljava/lang/String; protected final fun getKeyColumnsForUpsert (Lorg/jetbrains/exposed/sql/Table;[Lorg/jetbrains/exposed/sql/Column;)Ljava/util/List; - protected final fun getUpdateColumnsForUpsert (Ljava/util/List;Ljava/util/Set;Ljava/util/List;)Ljava/util/List; + protected final fun getUpdateColumnsForUpsert (Ljava/util/List;Ljava/util/List;Ljava/util/List;)Ljava/util/List; public fun groupConcat (Lorg/jetbrains/exposed/sql/GroupConcat;Lorg/jetbrains/exposed/sql/QueryBuilder;)V public fun hour (Lorg/jetbrains/exposed/sql/Expression;Lorg/jetbrains/exposed/sql/QueryBuilder;)V public fun insert (ZLorg/jetbrains/exposed/sql/Table;Ljava/util/List;Ljava/lang/String;Lorg/jetbrains/exposed/sql/Transaction;)Ljava/lang/String; @@ -3550,7 +3550,7 @@ public abstract class org/jetbrains/exposed/sql/vendors/FunctionProvider { public static synthetic fun substring$default (Lorg/jetbrains/exposed/sql/vendors/FunctionProvider;Lorg/jetbrains/exposed/sql/Expression;Lorg/jetbrains/exposed/sql/Expression;Lorg/jetbrains/exposed/sql/Expression;Lorg/jetbrains/exposed/sql/QueryBuilder;Ljava/lang/String;ILjava/lang/Object;)V public fun update (Lorg/jetbrains/exposed/sql/Join;Ljava/util/List;Ljava/lang/Integer;Lorg/jetbrains/exposed/sql/Op;Lorg/jetbrains/exposed/sql/Transaction;)Ljava/lang/String; public fun update (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Ljava/lang/Integer;Lorg/jetbrains/exposed/sql/Op;Lorg/jetbrains/exposed/sql/Transaction;)Ljava/lang/String; - public fun upsert (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Ljava/util/List;Ljava/util/Set;Lorg/jetbrains/exposed/sql/Op;Lorg/jetbrains/exposed/sql/Transaction;[Lorg/jetbrains/exposed/sql/Column;)Ljava/lang/String; + public fun upsert (Lorg/jetbrains/exposed/sql/Table;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lorg/jetbrains/exposed/sql/Op;Lorg/jetbrains/exposed/sql/Transaction;[Lorg/jetbrains/exposed/sql/Column;)Ljava/lang/String; public fun varPop (Lorg/jetbrains/exposed/sql/Expression;Lorg/jetbrains/exposed/sql/QueryBuilder;)V public fun varSamp (Lorg/jetbrains/exposed/sql/Expression;Lorg/jetbrains/exposed/sql/QueryBuilder;)V public fun year (Lorg/jetbrains/exposed/sql/Expression;Lorg/jetbrains/exposed/sql/QueryBuilder;)V diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Queries.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Queries.kt index e96a446543..8b4a277d87 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Queries.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Queries.kt @@ -418,7 +418,7 @@ fun Join.update(where: (SqlExpressionBuilder.() -> Op)? = null, limit: * If no columns are provided, primary keys will be used. If the table does not have any primary keys, the first unique index will be attempted. * @param onUpdate List of pairs of specific columns to update and the expressions to update them with. * If left null, all columns will be updated with the values provided for the insert. - * @param onUpdateExclude Set of specific columns to exclude from updating. + * @param onUpdateExclude List of specific columns to exclude from updating. * If left null, all columns will be updated with the values provided for the insert. * @param where Condition that determines which rows to update, if a unique violation is found. * @sample org.jetbrains.exposed.sql.tests.shared.dml.UpsertTests.testUpsertWithUniqueIndexConflict @@ -426,7 +426,7 @@ fun Join.update(where: (SqlExpressionBuilder.() -> Op)? = null, limit: fun T.upsert( vararg keys: Column<*>, onUpdate: List, Expression<*>>>? = null, - onUpdateExclude: Set>? = null, + onUpdateExclude: List>? = null, where: (SqlExpressionBuilder.() -> Op)? = null, body: T.(UpsertStatement) -> Unit ) = UpsertStatement(this, *keys, onUpdate = onUpdate, onUpdateExclude = onUpdateExclude, where = where?.let { SqlExpressionBuilder.it() }).apply { @@ -445,7 +445,7 @@ fun T.upsert( * primary keys will be used. If the table does not have any primary keys, the first unique index will be attempted. * @param onUpdate List of pairs of specific columns to update and the expressions to update them with. * If left null, all columns will be updated with the values provided for the insert. - * @param onUpdateExclude Set of specific columns to exclude from updating. + * @param onUpdateExclude List of specific columns to exclude from updating. * If left null, all columns will be updated with the values provided for the insert. * @param shouldReturnGeneratedValues Specifies whether newly generated values (for example, auto-incremented IDs) should be returned. * See [Batch Insert](https://github.com/JetBrains/Exposed/wiki/DSL#batch-insert) for more details. @@ -455,11 +455,11 @@ fun T.batchUpsert( data: Iterable, vararg keys: Column<*>, onUpdate: List, Expression<*>>>? = null, - onUpdateExclude: Set>? = null, + onUpdateExclude: List>? = null, shouldReturnGeneratedValues: Boolean = true, body: BatchUpsertStatement.(E) -> Unit ): List { - return batchUpsert(data.iterator(), onUpdate, onUpdateExclude, shouldReturnGeneratedValues, body, keys = keys) + return batchUpsert(data.iterator(), onUpdate, onUpdateExclude, shouldReturnGeneratedValues, keys = keys, body = body) } /** @@ -473,7 +473,7 @@ fun T.batchUpsert( * primary keys will be used. If the table does not have any primary keys, the first unique index will be attempted. * @param onUpdate List of pairs of specific columns to update and the expressions to update them with. * If left null, all columns will be updated with the values provided for the insert. - * @param onUpdateExclude Set of specific columns to exclude from updating. + * @param onUpdateExclude List of specific columns to exclude from updating. * If left null, all columns will be updated with the values provided for the insert. * @param shouldReturnGeneratedValues Specifies whether newly generated values (for example, auto-incremented IDs) should be returned. * See [Batch Insert](https://github.com/JetBrains/Exposed/wiki/DSL#batch-insert) for more details. @@ -483,11 +483,11 @@ fun T.batchUpsert( data: Sequence, vararg keys: Column<*>, onUpdate: List, Expression<*>>>? = null, - onUpdateExclude: Set>? = null, + onUpdateExclude: List>? = null, shouldReturnGeneratedValues: Boolean = true, body: BatchUpsertStatement.(E) -> Unit ): List { - return batchUpsert(data.iterator(), onUpdate, onUpdateExclude, shouldReturnGeneratedValues, body, keys = keys) + return batchUpsert(data.iterator(), onUpdate, onUpdateExclude, shouldReturnGeneratedValues, keys = keys, body = body) } /** @@ -501,7 +501,7 @@ fun T.batchUpsert( * primary keys will be used. If the table does not have any primary keys, the first unique index will be attempted. * @param onUpdate List of pairs of specific columns to update and the expressions to update them with. * If left null, all columns will be updated with the values provided for the insert. - * @param onUpdateExclude Set of specific columns to exclude from updating. + * @param onUpdateExclude List of specific columns to exclude from updating. * If left null, all columns will be updated with the values provided for the insert. * @param shouldReturnGeneratedValues Specifies whether newly generated values (for example, auto-incremented IDs) should be returned. * See [Batch Insert](https://github.com/JetBrains/Exposed/wiki/DSL#batch-insert) for more details. @@ -510,10 +510,10 @@ fun T.batchUpsert( private fun T.batchUpsert( data: Iterator, onUpdate: List, Expression<*>>>? = null, - onUpdateExclude: Set>? = null, + onUpdateExclude: List>? = null, shouldReturnGeneratedValues: Boolean = true, - body: BatchUpsertStatement.(E) -> Unit, - vararg keys: Column<*> + vararg keys: Column<*>, + body: BatchUpsertStatement.(E) -> Unit ): List = executeBatch(data, body) { BatchUpsertStatement(this, *keys, onUpdate = onUpdate, onUpdateExclude = onUpdateExclude, shouldReturnGeneratedValues = shouldReturnGeneratedValues) } diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/BatchUpsertStatement.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/BatchUpsertStatement.kt index 1904660c8e..4d82570dab 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/BatchUpsertStatement.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/BatchUpsertStatement.kt @@ -19,7 +19,7 @@ import org.jetbrains.exposed.sql.vendors.MysqlFunctionProvider * primary keys will be used. If the table does not have any primary keys, the first unique index will be attempted. * @param onUpdate List of pairs of specific columns to update and the expressions to update them with. * If left null, all columns will be updated with the values provided for the insert. - * @param onUpdateExclude Set of specific columns to exclude from updating. + * @param onUpdateExclude List of specific columns to exclude from updating. * If left null, all columns will be updated with the values provided for the insert. * @param shouldReturnGeneratedValues Specifies whether newly generated values (for example, auto-incremented IDs) should be returned. * See [Batch Insert](https://github.com/JetBrains/Exposed/wiki/DSL#batch-insert) for more details. @@ -28,7 +28,7 @@ open class BatchUpsertStatement( table: Table, vararg val keys: Column<*>, val onUpdate: List, Expression<*>>>?, - val onUpdateExclude: Set>?, + val onUpdateExclude: List>?, shouldReturnGeneratedValues: Boolean = true ) : BaseBatchInsertStatement(table, ignore = false, shouldReturnGeneratedValues) { diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpsertStatement.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpsertStatement.kt index 877525e3f6..92a28a068e 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpsertStatement.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/UpsertStatement.kt @@ -11,7 +11,7 @@ import org.jetbrains.exposed.sql.vendors.* * primary keys will be used. If the table does not have any primary keys, the first unique index will be attempted. * @param onUpdate List of pairs of specific columns to update and the expressions to update them with. * If left null, all columns will be updated with the values provided for the insert. - * @param onUpdateExclude Set of specific columns to exclude from updating. + * @param onUpdateExclude List of specific columns to exclude from updating. * If left null, all columns will be updated with the values provided for the insert. * @param where Condition that determines which rows to update, if a unique violation is found. This clause may not be supported by all vendors. */ @@ -19,7 +19,7 @@ open class UpsertStatement( table: Table, vararg val keys: Column<*>, val onUpdate: List, Expression<*>>>?, - val onUpdateExclude: Set>?, + val onUpdateExclude: List>?, val where: Op? ) : InsertStatement(table) { diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/FunctionProvider.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/FunctionProvider.kt index 86c92e3ad1..c300394f9a 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/FunctionProvider.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/FunctionProvider.kt @@ -534,7 +534,7 @@ abstract class FunctionProvider { * @param table Table to either insert values into or update values from. * @param data Pairs of columns to use for insert or update and values to insert or update. * @param onUpdate List of pairs of specific columns to update and the expressions to update them with. - * @param onUpdateExclude Set of specific columns to exclude from updating. + * @param onUpdateExclude List of specific columns to exclude from updating. * @param where Condition that determines which rows to update, if a unique violation is found. * @param transaction Transaction where the operation is executed. */ @@ -542,7 +542,7 @@ abstract class FunctionProvider { table: Table, data: List, Any?>>, onUpdate: List, Expression<*>>>?, - onUpdateExclude: Set>?, + onUpdateExclude: List>?, where: Op?, transaction: Transaction, vararg keys: Column<*> @@ -611,10 +611,10 @@ abstract class FunctionProvider { /** Returns the columns to be used in the update clause of an upsert statement. */ protected fun getUpdateColumnsForUpsert( dataColumns: List>, - toExclude: Set>?, + toExclude: List>?, keyColumns: List>? ): List> { - val updateColumns = toExclude?.let { dataColumns - it } ?: dataColumns + val updateColumns = toExclude?.let { dataColumns - it.toSet() } ?: dataColumns return keyColumns?.let { keys -> updateColumns.filter { it !in keys }.ifEmpty { updateColumns } } ?: updateColumns diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/MysqlDialect.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/MysqlDialect.kt index 6015c6eef7..b018811f26 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/MysqlDialect.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/MysqlDialect.kt @@ -230,7 +230,7 @@ internal open class MysqlFunctionProvider : FunctionProvider() { table: Table, data: List, Any?>>, onUpdate: List, Expression<*>>>?, - onUpdateExclude: Set>?, + onUpdateExclude: List>?, where: Op?, transaction: Transaction, vararg keys: Column<*> diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/OracleDialect.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/OracleDialect.kt index 8ff3f33d89..5f56a4e33e 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/OracleDialect.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/OracleDialect.kt @@ -266,7 +266,7 @@ internal object OracleFunctionProvider : FunctionProvider() { table: Table, data: List, Any?>>, onUpdate: List, Expression<*>>>?, - onUpdateExclude: Set>?, + onUpdateExclude: List>?, where: Op?, transaction: Transaction, vararg keys: Column<*> diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/PostgreSQL.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/PostgreSQL.kt index 9216e4915f..bee5325120 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/PostgreSQL.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/PostgreSQL.kt @@ -262,7 +262,7 @@ internal object PostgreSQLFunctionProvider : FunctionProvider() { table: Table, data: List, Any?>>, onUpdate: List, Expression<*>>>?, - onUpdateExclude: Set>?, + onUpdateExclude: List>?, where: Op?, transaction: Transaction, vararg keys: Column<*> diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLServerDialect.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLServerDialect.kt index b64abf57a5..6cc09d52bc 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLServerDialect.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLServerDialect.kt @@ -216,7 +216,7 @@ internal object SQLServerFunctionProvider : FunctionProvider() { table: Table, data: List, Any?>>, onUpdate: List, Expression<*>>>?, - onUpdateExclude: Set>?, + onUpdateExclude: List>?, where: Op?, transaction: Transaction, vararg keys: Column<*> diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLiteDialect.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLiteDialect.kt index 1ad1c40551..e244b7d883 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLiteDialect.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/SQLiteDialect.kt @@ -201,7 +201,7 @@ internal object SQLiteFunctionProvider : FunctionProvider() { table: Table, data: List, Any?>>, onUpdate: List, Expression<*>>>?, - onUpdateExclude: Set>?, + onUpdateExclude: List>?, where: Op?, transaction: Transaction, vararg keys: Column<*> diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/UpsertTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/UpsertTests.kt index 8e2072896c..abd30c14c5 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/UpsertTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/UpsertTests.kt @@ -388,7 +388,7 @@ class UpsertTests : DatabaseTestsBase() { rollback() } - tester.upsert(onUpdateExclude = setOf(tester.code, tester.gains)) { + tester.upsert(onUpdateExclude = listOf(tester.code, tester.gains)) { it[item] = itemA it[gains] = 200 it[losses] = 0