提交 a8133047 编写于 作者: Z zyyang

add TSDBPreparedStatement test cases

上级 d7dfde2d
...@@ -22,6 +22,7 @@ public class TSDBError { ...@@ -22,6 +22,7 @@ public class TSDBError {
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE, "Database not specified or available"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE, "Database not specified or available");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: (?)"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: (?)");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "not a valid sql for execute: (?)"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "not a valid sql for execute: (?)");
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_BOUNDARY, "parameter index out of range");
/**************************************************/ /**************************************************/
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error");
......
...@@ -16,6 +16,7 @@ public class TSDBErrorNumbers { ...@@ -16,6 +16,7 @@ public class TSDBErrorNumbers {
public static final int ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE = 0x2310; //Database not specified or available public static final int ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE = 0x2310; //Database not specified or available
public static final int ERROR_INVALID_FOR_EXECUTE_UPDATE = 0x2311; //not a valid sql for executeUpdate: (SQL) public static final int ERROR_INVALID_FOR_EXECUTE_UPDATE = 0x2311; //not a valid sql for executeUpdate: (SQL)
public static final int ERROR_INVALID_FOR_EXECUTE = 0x2312; //not a valid sql for execute: (SQL) public static final int ERROR_INVALID_FOR_EXECUTE = 0x2312; //not a valid sql for execute: (SQL)
public static final int ERROR_PARAMETER_INDEX_OUT_BOUNDARY = 0x2313; // parameter index out of range
public static final int ERROR_UNKNOWN = 0x2350; //unknown error public static final int ERROR_UNKNOWN = 0x2350; //unknown error
...@@ -45,6 +46,7 @@ public class TSDBErrorNumbers { ...@@ -45,6 +46,7 @@ public class TSDBErrorNumbers {
errorNumbers.add(ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE); errorNumbers.add(ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
errorNumbers.add(ERROR_INVALID_FOR_EXECUTE_UPDATE); errorNumbers.add(ERROR_INVALID_FOR_EXECUTE_UPDATE);
errorNumbers.add(ERROR_INVALID_FOR_EXECUTE); errorNumbers.add(ERROR_INVALID_FOR_EXECUTE);
errorNumbers.add(ERROR_PARAMETER_INDEX_OUT_BOUNDARY);
/*****************************************************/ /*****************************************************/
errorNumbers.add(ERROR_SUBSCRIBE_FAILED); errorNumbers.add(ERROR_SUBSCRIBE_FAILED);
......
package com.taosdata.jdbc; package com.taosdata.jdbc;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.sql.Connection; import java.sql.*;
import java.sql.DriverManager;
import java.sql.SQLException;
public class TSDBPreparedStatementTest { public class TSDBPreparedStatementTest {
private static final String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static Connection conn; private static Connection conn;
private static final String sql_insert = "insert into t1 values(?, ?)";
@Test private static PreparedStatement pstmt_insert;
public void executeQuery() { private static final String sql_select = "select * from t1 where ts > ? and ts <= ? and temperature >= ?";
private static PreparedStatement pstmt_select;
@Test
public void executeQuery() throws SQLException {
pstmt_select.setString(1, "now - 1h");
pstmt_select.setString(2, "now");
pstmt_select.setFloat(3, 0);
ResultSet rs = pstmt_select.executeQuery();
Assert.assertNotNull(rs);
ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) {
for (int i = 1; i <= meta.getColumnCount(); i++) {
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
}
System.out.println();
}
} }
@Test @Test
public void executeUpdate() { public void executeUpdate() throws SQLException {
pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
pstmt_insert.setFloat(2, 3.14f);
int result = pstmt_insert.executeUpdate();
Assert.assertEquals(1, result);
} }
@Test @Test
public void setNull() { public void setNull() throws SQLException {
pstmt_insert.setNull(2, Types.FLOAT);
} }
@Test @Test
public void setBoolean() { public void setBoolean() throws SQLException {
pstmt_insert.setBoolean(2, true);
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setByte() { public void setByte() throws SQLException {
pstmt_insert.setByte(1, (byte) 0x001);
} }
@Test @Test
...@@ -54,120 +75,150 @@ public class TSDBPreparedStatementTest { ...@@ -54,120 +75,150 @@ public class TSDBPreparedStatementTest {
public void setDouble() { public void setDouble() {
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setBigDecimal() { public void setBigDecimal() throws SQLException {
pstmt_insert.setBigDecimal(1, null);
} }
@Test @Test
public void setString() { public void setString() {
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setBytes() { public void setBytes() throws SQLException {
pstmt_insert.setBytes(1, new byte[]{});
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setDate() { public void setDate() throws SQLException {
pstmt_insert.setDate(1, new Date(System.currentTimeMillis()));
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setTime() { public void setTime() throws SQLException {
pstmt_insert.setTime(1, new Time(System.currentTimeMillis()));
} }
@Test @Test
public void setTimestamp() { public void setTimestamp() {
//TODO
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setAsciiStream() { public void setAsciiStream() throws SQLException {
} pstmt_insert.setAsciiStream(1, null);
@Test
public void setUnicodeStream() {
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setBinaryStream() { public void setBinaryStream() throws SQLException {
pstmt_insert.setBinaryStream(1, null);
} }
@Test @Test
public void clearParameters() { public void clearParameters() {
//TODO
} }
@Test @Test
public void setObject() { public void setObject() throws SQLException {
pstmt_insert.setObject(1, System.currentTimeMillis());
//TODO
} }
@Test @Test
public void execute() { public void execute() {
//TODO
} }
@Test @Test
public void addBatch() { public void addBatch() {
//TODO:
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setCharacterStream() { public void setCharacterStream() throws SQLException {
pstmt_insert.setCharacterStream(1, null);
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setRef() { public void setRef() throws SQLException {
pstmt_insert.setRef(1, null);
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setBlob() { public void setBlob() throws SQLException {
pstmt_insert.setBlob(1, (Blob) null);
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setClob() { public void setClob() throws SQLException {
pstmt_insert.setClob(1, (Clob) null);
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setArray() { public void setArray() throws SQLException {
pstmt_insert.setArray(1, null);
} }
@Test @Test
public void getMetaData() { public void getMetaData() throws SQLException {
ResultSetMetaData metaData = pstmt_insert.getMetaData();
Assert.assertNotNull(metaData);
//TODO
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setURL() { public void setURL() throws SQLException {
pstmt_insert.setURL(1, null);
} }
@Test @Test
public void getParameterMetaData() { public void getParameterMetaData() throws SQLException {
ParameterMetaData parameterMetaData = pstmt_insert.getParameterMetaData();
Assert.assertNotNull(parameterMetaData);
//TODO:
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setRowId() { public void setRowId() throws SQLException {
pstmt_insert.setRowId(1, null);
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setNString() { public void setNString() throws SQLException {
pstmt_insert.setNString(1, null);
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setNCharacterStream() { public void setNCharacterStream() throws SQLException {
pstmt_insert.setNCharacterStream(1, null);
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setNClob() { public void setNClob() throws SQLException {
pstmt_insert.setNClob(1, (NClob) null);
} }
@Test @Test(expected = SQLFeatureNotSupportedException.class)
public void setSQLXML() { public void setSQLXML() throws SQLException {
pstmt_insert.setSQLXML(1, null);
} }
@BeforeClass @BeforeClass
public static void beforeClass() { public static void beforeClass() {
try { try {
Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); Class.forName("com.taosdata.jdbc.TSDBDriver");
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata");
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists test_pstmt");
stmt.execute("create database if not exists test_pstmt");
stmt.execute("use test_pstmt");
stmt.execute("create table weather(ts timestamp, temperature float) tags(loc nchar(64))");
stmt.execute("create table t1 using weather tags('beijing')");
}
pstmt_insert = conn.prepareStatement(sql_insert);
pstmt_select = conn.prepareStatement(sql_select);
} catch (ClassNotFoundException | SQLException e) { } catch (ClassNotFoundException | SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -176,6 +227,7 @@ public class TSDBPreparedStatementTest { ...@@ -176,6 +227,7 @@ public class TSDBPreparedStatementTest {
@AfterClass @AfterClass
public static void afterClass() { public static void afterClass() {
try { try {
if (conn != null) if (conn != null)
conn.close(); conn.close();
} catch (SQLException e) { } catch (SQLException e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册