change
This commit is contained in:
parent
ffcc0dec9f
commit
a5f02a8954
|
@ -132,7 +132,7 @@ public class TSDBStatement extends AbstractStatement {
|
||||||
public void clearBatch() throws SQLException {
|
public void clearBatch() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||||
|
if (batchedArgs != null)
|
||||||
batchedArgs.clear();
|
batchedArgs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,14 @@ public class TSDBStatementTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void executeUpdate() {
|
public void executeUpdate() {
|
||||||
String dbName = "test_" + UUID.randomUUID();
|
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
|
||||||
dbName = dbName.replace("-", "_").substring(0,32);
|
|
||||||
try {
|
try {
|
||||||
int affectRows = stmt.executeUpdate("create database " + dbName);
|
int affectRows = stmt.executeUpdate("create database " + dbName);
|
||||||
Assert.assertEquals(0, affectRows);
|
Assert.assertEquals(0, affectRows);
|
||||||
|
affectRows = stmt.executeUpdate("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
|
||||||
|
Assert.assertEquals(0, affectRows);
|
||||||
|
affectRows = stmt.executeUpdate("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
|
||||||
|
Assert.assertEquals(1, affectRows);
|
||||||
affectRows = stmt.executeUpdate("drop database " + dbName);
|
affectRows = stmt.executeUpdate("drop database " + dbName);
|
||||||
Assert.assertEquals(0, affectRows);
|
Assert.assertEquals(0, affectRows);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -52,51 +55,152 @@ public class TSDBStatementTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void execute() {
|
public void execute() {
|
||||||
|
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
|
||||||
|
try {
|
||||||
|
boolean isSelect = stmt.execute("create database " + dbName);
|
||||||
|
Assert.assertEquals(false, isSelect);
|
||||||
|
int affectedRows = stmt.getUpdateCount();
|
||||||
|
Assert.assertEquals(0, affectedRows);
|
||||||
|
|
||||||
|
isSelect = stmt.execute("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
|
||||||
|
Assert.assertEquals(false, isSelect);
|
||||||
|
affectedRows = stmt.getUpdateCount();
|
||||||
|
Assert.assertEquals(0, affectedRows);
|
||||||
|
|
||||||
|
isSelect = stmt.execute("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
|
||||||
|
Assert.assertEquals(false, isSelect);
|
||||||
|
affectedRows = stmt.getUpdateCount();
|
||||||
|
Assert.assertEquals(1, affectedRows);
|
||||||
|
|
||||||
|
isSelect = stmt.execute("select * from " + dbName + ".weather");
|
||||||
|
Assert.assertEquals(true, isSelect);
|
||||||
|
|
||||||
|
isSelect = stmt.execute("drop database " + dbName);
|
||||||
|
Assert.assertEquals(false, isSelect);
|
||||||
|
affectedRows = stmt.getUpdateCount();
|
||||||
|
Assert.assertEquals(0, affectedRows);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResultSet() {
|
public void getResultSet() {
|
||||||
|
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
|
||||||
|
try {
|
||||||
|
boolean isSelect = stmt.execute("create database " + dbName);
|
||||||
|
Assert.assertEquals(false, isSelect);
|
||||||
|
int affectedRows = stmt.getUpdateCount();
|
||||||
|
Assert.assertEquals(0, affectedRows);
|
||||||
|
|
||||||
|
isSelect = stmt.execute("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
|
||||||
|
Assert.assertEquals(false, isSelect);
|
||||||
|
affectedRows = stmt.getUpdateCount();
|
||||||
|
Assert.assertEquals(0, affectedRows);
|
||||||
|
|
||||||
|
isSelect = stmt.execute("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
|
||||||
|
Assert.assertEquals(false, isSelect);
|
||||||
|
affectedRows = stmt.getUpdateCount();
|
||||||
|
Assert.assertEquals(1, affectedRows);
|
||||||
|
|
||||||
|
isSelect = stmt.execute("select * from " + dbName + ".weather");
|
||||||
|
Assert.assertEquals(true, isSelect);
|
||||||
|
ResultSet rs = stmt.getResultSet();
|
||||||
|
Assert.assertNotNull(rs);
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
Assert.assertEquals(3, meta.getColumnCount());
|
||||||
|
int count = 0;
|
||||||
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
Assert.assertEquals(1, count);
|
||||||
|
|
||||||
|
isSelect = stmt.execute("drop database " + dbName);
|
||||||
|
Assert.assertEquals(false, isSelect);
|
||||||
|
affectedRows = stmt.getUpdateCount();
|
||||||
|
Assert.assertEquals(0, affectedRows);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getUpdateCount() {
|
public void getUpdateCount() {
|
||||||
}
|
execute();
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getResultSetConcurrency() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getResultSetType() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addBatch() {
|
public void addBatch() {
|
||||||
|
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
|
||||||
|
try {
|
||||||
|
stmt.addBatch("create database " + dbName);
|
||||||
|
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
|
||||||
|
stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
|
||||||
|
stmt.addBatch("select * from " + dbName + ".weather");
|
||||||
|
stmt.addBatch("drop database " + dbName);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clearBatch() {
|
public void clearBatch() {
|
||||||
|
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
|
||||||
|
try {
|
||||||
|
stmt.clearBatch();
|
||||||
|
stmt.addBatch("create database " + dbName);
|
||||||
|
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
|
||||||
|
stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
|
||||||
|
stmt.addBatch("select * from " + dbName + ".weather");
|
||||||
|
stmt.addBatch("drop database " + dbName);
|
||||||
|
stmt.clearBatch();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void executeBatch() {
|
public void executeBatch() {
|
||||||
|
final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32);
|
||||||
|
try {
|
||||||
|
stmt.addBatch("create database " + dbName);
|
||||||
|
stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))");
|
||||||
|
stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)");
|
||||||
|
stmt.addBatch("select * from " + dbName + ".weather");
|
||||||
|
stmt.addBatch("drop database " + dbName);
|
||||||
|
int[] results = stmt.executeBatch();
|
||||||
|
Assert.assertEquals(0, results[0]);
|
||||||
|
Assert.assertEquals(0, results[1]);
|
||||||
|
Assert.assertEquals(1, results[2]);
|
||||||
|
Assert.assertEquals(Statement.SUCCESS_NO_INFO, results[3]);
|
||||||
|
Assert.assertEquals(0, results[4]);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnection() {
|
public void getConnection() {
|
||||||
|
try {
|
||||||
|
Connection connection = stmt.getConnection();
|
||||||
|
Assert.assertNotNull(connection);
|
||||||
|
Assert.assertTrue(this.conn == connection);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getMoreResults() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getResultSetHoldability() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isClosed() {
|
public void isClosed() {
|
||||||
|
try {
|
||||||
|
Assert.assertEquals(false, stmt.isClosed());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
|
Loading…
Reference in New Issue