From ac243ce503689f9e07e7598f455252c6071c9c73 Mon Sep 17 00:00:00 2001 From: "Na, Hyunik" Date: Tue, 30 Apr 2024 17:43:43 +0900 Subject: [PATCH 1/4] truncate milli-seconds when converting DATETIME to TIMESTAMP in server side JDBC --- .../src/main/java/com/cubrid/jsp/value/DatetimeValue.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DatetimeValue.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DatetimeValue.java index 5f24abc632c..71f0bfacd57 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DatetimeValue.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DatetimeValue.java @@ -83,7 +83,8 @@ public Time toTime() throws TypeMismatchException { } public Timestamp toTimestamp() throws TypeMismatchException { - return timestamp; + long sec = timestamp.getTime() / 1000L; // truncate milli-seconds + return new Timestamp(sec * 1000L); } public Timestamp toDatetime() throws TypeMismatchException { From 4a692745d84e7abfed34558497a643dc5c13fb01 Mon Sep 17 00:00:00 2001 From: "Na, Hyunik" Date: Thu, 2 May 2024 14:38:10 +0900 Subject: [PATCH 2/4] differentiated toDatetime() and toTimestamp() calls and added several assertions --- .../src/main/java/com/cubrid/jsp/StoredProcedure.java | 4 +--- .../src/main/java/com/cubrid/jsp/impl/SUStatement.java | 2 +- .../src/main/java/com/cubrid/jsp/value/DateValue.java | 3 ++- .../src/main/java/com/cubrid/jsp/value/DatetimeValue.java | 6 +++--- .../src/main/java/com/cubrid/jsp/value/TimeValue.java | 1 + 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java index e14f485a731..172afc2bda8 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java @@ -85,9 +85,7 @@ public Object[] getResolved() { return resolved; } - public void setArgs() {} - - public void checkArgs() throws TypeMismatchException { + private void checkArgs() throws TypeMismatchException { Class[] argsTypes = target.getArgsTypes(); if (argsTypes.length != args.length) { throw new TypeMismatchException( diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUStatement.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUStatement.java index 49f0dfbe9d7..a49e7e95b84 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUStatement.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUStatement.java @@ -604,7 +604,7 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException { if (obj == null) return null; try { - return obj.toTimestamp(); + return obj.toDatetime(); // toTimestamp() truncates non-zero millisecond value } catch (TypeMismatchException e) { return null; } diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DateValue.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DateValue.java index 48d28996d56..af2810ef705 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DateValue.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DateValue.java @@ -61,6 +61,7 @@ public DateValue(int year, int mon, int day, int mode, int dbType) { public DateValue(Date date) { this.date = date; + assert date.getTime() % 1000L == 0; // millisecond value must be zero } public Date toDate() throws TypeMismatchException { @@ -100,7 +101,7 @@ public Timestamp[] toTimestampArray() throws TypeMismatchException { } public Timestamp[] toDatetimeArray() throws TypeMismatchException { - return new Timestamp[] {toTimestamp()}; + return new Timestamp[] {toDatetime()}; } public Object[] toObjectArray() throws TypeMismatchException { diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DatetimeValue.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DatetimeValue.java index 71f0bfacd57..77835dd853d 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DatetimeValue.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/DatetimeValue.java @@ -92,7 +92,7 @@ public Timestamp toDatetime() throws TypeMismatchException { } public Object toDefault() throws TypeMismatchException { - return toTimestamp(); + return timestamp; } public String toString() { @@ -112,7 +112,7 @@ public Timestamp[] toTimestampArray() throws TypeMismatchException { } public Timestamp[] toDatetimeArray() throws TypeMismatchException { - return new Timestamp[] {toTimestamp()}; + return new Timestamp[] {toDatetime()}; } public Object[] toObjectArray() throws TypeMismatchException { @@ -124,6 +124,6 @@ public String[] toStringArray() throws TypeMismatchException { } public Object toObject() throws TypeMismatchException { - return toTimestamp(); + return timestamp; } } diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/TimeValue.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/TimeValue.java index be75606b74a..386269b290d 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/TimeValue.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/TimeValue.java @@ -61,6 +61,7 @@ public TimeValue(int hour, int min, int sec, int mode, int dbType) { public TimeValue(Time time) { this.time = time; + assert time.getTime() % 1000L == 0; } public Date toDate() throws TypeMismatchException { From c64142e7081f215a4876ec434096d000f67593a3 Mon Sep 17 00:00:00 2001 From: "Na, Hyunik" Date: Thu, 2 May 2024 15:28:07 +0900 Subject: [PATCH 3/4] use toDatetime() for arguments to DATETIME type parameters so as not to apply millisecond truncation --- .../main/java/com/cubrid/jsp/StoredProcedure.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java index 172afc2bda8..1788091af8e 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java @@ -31,6 +31,7 @@ package com.cubrid.jsp; +import com.cubrid.jsp.data.DBType; import com.cubrid.jsp.context.ContextManager; import com.cubrid.jsp.exception.ExecuteException; import com.cubrid.jsp.exception.TypeMismatchException; @@ -126,7 +127,11 @@ private void checkArgs() throws TypeMismatchException { resolved = args[i].toTime(); } else if (argsTypes[i] == Timestamp.class) { - resolved = args[i].toTimestamp(); + if (args[i].getDbType() == DBType.DB_DATETIME) { + resolved = args[i].toDatetime(); + } else { + resolved = args[i].toTimestamp(); + } } else if (argsTypes[i] == BigDecimal.class) { resolved = args[i].toBigDecimal(); @@ -183,7 +188,11 @@ private void checkArgs() throws TypeMismatchException { resolved = args[i].toTimeArray(); } else if (argsTypes[i] == Timestamp[].class) { - resolved = args[i].toTimestampArray(); + if (args[i].getDbType() == DBType.DB_DATETIME) { + resolved = args[i].toDatetimeArray(); + } else { + resolved = args[i].toTimestampArray(); + } } else if (argsTypes[i] == BigDecimal[].class) { resolved = args[i].toBigDecimalArray(); From 965d9df992d4a35295fd58b8777cb198da063e77 Mon Sep 17 00:00:00 2001 From: "Na, Hyunik" Date: Thu, 2 May 2024 15:29:55 +0900 Subject: [PATCH 4/4] code style --- .../pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java | 2 +- .../src/main/java/com/cubrid/jsp/impl/SUStatement.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java index 1788091af8e..3d50e1b5e0a 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/StoredProcedure.java @@ -31,8 +31,8 @@ package com.cubrid.jsp; -import com.cubrid.jsp.data.DBType; import com.cubrid.jsp.context.ContextManager; +import com.cubrid.jsp.data.DBType; import com.cubrid.jsp.exception.ExecuteException; import com.cubrid.jsp.exception.TypeMismatchException; import com.cubrid.jsp.value.BooleanValue; diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUStatement.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUStatement.java index a49e7e95b84..f9b72381a42 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUStatement.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUStatement.java @@ -604,7 +604,7 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException { if (obj == null) return null; try { - return obj.toDatetime(); // toTimestamp() truncates non-zero millisecond value + return obj.toDatetime(); // toTimestamp() truncates non-zero millisecond value } catch (TypeMismatchException e) { return null; }