Skip to content

Commit

Permalink
fix: EXPOSED-340 Syntax error using upsert with MySQL8 below 8.0.19 (#…
Browse files Browse the repository at this point in the history
…2049)

* fix: EXPOSED-340 Syntax error using upsert with MySQL8 below 8.0.19

MySQL `upsert()` uses an alias for the insert row values when the database
version is 8+.
Technically this is only possible starting with version 8.0.19.

Existing function `MysqlDialect.isMysql8` calls `isVersionCovers()`, which only
fetches the database's major and minor version, so it is not sufficient for
this comparison.
To get the patch version as well requires fetching metadata using the full
`databaseProductVersion` property.
  • Loading branch information
bog-walk committed Apr 17, 2024
1 parent 713ad95 commit d33deaf
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ internal open class MysqlFunctionProvider : FunctionProvider() {
}

val isAliasSupported = when (val dialect = transaction.db.dialect) {
is MysqlDialect -> dialect !is MariaDBDialect && dialect.isMysql8
is MysqlDialect -> dialect !is MariaDBDialect && dialect.fullVersion >= "8.0.19"
else -> false // H2_MySQL mode also uses this function provider & requires older version
}

Expand Down Expand Up @@ -281,6 +281,10 @@ open class MysqlDialect : VendorDialect(dialectName, MysqlDataTypeProvider, Mysq
TransactionManager.current().db.isVersionCovers(BigDecimal("8.0"))
}

internal val fullVersion: String by lazy {
TransactionManager.current().db.metadata { databaseProductVersion }
}

override val supportsCreateSequence: Boolean = false

override val supportsTernaryAffectedRowValues: Boolean = true
Expand Down

0 comments on commit d33deaf

Please sign in to comment.