Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPOSED-707 Handle MariaDB fractional seconds support since version 5.3 #2378

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions exposed-core/api/exposed-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -4169,7 +4169,7 @@ public final class org/jetbrains/exposed/sql/vendors/KeywordsKt {
public static final fun getVENDORS_KEYWORDS ()Ljava/util/Map;
}

public final class org/jetbrains/exposed/sql/vendors/MariaDBDialect : org/jetbrains/exposed/sql/vendors/MysqlDialect {
public class org/jetbrains/exposed/sql/vendors/MariaDBDialect : org/jetbrains/exposed/sql/vendors/MysqlDialect {
public static final field Companion Lorg/jetbrains/exposed/sql/vendors/MariaDBDialect$Companion;
public fun <init> ()V
public fun createIndex (Lorg/jetbrains/exposed/sql/Index;)Ljava/lang/String;
Expand All @@ -4179,6 +4179,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 @@ -4198,7 +4199,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 @@ -66,7 +66,7 @@ internal object MariaDBFunctionProvider : MysqlFunctionProvider() {
/**
* MariaDB dialect implementation.
*/
class MariaDBDialect : MysqlDialect() {
open class MariaDBDialect : MysqlDialect() {
override val name: String = dialectName
override val functionProvider: FunctionProvider = MariaDBFunctionProvider
override val supportsOnlyIdentifiersInGeneratedKeys: Boolean = true
Expand All @@ -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,10 +356,11 @@ 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 the MySQL database version is greater than or equal to 5.6. */
@Suppress("MagicNumber")
open fun isFractionDateTimeSupported(): Boolean = TransactionManager.current().db.isVersionCovers(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 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
Loading