提交 ad108b2d 编写于 作者: haoranc's avatar haoranc

Merge branch 'develop' of github.com:taosdata/TDengine into dev/chr

......@@ -14,13 +14,43 @@ import java.math.BigDecimal;
import java.sql.*;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.chrono.IsoChronology;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
public class RestfulResultSet extends AbstractResultSet implements ResultSet {
public static DateTimeFormatter rfc3339Parser = null;
{
rfc3339Parser = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.appendValue(ChronoField.YEAR, 4)
.appendLiteral('-')
.appendValue(ChronoField.MONTH_OF_YEAR, 2)
.appendLiteral('-')
.appendValue(ChronoField.DAY_OF_MONTH, 2)
.appendLiteral('T')
.appendValue(ChronoField.HOUR_OF_DAY, 2)
.appendLiteral(':')
.appendValue(ChronoField.MINUTE_OF_HOUR, 2)
.appendLiteral(':')
.appendValue(ChronoField.SECOND_OF_MINUTE, 2)
.optionalStart()
.appendFraction(ChronoField.NANO_OF_SECOND, 2, 9, true)
.optionalEnd()
.appendOffset("+HH:MM", "Z").toFormatter()
.withResolverStyle(ResolverStyle.STRICT)
.withChronology(IsoChronology.INSTANCE);
}
private final Statement statement;
// data
private final List<List<Object>> resultSet = new ArrayList<>();
......@@ -187,25 +217,41 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
}
case UTC: {
String value = row.getString(colIndex);
long epochSec = Timestamp.valueOf(value.substring(0, 19).replace("T", " ")).getTime() / 1000;
int fractionalSec = Integer.parseInt(value.substring(20, value.length() - 5));
long nanoAdjustment;
if (value.length() > 31) {
// ns timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSSSSS+0x00
nanoAdjustment = fractionalSec;
this.timestampPrecision = TimestampPrecision.NS;
} else if (value.length() > 28) {
// ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x00
nanoAdjustment = fractionalSec * 1000L;
this.timestampPrecision = TimestampPrecision.US;
if (value.lastIndexOf(":") > 19) {
ZonedDateTime parse = ZonedDateTime.parse(value, rfc3339Parser);
long nanoAdjustment;
if (value.length() > 32) {
// ns timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSSSSS+0x:00
this.timestampPrecision = TimestampPrecision.NS;
} else if (value.length() > 29) {
// ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x:00
this.timestampPrecision = TimestampPrecision.US;
} else {
// ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x:00
this.timestampPrecision = TimestampPrecision.MS;
}
return Timestamp.from(parse.toInstant());
} else {
// ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x00
nanoAdjustment = fractionalSec * 1000_000L;
this.timestampPrecision = TimestampPrecision.MS;
long epochSec = Timestamp.valueOf(value.substring(0, 19).replace("T", " ")).getTime() / 1000;
int fractionalSec = Integer.parseInt(value.substring(20, value.length() - 5));
long nanoAdjustment;
if (value.length() > 32) {
// ns timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSSSSS+0x00
nanoAdjustment = fractionalSec;
this.timestampPrecision = TimestampPrecision.NS;
} else if (value.length() > 29) {
// ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x00
nanoAdjustment = fractionalSec * 1000L;
this.timestampPrecision = TimestampPrecision.US;
} else {
// ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x00
nanoAdjustment = fractionalSec * 1000_000L;
this.timestampPrecision = TimestampPrecision.MS;
}
ZoneOffset zoneOffset = ZoneOffset.of(value.substring(value.length() - 5));
Instant instant = Instant.ofEpochSecond(epochSec, nanoAdjustment).atOffset(zoneOffset).toInstant();
return Timestamp.from(instant);
}
ZoneOffset zoneOffset = ZoneOffset.of(value.substring(value.length() - 5));
Instant instant = Instant.ofEpochSecond(epochSec, nanoAdjustment).atOffset(zoneOffset).toInstant();
return Timestamp.from(instant);
}
case STRING:
default: {
......
......@@ -72,6 +72,7 @@ public class RestfulStatement extends AbstractStatement {
}
this.database = sql.trim().replace("use", "").trim();
this.conn.setCatalog(this.database);
this.conn.setClientInfo(TSDBDriver.PROPERTY_KEY_DBNAME, this.database);
result = false;
} else if (SqlSyntaxValidator.isDatabaseUnspecifiedQuery(sql)) {
executeOneQuery(sql);
......
......@@ -128,8 +128,8 @@ public class ParameterBindTest {
@After
public void after() {
try {
// Statement stmt = conn.createStatement();
// stmt.execute("drop database if exists test_pd");
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test_pd");
if (conn != null)
conn.close();
} catch (SQLException e) {
......
......@@ -187,7 +187,6 @@ public class SchemalessInsertTest {
public void after() {
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
......
......@@ -380,8 +380,12 @@ public class TSDBConnectionTest {
@AfterClass
public static void afterClass() throws SQLException {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists test");
statement.close();
conn.close();
}
}
}
\ No newline at end of file
package com.taosdata.jdbc;
import org.junit.BeforeClass;
import org.junit.Test;
import java.sql.*;
......
......@@ -7,6 +7,7 @@ import org.junit.Test;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
......@@ -19,115 +20,111 @@ public class TSDBJNIConnectorTest {
private static TSDBResultSetRowData rowData;
@Test
public void test() {
public void test() throws SQLException {
try {
try {
//change sleepSeconds when debugging with attach to process to find PID
int sleepSeconds = -1;
if (sleepSeconds > 0) {
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
String jvmName = runtimeBean.getName();
long pid = Long.valueOf(jvmName.split("@")[0]);
System.out.println("JVM PID = " + pid);
Thread.sleep(sleepSeconds * 1000);
}
} catch (Exception e) {
e.printStackTrace();
//change sleepSeconds when debugging with attach to process to find PID
int sleepSeconds = -1;
if (sleepSeconds > 0) {
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
String jvmName = runtimeBean.getName();
long pid = Long.valueOf(jvmName.split("@")[0]);
System.out.println("JVM PID = " + pid);
Thread.sleep(sleepSeconds * 1000);
}
} catch (Exception e) {
e.printStackTrace();
}
// init
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR, "/etc/taos");
TSDBJNIConnector.init(properties);
// connect
TSDBJNIConnector connector = new TSDBJNIConnector();
connector.connect("127.0.0.1", 6030, null, "root", "taosdata");
// setup
String setupSqlStrs[] = {"create database if not exists d precision \"us\"",
"create table if not exists d.t(ts timestamp, f int)",
"create database if not exists d2",
"create table if not exists d2.t2(ts timestamp, f int)",
"insert into d.t values(now+100s, 100)",
"insert into d2.t2 values(now+200s, 200)"
};
for (String setupSqlStr : setupSqlStrs) {
long setupSql = connector.executeQuery(setupSqlStr);
assertEquals(0, connector.getResultTimePrecision(setupSql));
if (connector.isUpdateQuery(setupSql)) {
connector.freeResultSet(setupSql);
}
// init
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR, "/etc/taos");
TSDBJNIConnector.init(properties);
// connect
TSDBJNIConnector connector = new TSDBJNIConnector();
connector.connect("127.0.0.1", 6030, null, "root", "taosdata");
// setup
String setupSqlStrs[] = {"create database if not exists d precision \"us\"",
"create table if not exists d.t(ts timestamp, f int)",
"create database if not exists d2",
"create table if not exists d2.t2(ts timestamp, f int)",
"insert into d.t values(now+100s, 100)",
"insert into d2.t2 values(now+200s, 200)"
};
for (String setupSqlStr : setupSqlStrs) {
long setupSql = connector.executeQuery(setupSqlStr);
assertEquals(0, connector.getResultTimePrecision(setupSql));
if (connector.isUpdateQuery(setupSql)) {
connector.freeResultSet(setupSql);
}
}
{
long sqlObj1 = connector.executeQuery("select * from d2.t2");
assertEquals(0, connector.getResultTimePrecision(sqlObj1));
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
int code = connector.getSchemaMetaData(sqlObj1, columnMetaDataList);
rowData = new TSDBResultSetRowData(columnMetaDataList.size());
assertTrue(next(connector, sqlObj1));
assertEquals(0, connector.getResultTimePrecision(sqlObj1));
connector.freeResultSet(sqlObj1);
}
{
long sqlObj1 = connector.executeQuery("select * from d2.t2");
assertEquals(0, connector.getResultTimePrecision(sqlObj1));
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
int code = connector.getSchemaMetaData(sqlObj1, columnMetaDataList);
rowData = new TSDBResultSetRowData(columnMetaDataList.size());
assertTrue(next(connector, sqlObj1));
assertEquals(0, connector.getResultTimePrecision(sqlObj1));
connector.freeResultSet(sqlObj1);
}
// executeQuery
long pSql = connector.executeQuery("select * from d.t");
// executeQuery
long pSql = connector.executeQuery("select * from d.t");
if (connector.isUpdateQuery(pSql)) {
connector.freeResultSet(pSql);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
}
if (connector.isUpdateQuery(pSql)) {
connector.freeResultSet(pSql);
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY);
}
assertEquals(1, connector.getResultTimePrecision(pSql));
assertEquals(1, connector.getResultTimePrecision(pSql));
// get schema
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
int code = connector.getSchemaMetaData(pSql, columnMetaDataList);
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
}
if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
}
if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0);
}
// get schema
List<ColumnMetaData> columnMetaDataList = new ArrayList<>();
int code = connector.getSchemaMetaData(pSql, columnMetaDataList);
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
}
if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
}
if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0);
}
assertEquals(1, connector.getResultTimePrecision(pSql));
int columnSize = columnMetaDataList.size();
// print metadata
for (int i = 0; i < columnSize; i++) {
// System.out.println(columnMetaDataList.get(i));
}
rowData = new TSDBResultSetRowData(columnSize);
// iterate resultSet
for (int i = 0; next(connector, pSql); i++) {
assertEquals(1, connector.getResultTimePrecision(pSql));
int columnSize = columnMetaDataList.size();
// print metadata
for (int i = 0; i < columnSize; i++) {
System.out.println(columnMetaDataList.get(i));
}
rowData = new TSDBResultSetRowData(columnSize);
// iterate resultSet
for (int i = 0; next(connector, pSql); i++) {
assertEquals(1, connector.getResultTimePrecision(pSql));
System.out.println();
}
// close resultSet
code = connector.freeResultSet(pSql);
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
} else if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
}
// close statement
connector.executeQuery("use d");
String[] lines = new String[]{
"st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000",
"st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000"};
connector.insertLines(lines, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO_SECONDS);
// close connection
connector.closeConnection();
} catch (SQLException e) {
e.printStackTrace();
}
// close resultSet
code = connector.freeResultSet(pSql);
if (code == TSDBConstants.JNI_CONNECTION_NULL) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
} else if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
}
// close statement
connector.executeQuery("use d");
String[] lines = new String[]{
"st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000",
"st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000"};
connector.insertLines(lines, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO_SECONDS);
// close connection
connector.executeQuery("drop database if exists d");
connector.executeQuery("drop database if exists d2");
connector.closeConnection();
}
private static boolean next(TSDBJNIConnector connector, long pSql) throws SQLException {
......
......@@ -17,6 +17,7 @@ public class TSDBParameterMetaDataTest {
private static PreparedStatement pstmt_select;
private static ParameterMetaData parameterMetaData_insert;
private static ParameterMetaData parameterMetaData_select;
private static final String dbname = "test_pstmt";
@Test
public void getParameterCount() throws SQLException {
......@@ -152,9 +153,9 @@ public class TSDBParameterMetaDataTest {
try {
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("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64))");
stmt.execute("create table t1 using weather tags('beijing')");
}
......@@ -190,8 +191,12 @@ public class TSDBParameterMetaDataTest {
pstmt_insert.close();
if (pstmt_select != null)
pstmt_select.close();
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists " + dbname);
statement.close();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
......
......@@ -1233,6 +1233,7 @@ public class TSDBPreparedStatementTest {
try {
Statement statement = conn.createStatement();
statement.execute("drop database if exists " + dbname);
statement.execute("drop database if exists dbtest");
statement.close();
if (conn != null)
conn.close();
......
......@@ -668,8 +668,12 @@ public class TSDBResultSetTest {
rs.close();
if (stmt != null)
stmt.close();
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists restful_test");
statement.close();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
......
package com.taosdata.jdbc.cases;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.*;
import org.junit.runners.MethodSorters;
import java.sql.*;
......@@ -16,36 +13,32 @@ public class InsertDbwithoutUseDbTest {
private static final String host = "127.0.0.1";
private static Properties properties;
private static final Random random = new Random(System.currentTimeMillis());
private static final String dbname = "inWithoutDb";
@Test
public void case001() throws SQLException {
// prepare schema
String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata";
Connection conn = DriverManager.getConnection(url, properties);
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists inWithoutDb");
stmt.execute("create database if not exists inWithoutDb");
stmt.execute("create table inWithoutDb.weather(ts timestamp, f1 int)");
}
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("create table " + dbname + ".weather(ts timestamp, f1 int)");
conn.close();
// execute insert
url = "jdbc:TAOS://127.0.0.1:6030/inWithoutDb?user=root&password=taosdata";
url = "jdbc:TAOS://127.0.0.1:6030/" + dbname + "?user=root&password=taosdata";
conn = DriverManager.getConnection(url, properties);
try (Statement stmt = conn.createStatement()) {
int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")");
Assert.assertEquals(1, affectedRow);
boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")");
Assert.assertEquals(false, flag);
ResultSet rs = stmt.executeQuery("select count(*) from weather");
rs.next();
int count = rs.getInt("count(*)");
Assert.assertEquals(2, count);
} catch (SQLException e) {
e.printStackTrace();
}
stmt = conn.createStatement();
int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")");
Assert.assertEquals(1, affectedRow);
boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")");
Assert.assertEquals(false, flag);
ResultSet rs = stmt.executeQuery("select count(*) from weather");
rs.next();
int count = rs.getInt("count(*)");
Assert.assertEquals(2, count);
conn.close();
}
......@@ -54,28 +47,25 @@ public class InsertDbwithoutUseDbTest {
// prepare the schema
final String url = "jdbc:TAOS-RS://" + host + ":6041/inWithoutDb?user=root&password=taosdata";
Connection conn = DriverManager.getConnection(url, properties);
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists inWithoutDb");
stmt.execute("create database if not exists inWithoutDb");
stmt.execute("create table inWithoutDb.weather(ts timestamp, f1 int)");
}
conn.close();
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("create table " + dbname + ".weather(ts timestamp, f1 int)");
stmt.close();
// execute
conn = DriverManager.getConnection(url, properties);
try (Statement stmt = conn.createStatement()) {
int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")");
Assert.assertEquals(1, affectedRow);
boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")");
Assert.assertEquals(false, flag);
ResultSet rs = stmt.executeQuery("select count(*) from weather");
rs.next();
int count = rs.getInt("count(*)");
Assert.assertEquals(2, count);
} catch (SQLException e) {
e.printStackTrace();
}
stmt = conn.createStatement();
int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")");
Assert.assertEquals(1, affectedRow);
boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")");
Assert.assertEquals(false, flag);
ResultSet rs = stmt.executeQuery("select count(*) from weather");
rs.next();
int count = rs.getInt("count(*)");
Assert.assertEquals(2, count);
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
}
@BeforeClass
......
......@@ -427,8 +427,12 @@ public class InsertSpecialCharacterJniTest {
@AfterClass
public static void afterClass() throws SQLException {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists " + dbName);
statement.close();
conn.close();
}
}
}
......@@ -391,8 +391,12 @@ public class InsertSpecialCharacterRestfulTest {
@AfterClass
public static void afterClass() throws SQLException {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists "+ dbName);
statement.close();
conn.close();
}
}
}
package com.taosdata.jdbc.cases;
import org.junit.AfterClass;
import org.junit.Test;
import java.sql.*;
public class JDBCTypeAndTypeCompareTest {
private static Connection conn;
private static final String dbname = "test";
@Test
public void test() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:TAOS://192.168.17.156:6030/", "root", "taosdata");
conn = DriverManager.getConnection("jdbc:TAOS://127.0.0.1:6030/", "root", "taosdata");
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test");
stmt.execute("create database if not exists test");
stmt.execute("use test");
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(10), f9 nchar(10) )");
stmt.execute("insert into weather values(now, 1, 2, 3.0, 4.0, 5, 6, true, 'test','test')");
......@@ -29,6 +32,19 @@ public class JDBCTypeAndTypeCompareTest {
}
stmt.close();
conn.close();
}
@AfterClass
public static void afterClass() {
try {
if (null != conn) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists " + dbname);
statement.close();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
......@@ -47,7 +47,7 @@ public class MicroSecondPrecisionJNITest {
Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos);
ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts);
Assert.assertEquals(timestamp2, ts);
} catch (SQLException e) {
e.printStackTrace();
}
......@@ -79,8 +79,13 @@ public class MicroSecondPrecisionJNITest {
@AfterClass
public static void afterClass() {
try {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database " + ms_timestamp_db);
statement.execute("drop database " + us_timestamp_db);
statement.close();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
......
......@@ -47,7 +47,7 @@ public class MicroSecondPrecisionRestfulTest {
Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos);
ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts);
Assert.assertEquals(timestamp2, ts);
}
}
......@@ -77,7 +77,7 @@ public class MicroSecondPrecisionRestfulTest {
Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos);
ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts);
Assert.assertEquals(timestamp2, ts);
}
}
......@@ -107,7 +107,7 @@ public class MicroSecondPrecisionRestfulTest {
Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos);
ts = rs.getLong(1);
Assert.assertEquals(timestamp1, ts);
Assert.assertEquals(timestamp2, ts);
}
}
......@@ -142,12 +142,21 @@ public class MicroSecondPrecisionRestfulTest {
}
@AfterClass
public static void afterClass() throws SQLException {
if (conn1 != null)
conn1.close();
if (conn2 != null)
conn2.close();
if (conn3 != null)
conn3.close();
public static void afterClass() {
try {
if (conn1 != null) {
Statement statement = conn1.createStatement();
statement.execute("drop database if exists " + ms_timestamp_db);
statement.execute("drop database if exists " + us_timestamp_db);
statement.close();
conn1.close();
}
if (conn2 != null)
conn2.close();
if (conn3 != null)
conn3.close();
}catch (SQLException e){
e.printStackTrace();
}
}
}
package com.taosdata.jdbc.cases;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -90,4 +91,16 @@ public class MultiConnectionWithDifferentDbTest {
}
}
@After
public void after() {
String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
try (Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement()) {
statement.execute("drop database if exists " + db1);
statement.execute("drop database if exists " + db2);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
package com.taosdata.jdbc.cases;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.*;
import java.sql.*;
import java.time.Instant;
......@@ -83,9 +80,9 @@ public class NanoSecondTimestampJNITest {
// then
long actual = rs.getLong(1);
Assert.assertEquals(ms, actual);
Assert.assertEquals(ns, actual);
actual = rs.getLong("ts");
Assert.assertEquals(ms, actual);
Assert.assertEquals(ns, actual);
}
@Test
......@@ -160,4 +157,18 @@ public class NanoSecondTimestampJNITest {
}
}
@AfterClass
public static void afterClass(){
try {
if (null != conn){
Statement statement = conn.createStatement();
statement.execute("drop database if exists " + dbname);
statement.close();
conn.close();
}
}catch (SQLException e){
e.printStackTrace();
}
}
}
package com.taosdata.jdbc.cases;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.*;
import java.sql.*;
import java.time.Instant;
......@@ -83,9 +80,9 @@ public class NanoSecondTimestampRestfulTest {
// then
long actual = rs.getLong(1);
Assert.assertEquals(ms, actual);
Assert.assertEquals(ns, actual);
actual = rs.getLong("ts");
Assert.assertEquals(ms, actual);
Assert.assertEquals(ns, actual);
}
@Test
......@@ -160,4 +157,14 @@ public class NanoSecondTimestampRestfulTest {
}
}
@AfterClass
public static void afterClass() throws SQLException {
if (conn != null){
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists " + dbname);
}
conn.close();
}
}
}
......@@ -45,7 +45,11 @@ public class NullValueInResultSetJNITest {
@After
public void after() throws SQLException {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists test_null");
statement.close();
conn.close();
}
}
}
......@@ -47,7 +47,11 @@ public class NullValueInResultSetRestfulTest {
@After
public void after() throws SQLException {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists test_null");
statement.close();
conn.close();
}
}
}
......@@ -85,7 +85,11 @@ public class NullValueInResultSetTest {
public static void afterClass() throws SQLException {
if (conn_restful != null)
conn_restful.close();
if (conn_jni != null)
if (conn_jni != null) {
Statement statement = conn_jni.createStatement();
statement.execute("drop database if exists test_null");
statement.close();
conn_jni.close();
}
}
}
......@@ -62,8 +62,12 @@ public class TimestampPrecisionInNanoInJniTest {
@AfterClass
public static void afterClass() {
try {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists " + ns_timestamp_db);
statement.close();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
......@@ -83,7 +87,7 @@ public class TimestampPrecisionInNanoInJniTest {
int nanos = rs.getTimestamp(1).getNanos();
Assert.assertEquals(ts % 1000_000_000l, nanos);
long test_ts = rs.getLong(1);
Assert.assertEquals(ts / 1000_000l, test_ts);
Assert.assertEquals(ts, test_ts);
}
@Test
......
......@@ -62,8 +62,12 @@ public class TimestampPrecisonInNanoRestTest {
@AfterClass
public static void afterClass() {
try {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists " + ns_timestamp_db);
statement.close();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
......@@ -83,7 +87,7 @@ public class TimestampPrecisonInNanoRestTest {
int nanos = rs.getTimestamp(1).getNanos();
Assert.assertEquals(ts % 1000_000_000l, nanos);
long test_ts = rs.getLong(1);
Assert.assertEquals(ts / 1000_000l, test_ts);
Assert.assertEquals(ts, test_ts);
}
@Test
......
......@@ -156,8 +156,12 @@ public class UnsignedNumberJniTest {
@AfterClass
public static void afterClass() throws SQLException {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists unsign_jni");
statement.close();
conn.close();
}
}
}
......@@ -14,6 +14,7 @@ public class UnsignedNumberRestfulTest {
private static final String host = "127.0.0.1";
private static Connection conn;
private static long ts;
private static final String dbname = "unsign_restful";
@Test
public void testCase001() throws SQLException {
......@@ -148,9 +149,9 @@ public class UnsignedNumberRestfulTest {
final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
conn = DriverManager.getConnection(url, properties);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists unsign_restful");
stmt.execute("create database if not exists unsign_restful");
stmt.execute("use unsign_restful");
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)");
stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + ts + ", 127, 32767,2147483647, 9223372036854775807)");
stmt.close();
......@@ -162,8 +163,12 @@ public class UnsignedNumberRestfulTest {
@AfterClass
public static void afterClass() {
try {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists " + dbname);
statement.close();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
......
package com.taosdata.jdbc.cases;
import org.junit.AfterClass;
import org.junit.Test;
import java.sql.*;
......@@ -8,7 +9,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class UseNowInsertTimestampTest {
String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata";
private static String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata";
@Test
public void millisec() throws SQLException {
......@@ -55,13 +56,14 @@ public class UseNowInsertTimestampTest {
@Test
public void nanosec() throws SQLException {
long now_time = System.currentTimeMillis() * 1000_000L + System.nanoTime() % 1000_000L;
try (Connection conn = DriverManager.getConnection(url)) {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test");
stmt.execute("create database if not exists test precision 'ns'");
stmt.execute("use test");
stmt.execute("create table weather(ts timestamp, f1 int)");
stmt.execute("insert into weather values(now, 1)");
stmt.execute("insert into weather values(" + now_time + ", 1)");
ResultSet rs = stmt.executeQuery("select * from weather");
rs.next();
......@@ -74,4 +76,15 @@ public class UseNowInsertTimestampTest {
stmt.execute("drop database if exists test");
}
}
@AfterClass
public static void afterClass() {
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists test");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
......@@ -45,7 +45,11 @@ public class BadLocaleSettingTest {
@AfterClass
public static void afterClass() throws SQLException {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database " + dbName);
statement.close();
conn.close();
}
}
}
\ No newline at end of file
......@@ -79,4 +79,15 @@ public class BatchFetchTest {
}
return builder.toString();
}
@AfterClass
public static void afterClass(){
String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists test");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
package com.taosdata.jdbc.confprops;
import com.taosdata.jdbc.TSDBDriver;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
......@@ -37,4 +38,18 @@ public class CharsetTest {
}
}
@AfterClass
public static void afterClass(){
String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
Properties props = new Properties();
props.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
try (Connection conn = DriverManager.getConnection(url, props);
Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists test");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
......@@ -29,7 +29,7 @@ public class TimeZoneTest {
}
@Test
public void taosTimeZone() {
public void taosTimeZone() throws SQLException {
// given
Properties props = new Properties();
props.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
......@@ -39,7 +39,7 @@ public class TimeZoneTest {
Statement stmt = connection.createStatement();
stmt.execute("drop database if exists timezone_test");
stmt.execute("create database if not exists timezone_test keep 365000");
stmt.execute("create database if not exists timezone_test keep 36500");
stmt.execute("use timezone_test");
stmt.execute("create table weather(ts timestamp, temperature float)");
......@@ -51,7 +51,7 @@ public class TimeZoneTest {
System.out.println("ts: " + ts.getTime() + "," + ts);
}
stmt.execute("insert into timezone_test.weather(ts, temperature, humidity) values('1970-01-02 00:00:00', 1.0, 2.0)");
stmt.execute("insert into timezone_test.weather(ts, temperature) values('1970-01-02 00:00:00', 1.0)");
rs = stmt.executeQuery("select * from timezone_test.weather");
while (rs.next()) {
......@@ -63,8 +63,6 @@ public class TimeZoneTest {
stmt.execute("drop database if exists timezone_test");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
......
package com.taosdata.jdbc.confprops;
import com.taosdata.jdbc.TSDBDriver;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;
import java.sql.*;
import java.time.Instant;
import java.util.Calendar;
import java.util.Properties;
public class TimestampFormatTest {
private static final String host = "127.0.0.1";
private long ts = Instant.now().toEpochMilli();
private Connection conn;
@Test
public void string() throws SQLException {
......@@ -154,13 +154,27 @@ public class TimestampFormatTest {
@Before
public void before() throws SQLException {
String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists test");
stmt.execute("create database if not exists test");
stmt.execute("use test");
stmt.execute("create table weather(ts timestamp, temperature nchar(10))");
stmt.execute("insert into weather values(" + ts + ", '北京')");
conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test");
stmt.execute("create database if not exists test");
stmt.execute("use test");
stmt.execute("create table weather(ts timestamp, temperature nchar(10))");
stmt.execute("insert into weather values(" + ts + ", '北京')");
stmt.close();
}
@After
public void after() {
try {
if (null != conn) {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists test");
stmt.close();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
......
......@@ -33,7 +33,6 @@ public class DatabaseSpecifiedTest {
String loc = rs.getString("loc");
assertEquals("beijing", loc);
}
connection.close();
}
@Before
......@@ -59,8 +58,12 @@ public class DatabaseSpecifiedTest {
@After
public void after() {
try {
if (connection != null)
if (connection != null) {
Statement statement = connection.createStatement();
statement.execute("drop database if exists " + dbname);
statement.close();
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
......
......@@ -383,8 +383,12 @@ public class RestfulConnectionTest {
@AfterClass
public static void afterClass() throws SQLException {
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists test");
statement.close();
conn.close();
}
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ public class RestfulParameterMetaDataTest {
private static PreparedStatement pstmt_select;
private static ParameterMetaData parameterMetaData_insert;
private static ParameterMetaData parameterMetaData_select;
private static final String dbname = "test_pstmt";
@Test
public void getParameterCount() throws SQLException {
......@@ -148,9 +149,9 @@ public class RestfulParameterMetaDataTest {
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?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("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64))");
stmt.execute("create table t1 using weather tags('beijing')");
}
......@@ -186,8 +187,12 @@ public class RestfulParameterMetaDataTest {
pstmt_insert.close();
if (pstmt_select != null)
pstmt_select.close();
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists " + dbname);
statement.close();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
......
......@@ -400,8 +400,12 @@ public class RestfulPreparedStatementTest {
pstmt_select.close();
if (pstmt_without_parameters != null)
pstmt_without_parameters.close();
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists test_pstmt");
statement.close();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
......
......@@ -15,6 +15,7 @@ public class RestfulResultSetMetaDataTest {
private static Statement stmt;
private static ResultSet rs;
private static ResultSetMetaData meta;
private static final String dbname = "restful_test";
@Test
public void getColumnCount() throws SQLException {
......@@ -206,8 +207,12 @@ public class RestfulResultSetMetaDataTest {
rs.close();
if (stmt != null)
stmt.close();
if (conn != null)
if (conn != null) {
Statement statement = conn.createStatement();
statement.execute("drop database if exists " + dbname);
statement.close();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
......
......@@ -1003,6 +1003,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) {
newCfg.daysToKeep0 = daysToKeep0;
}
#ifdef _STORAGE
if (daysToKeep1 > 0 && (daysToKeep1 != pDb->cfg.daysToKeep1 || newCfg.daysToKeep1 != pDb->cfg.daysToKeep1)) {
mDebug("db:%s, daysToKeep1:%d change to %d", pDb->name, pDb->cfg.daysToKeep1, daysToKeep1);
newCfg.daysToKeep1 = daysToKeep1;
......@@ -1012,6 +1013,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) {
mDebug("db:%s, daysToKeep2:%d change to %d", pDb->name, pDb->cfg.daysToKeep2, daysToKeep2);
newCfg.daysToKeep2 = daysToKeep2;
}
#endif
if (minRows > 0 && minRows != pDb->cfg.minRowsPerFileBlock) {
mError("db:%s, can't alter minRows option", pDb->name);
......@@ -1100,6 +1102,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) {
// community version can only change daysToKeep
// but enterprise version can change all daysToKeep options
#ifndef _STORAGE
newCfg.daysToKeep1 = newCfg.daysToKeep0;
newCfg.daysToKeep2 = newCfg.daysToKeep0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册