From 75328e947d080284c2f413fd4696e73476ba5731 Mon Sep 17 00:00:00 2001 From: Oleg Babichev Date: Fri, 26 Apr 2024 15:41:26 +0200 Subject: [PATCH] Fix review issues --- .../sql/javatime/JavaDateColumnType.kt | 9 +- .../jetbrains/exposed/DateTimeLiteralTest.kt | 115 ------------------ .../exposed/sql/jodatime/DateColumnType.kt | 3 +- 3 files changed, 5 insertions(+), 122 deletions(-) diff --git a/exposed-java-time/src/main/kotlin/org/jetbrains/exposed/sql/javatime/JavaDateColumnType.kt b/exposed-java-time/src/main/kotlin/org/jetbrains/exposed/sql/javatime/JavaDateColumnType.kt index b2678d3dbb..6ccae5c88b 100644 --- a/exposed-java-time/src/main/kotlin/org/jetbrains/exposed/sql/javatime/JavaDateColumnType.kt +++ b/exposed-java-time/src/main/kotlin/org/jetbrains/exposed/sql/javatime/JavaDateColumnType.kt @@ -249,13 +249,10 @@ class JavaLocalTimeColumnType : ColumnType(), IDateColumnType { override fun sqlType(): String = currentDialect.dataTypeProvider.timeType() override fun nonNullValueToString(value: LocalTime): String { - if (currentDialect is OracleDialect) { - return "TO_TIMESTAMP('${ORACLE_TIME_STRING_FORMATTER.format(value)}', 'YYYY-MM-DD HH24:MI:SS')" - } - if (currentDialect.h2Mode == H2Dialect.H2CompatibilityMode.Oracle) { - return "'${ORACLE_TIME_STRING_FORMATTER.format(value)}'" + val dialect = currentDialect + if (dialect is OracleDialect || dialect.h2Mode == H2Dialect.H2CompatibilityMode.Oracle) { + return "TIMESTAMP '${ORACLE_TIME_STRING_FORMATTER.format(value)}'" } - return "'${DEFAULT_TIME_STRING_FORMATTER.format(value)}'" } diff --git a/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DateTimeLiteralTest.kt b/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DateTimeLiteralTest.kt index ff1ce63bc8..7f8eee94ed 100644 --- a/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DateTimeLiteralTest.kt +++ b/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DateTimeLiteralTest.kt @@ -6,13 +6,10 @@ import org.jetbrains.exposed.sql.javatime.* import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.tests.DatabaseTestsBase import org.jetbrains.exposed.sql.tests.shared.assertEquals -import org.jetbrains.exposed.sql.update -import org.junit.Ignore import org.junit.Test import java.time.Instant import java.time.LocalDate import java.time.LocalDateTime -import java.time.LocalTime import kotlin.test.assertNotNull class DateTimeLiteralTest : DatabaseTestsBase() { @@ -31,41 +28,11 @@ class DateTimeLiteralTest : DatabaseTestsBase() { } private val defaultTimestamp = Instant.parse("2000-01-01T01:00:00.00Z") - private val futureTimestamp = Instant.parse("3000-01-01T01:00:00.00Z") object TableWithTimestamp : IntIdTable() { val timestamp = timestamp("timestamp") } - private val defaultLocalTime = LocalTime.of(1, 0, 0) - private val futureLocalTime = LocalTime.of(18, 0, 0) - - object TableWithTime : IntIdTable() { - val time = time("time") - } - - @Test - fun testInsertWithDateLiteral() { - withTables(TableWithDate) { - TableWithDate.insert { - it[date] = dateLiteral(defaultDate) - } - assertEquals(defaultDate, TableWithDate.selectAll().first()[TableWithDate.date]) - } - } - - @Test - fun testUpdateWithDateLiteral() { - withTables(TableWithDate) { - TableWithDate.insert { - it[date] = defaultDate - } - - TableWithDate.update { it[date] = dateLiteral(futureDate) } - assertEquals(futureDate, TableWithDate.selectAll().first()[TableWithDate.date]) - } - } - @Test fun testSelectByDateLiteralEquality() { withTables(TableWithDate) { @@ -89,28 +56,6 @@ class DateTimeLiteralTest : DatabaseTestsBase() { } } - @Test - fun testInsertDatetimeLiteral() { - withTables(TableWithDatetime) { - TableWithDatetime.insert { - it[datetime] = dateTimeLiteral(defaultDatetime) - } - assertEquals(defaultDatetime, TableWithDatetime.selectAll().first()[TableWithDatetime.datetime]) - } - } - - @Test - fun testUpdateWithDatetimeLiteral() { - withTables(TableWithDatetime) { - TableWithDatetime.insert { - it[datetime] = defaultDatetime - } - - TableWithDatetime.update { it[datetime] = dateTimeLiteral(futureDatetime) } - assertEquals(futureDatetime, TableWithDatetime.selectAll().first()[TableWithDatetime.datetime]) - } - } - @Test fun testSelectByDatetimeLiteralEquality() { withTables(TableWithDatetime) { @@ -134,28 +79,6 @@ class DateTimeLiteralTest : DatabaseTestsBase() { } } - @Test - fun testInsertWithTimestampLiteral() { - withTables(TableWithTimestamp) { - TableWithTimestamp.insert { - it[timestamp] = timestampLiteral(defaultTimestamp) - } - assertEquals(defaultTimestamp, TableWithTimestamp.selectAll().first()[TableWithTimestamp.timestamp]) - } - } - - @Test - fun testUpdateWithTimestampLiteral() { - withTables(TableWithTimestamp) { - TableWithTimestamp.insert { - it[timestamp] = defaultTimestamp - } - - TableWithTimestamp.update { it[timestamp] = timestampLiteral(futureTimestamp) } - assertEquals(futureTimestamp, TableWithTimestamp.selectAll().first()[TableWithTimestamp.timestamp]) - } - } - @Test fun testSelectByTimestampLiteralEquality() { withTables(TableWithTimestamp) { @@ -167,42 +90,4 @@ class DateTimeLiteralTest : DatabaseTestsBase() { assertEquals(defaultTimestamp, query.single()[TableWithTimestamp.timestamp]) } } - - @Test - fun testInsertTimeLiteral() { - withTables(TableWithTime) { - TableWithTime.insert { - it[time] = timeLiteral(defaultLocalTime) - } - assertEquals(defaultLocalTime, TableWithTime.selectAll().first()[TableWithTime.time]) - } - } - - @Test - fun testUpdateWithTimeLiteral() { - withTables(TableWithTime) { - TableWithTime.insert { - it[time] = defaultLocalTime - } - - TableWithTime.update { it[time] = timeLiteral(futureLocalTime) } - assertEquals(futureLocalTime, TableWithTime.selectAll().first()[TableWithTime.time]) - } - } - - @Test - @Ignore( - "Test fails with 'Collection is empty.' message. It can not find anything in db after insert. " + - "But SQL requests looks correct, and work well manually applied." - ) - fun testSelectByTimeLiteralEquality() { - withTables(TableWithTime) { - TableWithTime.insert { - it[time] = defaultLocalTime - } - - val query = TableWithTime.select(TableWithTime.id, TableWithTime.time).where { TableWithTime.time eq timeLiteral(defaultLocalTime) } - assertEquals(defaultLocalTime, query.single()[TableWithTime.time]) - } - } } diff --git a/exposed-jodatime/src/main/kotlin/org/jetbrains/exposed/sql/jodatime/DateColumnType.kt b/exposed-jodatime/src/main/kotlin/org/jetbrains/exposed/sql/jodatime/DateColumnType.kt index 564bdcbad1..40a465dbbc 100644 --- a/exposed-jodatime/src/main/kotlin/org/jetbrains/exposed/sql/jodatime/DateColumnType.kt +++ b/exposed-jodatime/src/main/kotlin/org/jetbrains/exposed/sql/jodatime/DateColumnType.kt @@ -174,7 +174,8 @@ class DateTimeWithTimeZoneColumnType : ColumnType(), IDateColumnType { override fun nonNullValueToString(value: DateTime): String = when (currentDialect) { is SQLiteDialect -> "'${SQLITE_AND_MYSQL_DATE_TIME_WITH_TIME_ZONE_FORMATTER.print(value)}'" is MysqlDialect -> "'${SQLITE_AND_MYSQL_DATE_TIME_WITH_TIME_ZONE_FORMATTER.print(value)}'" - is OracleDialect -> "'${ORACLE_DATE_TIME_WITH_TIME_ZONE_FORMATTER.print(value)}'" + is OracleDialect -> + "TO_TIMESTAMP_TZ('${ORACLE_DATE_TIME_WITH_TIME_ZONE_FORMATTER.print(value.toDateTime(DateTimeZone.getDefault()))}', 'YYYY-MM-DD HH24:MI:SS.FF3 TZH:TZM')" else -> "'${DEFAULT_DATE_TIME_WITH_TIME_ZONE_FORMATTER.print(value)}'" }