This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 8b9a1abb09e Add support for LocalDate conversion in ResultSetUtils 
(#37388)
8b9a1abb09e is described below

commit 8b9a1abb09e085695774071399be9fb2854dc1e2
Author: Cong Hu <[email protected]>
AuthorDate: Tue Dec 16 09:12:26 2025 +0800

    Add support for LocalDate conversion in ResultSetUtils (#37388)
---
 .../query/impl/driver/jdbc/type/util/ResultSetUtils.java | 16 ++++++++++++++++
 .../jdbc/core/resultset/ShardingSphereResultSetTest.java | 15 +++++++++++++++
 2 files changed, 31 insertions(+)

diff --git 
a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtils.java
 
b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtils.java
index 971ca6bc4c0..f572a20f2c9 100644
--- 
a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtils.java
+++ 
b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtils.java
@@ -64,6 +64,9 @@ public final class ResultSetUtils {
         if (value instanceof LocalDateTime) {
             return convertLocalDateTimeValue((LocalDateTime) value, 
convertType);
         }
+        if (value instanceof LocalDate) {
+            return convertLocalDateValue((LocalDate) value, convertType);
+        }
         if (value instanceof Timestamp) {
             return convertTimestampValue((Timestamp) value, convertType);
         }
@@ -123,6 +126,19 @@ public final class ResultSetUtils {
         return value;
     }
     
+    private static Object convertLocalDateValue(final LocalDate value, final 
Class<?> convertType) {
+        if (java.sql.Date.class.equals(convertType)) {
+            return java.sql.Date.valueOf(value);
+        }
+        if (Timestamp.class.equals(convertType)) {
+            return Timestamp.valueOf(value.atStartOfDay());
+        }
+        if (String.class.equals(convertType)) {
+            return value.toString();
+        }
+        return value;
+    }
+    
     private static Object convertTimestampValue(final Timestamp value, final 
Class<?> convertType) {
         if (LocalDateTime.class.equals(convertType)) {
             return 
value.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
diff --git 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
index 4ec2dcbbed8..354b4e63925 100644
--- 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
+++ 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
@@ -44,6 +44,7 @@ import java.sql.SQLException;
 import java.sql.SQLXML;
 import java.sql.Time;
 import java.sql.Timestamp;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.OffsetDateTime;
 import java.util.Calendar;
@@ -271,6 +272,13 @@ class ShardingSphereResultSetTest {
         assertThat(shardingSphereResultSet.getDate(1), is(new Date(0L)));
     }
     
+    @Test
+    void assertGetDateConvertedByLocalDateWithColumnIndex() throws 
SQLException {
+        LocalDate localDate = LocalDate.now();
+        when(mergeResultSet.getValue(1, Date.class)).thenReturn(localDate);
+        assertThat(shardingSphereResultSet.getDate(1), 
is(Date.valueOf(localDate)));
+    }
+    
     @Test
     void assertGetDateWithColumnLabel() throws SQLException {
         when(mergeResultSet.getValue(1, Date.class)).thenReturn(new Date(0L));
@@ -323,6 +331,13 @@ class ShardingSphereResultSetTest {
         assertThat(shardingSphereResultSet.getTimestamp(1), is(new 
Timestamp(0L)));
     }
     
+    @Test
+    void assertGetTimestampConvertedByLocalDateWithColumnIndex() throws 
SQLException {
+        LocalDate localDate = LocalDate.now();
+        when(mergeResultSet.getValue(1, 
Timestamp.class)).thenReturn(localDate);
+        assertThat(shardingSphereResultSet.getTimestamp(1), 
is(Timestamp.valueOf(localDate.atStartOfDay())));
+    }
+    
     @Test
     void assertGetTimestampWithColumnLabel() throws SQLException {
         when(mergeResultSet.getValue(1, Timestamp.class)).thenReturn(new 
Timestamp(0L));

Reply via email to