Skip to content

Commit

Permalink
fix: EXPOSED-707 Handle MariaDB fractional seconds support since vers…
Browse files Browse the repository at this point in the history
…ion 5.3

According to the documentation [here](https://mariadb.com/kb/en/changes-improvements-in-mariadb-5-3/#datatypes), MariaDB introduced fractional seconds support in temporal data types from version 5.3. For MySQL, it's from version 5.6. Previously, Exposed was assuming it was 5.6 for both MariaDB and MySQL.
  • Loading branch information
joc-a committed Jan 29, 2025
1 parent e815785 commit 5945608
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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 @@ -356,10 +356,14 @@ open class MysqlDialect : VendorDialect(dialectName, MysqlDataTypeProvider, Mysq

override val supportsSetDefaultReferenceOption: Boolean = false

/** Returns `true` if the MySQL JDBC connector version is greater than or equal to 5.6. */
fun isFractionDateTimeSupported(): Boolean = TransactionManager.current().db.isVersionCovers(BigDecimal("5.6"))

/** Returns `true` if a MySQL JDBC connector is being used and its version is greater than or equal to 8.0. */
/** Returns `true` if the database version is greater than or equal to 5.6 for MySQL, or 5.3 for MariaDB. */
@Suppress("MagicNumber")
fun isFractionDateTimeSupported(): Boolean = TransactionManager.current().db.isVersionCovers(
5,
if (currentDialect is MariaDBDialect) 3 else 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

private val notAcceptableDefaults = mutableListOf("CURRENT_DATE()", "CURRENT_DATE")
Expand Down

0 comments on commit 5945608

Please sign in to comment.