Skip to content

Commit

Permalink
fix: Fix isVersionCovers to handle comparison of 8.0 with 5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
joc-a committed Jan 29, 2025
1 parent b477cc2 commit fc6a401
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion exposed-core/api/exposed-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc6a401

Please sign in to comment.