From fc6a40163ad226f91d8ffa9f2cbc132ae25767b2 Mon Sep 17 00:00:00 2001 From: Jocelyne Date: Tue, 28 Jan 2025 19:16:30 +0100 Subject: [PATCH] fix: Fix `isVersionCovers` to handle comparison of 8.0 with 5.6 --- exposed-core/api/exposed-core.api | 3 ++- .../src/main/kotlin/org/jetbrains/exposed/sql/Database.kt | 2 +- .../org/jetbrains/exposed/sql/vendors/MariaDBDialect.kt | 4 ++++ .../org/jetbrains/exposed/sql/vendors/MysqlDialect.kt | 7 ++----- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/exposed-core/api/exposed-core.api b/exposed-core/api/exposed-core.api index 3e58f5ce87..a5624063b6 100644 --- a/exposed-core/api/exposed-core.api +++ b/exposed-core/api/exposed-core.api @@ -4167,6 +4167,7 @@ public final class org/jetbrains/exposed/sql/vendors/MariaDBDialect : org/jetbra public fun getSupportsOnlyIdentifiersInGeneratedKeys ()Z public fun getSupportsSequenceAsGeneratedKeys ()Z public fun getSupportsSetDefaultReferenceOption ()Z + public fun isFractionDateTimeSupported ()Z } public final class org/jetbrains/exposed/sql/vendors/MariaDBDialect$Companion : org/jetbrains/exposed/sql/vendors/VendorDialect$DialectNameProvider { @@ -4186,7 +4187,7 @@ public class org/jetbrains/exposed/sql/vendors/MysqlDialect : org/jetbrains/expo public fun getSupportsSubqueryUnions ()Z public fun getSupportsTernaryAffectedRowValues ()Z public fun isAllowedAsColumnDefault (Lorg/jetbrains/exposed/sql/Expression;)Z - public final fun isFractionDateTimeSupported ()Z + public fun isFractionDateTimeSupported ()Z public final fun isTimeZoneOffsetSupported ()Z protected fun metadataMatchesTable (Ljava/lang/String;Ljava/lang/String;Lorg/jetbrains/exposed/sql/Table;)Z public fun setSchema (Lorg/jetbrains/exposed/sql/Schema;)Ljava/lang/String; diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt index 022f6c600c..6191a3fa9d 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt @@ -72,7 +72,7 @@ class Database private constructor( /** Whether the version number of the database is equal to or greater than the provided [majorVersion] and [minorVersion]. */ fun isVersionCovers(majorVersion: Int, minorVersion: Int) = - this.majorVersion >= majorVersion && this.minorVersion >= minorVersion + this.majorVersion > majorVersion || (this.majorVersion == majorVersion && this.minorVersion >= minorVersion) /** Whether the database supports ALTER TABLE with an add column clause. */ val supportsAlterTableWithAddColumn by lazy( diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/MariaDBDialect.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/MariaDBDialect.kt index 86093dad04..b9ffb597c8 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/MariaDBDialect.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/vendors/MariaDBDialect.kt @@ -78,6 +78,10 @@ class MariaDBDialect : MysqlDialect() { // actually MariaDb supports it but jdbc driver prepares statement without RETURNING clause override val supportsSequenceAsGeneratedKeys: Boolean = false + /** Returns `true` if the MariaDB database version is greater than or equal to 5.3. */ + @Suppress("MagicNumber") + override fun isFractionDateTimeSupported(): Boolean = TransactionManager.current().db.isVersionCovers(5, 3) + override fun createIndex(index: Index): String { if (index.functions != null) { exposedLogger.warn( 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 01c34fd520..1f68d21c50 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 @@ -356,12 +356,9 @@ open class MysqlDialect : VendorDialect(dialectName, MysqlDataTypeProvider, Mysq override val supportsSetDefaultReferenceOption: Boolean = false - /** Returns `true` if the database version is greater than or equal to 5.6 for MySQL, or 5.3 for MariaDB. */ + /** Returns `true` if the MySQL database version is greater than or equal to 5.6. */ @Suppress("MagicNumber") - fun isFractionDateTimeSupported(): Boolean = TransactionManager.current().db.isVersionCovers( - 5, - if (currentDialect is MariaDBDialect) 3 else 6 - ) + open fun isFractionDateTimeSupported(): Boolean = TransactionManager.current().db.isVersionCovers(5, 6) /** Returns `true` if a MySQL database is being used and its version is greater than or equal to 8.0. */ fun isTimeZoneOffsetSupported(): Boolean = (currentDialect !is MariaDBDialect) && isMysql8