Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] jdbc: fix date/time parameters binding
@ 2018-10-10 11:48 Sergei Kalashnikov
  2018-10-29 17:19 ` [tarantool-patches] " Alexander Turenko
  0 siblings, 1 reply; 2+ messages in thread
From: Sergei Kalashnikov @ 2018-10-10 11:48 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Sergei Kalashnikov

Fixed exception when packing date/time parameters of prepared statement.
Added test for parameter binding methods.

Closes #43
---
https://github.com/tarantool/tarantool-java/issues/43
https://github.com/ztarvos/tarantool-java/commits/gh-43-fix-jdbc-datetime-param

 .../java/org/tarantool/jdbc/SQLMsgPackLite.java    |  6 +-
 .../tarantool/jdbc/JdbcPreparedStatementIT.java    | 66 ++++++++++++++++++++++
 2 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/tarantool/jdbc/SQLMsgPackLite.java b/src/main/java/org/tarantool/jdbc/SQLMsgPackLite.java
index 0f73efb..1506877 100644
--- a/src/main/java/org/tarantool/jdbc/SQLMsgPackLite.java
+++ b/src/main/java/org/tarantool/jdbc/SQLMsgPackLite.java
@@ -17,11 +17,11 @@ public class SQLMsgPackLite extends MsgPackLite {
     public void pack(Object item, OutputStream os) throws IOException {
         if(item instanceof Date) {
             super.pack(((Date)item).getTime(), os);
-        } if(item instanceof Time) {
+        } else if(item instanceof Time) {
             super.pack(((Time)item).getTime(), os);
-        } if(item instanceof Timestamp) {
+        } else if(item instanceof Timestamp) {
             super.pack(((Timestamp)item).getTime(), os);
-        } if(item instanceof BigDecimal) {
+        } else if(item instanceof BigDecimal) {
             super.pack(((BigDecimal)item).toPlainString(), os);
         } else {
             super.pack(item, os);
diff --git a/src/test/java/org/tarantool/jdbc/JdbcPreparedStatementIT.java b/src/test/java/org/tarantool/jdbc/JdbcPreparedStatementIT.java
index f356f6b..68628ef 100644
--- a/src/test/java/org/tarantool/jdbc/JdbcPreparedStatementIT.java
+++ b/src/test/java/org/tarantool/jdbc/JdbcPreparedStatementIT.java
@@ -3,9 +3,13 @@ package org.tarantool.jdbc;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.AfterEach;
 
+import java.math.BigDecimal;
+import java.sql.Date;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -64,4 +68,66 @@ public class JdbcPreparedStatementIT extends AbstractJdbcIT {
 
         assertEquals("thousand", getRow("test", 1000).get(1));
     }
+
+    @Test
+    public void testSetParameter() throws SQLException {
+        prep = conn.prepareStatement("INSERT INTO test_types VALUES (" +
+                "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+        assertNotNull(prep);
+
+        prep.setInt(1, 1000);//INT
+        prep.setString(2, (String)testRow[1]);//CHAR
+        prep.setString(3, (String)testRow[2]);//VARCHAR
+        prep.setString(4, (String)testRow[3]);//LONGVARCHAR
+        prep.setBigDecimal(5, (BigDecimal)testRow[4]);//NUMERIC
+        prep.setBigDecimal(6, (BigDecimal)testRow[5]);//DECIMAL
+        prep.setBoolean(7, (Boolean)testRow[6]);//BIT
+        prep.setByte(8, (Byte)testRow[7]);//TINYINT
+        prep.setShort(9, (Short)testRow[8]);//SMALLINT
+        prep.setInt(10, (Integer)testRow[9]);//INTEGER
+        prep.setLong(11, (Long)testRow[10]);//BIGINT
+        prep.setFloat(12, (Float)testRow[11]);//REAL
+        prep.setDouble(13, (Double)testRow[12]);//FLOAT
+        prep.setBytes(14, (byte[])testRow[13]);//BINARY
+        prep.setBytes(15, (byte[])testRow[14]);//VARBINARY
+        prep.setBytes(16, (byte[])testRow[15]);//LONGVARBINARY
+        prep.setDate(17, (Date)testRow[16]);//DATE
+        prep.setTime(18, (Time)testRow[17]);//TIME
+        prep.setTimestamp(19, (Timestamp)testRow[18]);//TIMESTAMP
+
+        int count = prep.executeUpdate();
+        assertEquals(1, count);
+
+        prep.close();
+
+        prep = conn.prepareStatement("SELECT * FROM test_types WHERE f1 = ?");
+        prep.setInt(1, 1000);
+
+        ResultSet rs = prep.executeQuery();
+        assertNotNull(rs);
+
+        assertTrue(rs.next());
+        assertEquals(1000, rs.getInt(1));//INT
+        assertEquals(testRow[1], rs.getString(2));//CHAR
+        assertEquals(testRow[2], rs.getString(3));//VARCHAR
+        assertEquals(testRow[3], rs.getString(4)); //LONGVARCHAR
+        assertEquals(testRow[4], rs.getBigDecimal(5));//NUMERIC
+        assertEquals(testRow[5], rs.getBigDecimal(6));//DECIMAL
+        assertEquals(testRow[6], rs.getBoolean(7));//BIT
+        assertEquals(testRow[7], rs.getByte(8));//TINYINT
+        assertEquals(testRow[8], rs.getShort(9));//SMALLINT
+        assertEquals(testRow[9], rs.getInt(10));//INTEGER
+        assertEquals(testRow[10], rs.getLong(11));//BIGINT
+        assertEquals((Float)testRow[11], rs.getFloat(12), 1e-10f);//REAL
+        assertEquals((Double)testRow[12], rs.getDouble(13), 1e-10d);//FLOAT
+        //Issue#45
+        //assertTrue(Arrays.equals((byte[])testRow[13], rs.getBytes(14)));//BINARY
+        //assertTrue(Arrays.equals((byte[])testRow[14], rs.getBytes(15)));//VARBINARY
+        //assertTrue(Arrays.equals((byte[])testRow[15], rs.getBytes(16)));//LONGVARBINARY
+        assertEquals(testRow[16], rs.getDate(17));//DATE
+        assertEquals(testRow[17], rs.getTime(18));//TIME
+        assertEquals(testRow[18], rs.getTimestamp(19));//TIMESTAMP
+
+        rs.close();
+    }
 }
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [tarantool-patches] Re: [PATCH] jdbc: fix date/time parameters binding
  2018-10-10 11:48 [tarantool-patches] [PATCH] jdbc: fix date/time parameters binding Sergei Kalashnikov
@ 2018-10-29 17:19 ` Alexander Turenko
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Turenko @ 2018-10-29 17:19 UTC (permalink / raw)
  To: Sergei Kalashnikov; +Cc: tarantool-patches

Pushed to connector-1.8.jdbc.

WBR, Alexander Turenko.

On Wed, Oct 10, 2018 at 02:48:20PM +0300, Sergei Kalashnikov wrote:
> Fixed exception when packing date/time parameters of prepared statement.
> Added test for parameter binding methods.
> 
> Closes #43
> ---
> https://github.com/tarantool/tarantool-java/issues/43
> https://github.com/ztarvos/tarantool-java/commits/gh-43-fix-jdbc-datetime-param

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-29 17:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-10 11:48 [tarantool-patches] [PATCH] jdbc: fix date/time parameters binding Sergei Kalashnikov
2018-10-29 17:19 ` [tarantool-patches] " Alexander Turenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox