You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2021/05/24 07:03:43 UTC
[iotdb] branch master updated: Support JDBC placeholder when set
sensor or device by set string (#3249)
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new b303d33 Support JDBC placeholder when set sensor or device by set string (#3249)
b303d33 is described below
commit b303d332efc0f74aaf28293a6186dd42bce72419
Author: yanhong wang <67...@users.noreply.github.com>
AuthorDate: Mon May 24 15:03:12 2021 +0800
Support JDBC placeholder when set sensor or device by set string (#3249)
---
.../apache/iotdb/jdbc/IoTDBPreparedStatement.java | 2 +-
.../iotdb/jdbc/IoTDBPreparedStatementTest.java | 42 +++++++++++++++++++---
2 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java
index 786a975..ea8c2b7 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java
@@ -408,7 +408,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement implements PreparedSt
@Override
public void setString(int parameterIndex, String x) {
- this.parameters.put(parameterIndex, "'" + x.replace("'", "\\'") + "'");
+ this.parameters.put(parameterIndex, x);
}
@Override
diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java
index 559f2dc..ee57d35 100644
--- a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java
+++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java
@@ -183,12 +183,12 @@ public class IoTDBPreparedStatementTest {
@SuppressWarnings("resource")
@Test
- public void oneStringArgument() throws Exception {
+ public void oneStringArgument1() throws Exception {
String sql =
"SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < ? and time > 2017-11-1 0:13:00";
IoTDBPreparedStatement ps =
new IoTDBPreparedStatement(connection, client, sessionId, sql, zoneId);
- ps.setString(1, "abcde");
+ ps.setString(1, "'abcde'");
ps.execute();
ArgumentCaptor<TSExecuteStatementReq> argument =
ArgumentCaptor.forClass(TSExecuteStatementReq.class);
@@ -200,6 +200,38 @@ public class IoTDBPreparedStatementTest {
@SuppressWarnings("resource")
@Test
+ public void oneStringArgument2() throws Exception {
+ String sql =
+ "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < ? and time > 2017-11-1 0:13:00";
+ IoTDBPreparedStatement ps =
+ new IoTDBPreparedStatement(connection, client, sessionId, sql, zoneId);
+ ps.setString(1, "\"abcde\"");
+ ps.execute();
+ ArgumentCaptor<TSExecuteStatementReq> argument =
+ ArgumentCaptor.forClass(TSExecuteStatementReq.class);
+ verify(client).executeStatement(argument.capture());
+ assertEquals(
+ "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < \"abcde\" and time > 2017-11-1 0:13:00",
+ argument.getValue().getStatement());
+ }
+
+ @SuppressWarnings("resource")
+ @Test
+ public void oneStringArgument3() throws Exception {
+ String sql = "SELECT status, ? FROM root.ln.wf01.wt01";
+ IoTDBPreparedStatement ps =
+ new IoTDBPreparedStatement(connection, client, sessionId, sql, zoneId);
+ ps.setString(1, "temperature");
+ ps.execute();
+ ArgumentCaptor<TSExecuteStatementReq> argument =
+ ArgumentCaptor.forClass(TSExecuteStatementReq.class);
+ verify(client).executeStatement(argument.capture());
+ assertEquals(
+ "SELECT status, temperature FROM root.ln.wf01.wt01", argument.getValue().getStatement());
+ }
+
+ @SuppressWarnings("resource")
+ @Test
public void oneTimeLongArgument() throws Exception {
String sql = "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE time > ?";
IoTDBPreparedStatement ps =
@@ -280,7 +312,7 @@ public class IoTDBPreparedStatementTest {
ps.setLong(4, 123234345);
ps.setFloat(5, 123.423f);
ps.setDouble(6, -1323.0);
- ps.setString(7, "abc");
+ ps.setString(7, "'abc'");
ps.execute();
ArgumentCaptor<TSExecuteStatementReq> argument =
@@ -304,14 +336,14 @@ public class IoTDBPreparedStatementTest {
ps.setLong(4, 123234345);
ps.setFloat(5, 123.423f);
ps.setDouble(6, -1323.0);
- ps.setString(7, "abc");
+ ps.setString(7, "\"abc\"");
ps.execute();
ArgumentCaptor<TSExecuteStatementReq> argument =
ArgumentCaptor.forClass(TSExecuteStatementReq.class);
verify(client).executeStatement(argument.capture());
assertEquals(
- "INSERT INTO root.ln.wf01.wt01(timestamp,a,b,c,d,e,f) VALUES(2017-11-01T00:13:00,false,123,123234345,123.423,-1323.0,'abc')",
+ "INSERT INTO root.ln.wf01.wt01(timestamp,a,b,c,d,e,f) VALUES(2017-11-01T00:13:00,false,123,123234345,123.423,-1323.0,\"abc\")",
argument.getValue().getStatement());
}
}