Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
511cdbea
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
511cdbea
编写于
5月 09, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-4038]
上级
a1fe6660
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
223 addition
and
144 deletion
+223
-144
src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h
src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h
+2
-2
src/client/src/TSDBJNIConnector.c
src/client/src/TSDBJNIConnector.c
+43
-7
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+2
-3
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+1
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
.../jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
+9
-5
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+13
-31
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
...rc/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
+115
-58
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
+34
-32
src/inc/taos.h
src/inc/taos.h
+4
-5
未找到文件。
src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h
浏览文件 @
511cdbea
...
...
@@ -204,10 +204,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setBindTableNameI
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
* Method: bindColDataImp
* Signature: (J[BIIIJ)J
* Signature: (J[B
[BI
IIIJ)J
*/
JNIEXPORT
jlong
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_bindColDataImp
(
JNIEnv
*
,
jobject
,
jlong
,
jbyteArray
,
jint
,
jint
,
jint
,
jlong
);
(
JNIEnv
*
,
jobject
,
jlong
,
jbyteArray
,
j
byteArray
,
jint
,
j
int
,
jint
,
jint
,
jlong
);
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
...
...
src/client/src/TSDBJNIConnector.c
浏览文件 @
511cdbea
...
...
@@ -746,14 +746,14 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setBindTableNameI
return
JNI_TDENGINE_ERROR
;
}
jniDebug
(
"jobj:%p, conn:%p, set stmt bind table name
"
,
jobj
,
tsconn
);
jniDebug
(
"jobj:%p, conn:%p, set stmt bind table name
:%s"
,
jobj
,
tsconn
,
name
);
(
*
env
)
->
ReleaseStringUTFChars
(
env
,
jname
,
name
);
return
JNI_SUCCESS
;
}
JNIEXPORT
jlong
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_bindColDataImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
stmt
,
jbyteArray
data
,
j
int
dataType
,
jint
numOfRows
,
jint
colIndex
,
jlong
con
)
{
jbyteArray
data
,
j
byteArray
length
,
jint
dataType
,
jint
dataBytes
,
jint
numOfRows
,
jint
colIndex
,
jlong
con
)
{
TAOS
*
tscon
=
(
TAOS
*
)
con
;
if
(
tscon
==
NULL
)
{
jniError
(
"jobj:%p, connection already closed"
,
jobj
);
...
...
@@ -766,15 +766,50 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_bindColDataImp(J
return
JNI_SQL_NULL
;
}
#if 0
TAOS_BIND* b = malloc(20);
b.num= jrows;
int32_t code = taos_stmt_bind_param_batch(stmt, b, colInex);
// todo refactor
jsize
len
=
(
*
env
)
->
GetArrayLength
(
env
,
data
);
char
*
colBuf
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
len
);
(
*
env
)
->
GetByteArrayRegion
(
env
,
data
,
0
,
len
,
(
jbyte
*
)
colBuf
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
// todo handle error
}
len
=
(
*
env
)
->
GetArrayLength
(
env
,
length
);
char
*
lengthArray
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
len
);
(
*
env
)
->
GetByteArrayRegion
(
env
,
length
,
0
,
len
,
(
jbyte
*
)
lengthArray
);
if
((
*
env
)
->
ExceptionCheck
(
env
))
{
}
// bind multi-rows with only one invoke.
TAOS_MULTI_BIND
*
b
=
calloc
(
1
,
sizeof
(
TAOS_MULTI_BIND
));
b
->
num
=
numOfRows
;
b
->
buffer_type
=
dataType
;
// todo check data type
b
->
buffer_length
=
tDataTypes
[
dataType
].
bytes
;
b
->
is_null
=
calloc
(
numOfRows
,
sizeof
(
int32_t
));
b
->
buffer
=
colBuf
;
b
->
length
=
(
uintptr_t
*
)
lengthArray
;
// set the length and is_null array
switch
(
dataType
)
{
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_BIGINT
:
{
int32_t
bytes
=
tDataTypes
[
dataType
].
bytes
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
b
->
length
[
i
]
=
bytes
;
b
->
is_null
[
i
]
=
isNull
(
colBuf
+
bytes
*
i
,
dataType
);
}
}
}
int32_t
code
=
taos_stmt_bind_single_param_batch
(
pStmt
,
b
,
colIndex
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
jniError
(
"jobj:%p, conn:%p, code:%s"
,
jobj
,
tscon
,
tstrerror
(
code
));
return
JNI_TDENGINE_ERROR
;
}
#endif
return
JNI_SUCCESS
;
}
...
...
@@ -792,6 +827,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeBatchImp(J
return
JNI_SQL_NULL
;
}
taos_stmt_add_batch
(
pStmt
);
int32_t
code
=
taos_stmt_execute
(
pStmt
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
jniError
(
"jobj:%p, conn:%p, code:%s"
,
jobj
,
tscon
,
tstrerror
(
code
));
...
...
src/client/src/tscPrepare.c
浏览文件 @
511cdbea
...
...
@@ -1306,10 +1306,9 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
}
pStmt
->
mtb
.
tbname
=
tscReplaceStrToken
(
&
pSql
->
sqlstr
,
&
pStmt
->
mtb
.
tbname
,
name
);
pStmt
->
mtb
.
nameSet
=
true
;
tscDebug
(
"
sqlstr set to %s"
,
pSql
->
sqlstr
);
tscDebug
(
"
0x%"
PRIx64
" SQL: %s"
,
pSql
->
self
,
pSql
->
sqlstr
);
pSql
->
cmd
.
parseFinished
=
0
;
pSql
->
cmd
.
numOfParams
=
0
;
...
...
@@ -1350,7 +1349,7 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
taosHashPut
(
pStmt
->
mtb
.
pTableHash
,
name
,
strlen
(
name
),
(
char
*
)
&
pTableMeta
->
id
.
uid
,
sizeof
(
pTableMeta
->
id
.
uid
));
tscDebug
(
"
table:%s is prepared, uid:%"
PRIu64
,
name
,
pStmt
->
mtb
.
currentUid
);
tscDebug
(
"
0x%"
PRIx64
" table:%s is prepared, uid:%"
PRIx64
,
pSql
->
self
,
name
,
pStmt
->
mtb
.
currentUid
);
}
return
code
;
...
...
src/client/src/tscUtil.c
浏览文件 @
511cdbea
...
...
@@ -1319,7 +1319,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, bool freeBlockMap) {
pBlocks
->
numOfRows
=
0
;
}
else
{
tscDebug
(
"
table %s data block is empty"
,
pOneTableBlock
->
tableName
.
tname
);
tscDebug
(
"
0x%"
PRIx64
" table %s data block is empty"
,
pSql
->
self
,
pOneTableBlock
->
tableName
.
tname
);
}
p
=
taosHashIterate
(
pCmd
->
pTableBlockHashList
,
p
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
浏览文件 @
511cdbea
...
...
@@ -49,7 +49,7 @@ public class TSDBConnection extends AbstractConnection {
this
.
databaseMetaData
.
setConnection
(
this
);
}
public
TSDBJNIConnector
getConnect
ion
()
{
public
TSDBJNIConnector
getConnect
or
()
{
return
this
.
connector
;
}
...
...
@@ -58,7 +58,7 @@ public class TSDBConnection extends AbstractConnection {
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
}
return
new
TSDBStatement
(
this
,
this
.
connector
);
return
new
TSDBStatement
(
this
);
}
public
TSDBSubscribe
subscribe
(
String
topic
,
String
sql
,
boolean
restart
)
throws
SQLException
{
...
...
@@ -74,14 +74,18 @@ public class TSDBConnection extends AbstractConnection {
}
public
PreparedStatement
prepareStatement
(
String
sql
)
throws
SQLException
{
if
(
isClosed
())
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_CONNECTION_CLOSED
);
return
new
TSDBPreparedStatement
(
this
,
this
.
connector
,
sql
);
}
return
new
TSDBPreparedStatement
(
this
,
sql
);
}
public
void
close
()
throws
SQLException
{
if
(
isClosed
)
if
(
isClosed
)
{
return
;
}
this
.
connector
.
closeConnection
();
this
.
isClosed
=
true
;
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
浏览文件 @
511cdbea
...
...
@@ -30,10 +30,13 @@ public class TSDBJNIConnector {
private
static
volatile
Boolean
isInitialized
=
false
;
private
TaosInfo
taosInfo
=
TaosInfo
.
getInstance
();
// Connection pointer used in C
private
long
taos
=
TSDBConstants
.
JNI_NULL_POINTER
;
// result set status in current connection
private
boolean
isResultsetClosed
=
true
;
private
int
affectedRows
=
-
1
;
static
{
...
...
@@ -163,37 +166,14 @@ public class TSDBJNIConnector {
private
native
long
isUpdateQueryImp
(
long
connection
,
long
pSql
);
/**
* Free result
set operation from C to release result
set pointer by JNI
* Free result
set operation from C to release result
set pointer by JNI
*/
public
int
freeResultSet
(
long
pSql
)
{
int
res
=
TSDBConstants
.
JNI_SUCCESS
;
// if (result != taosResultSetPointer && taosResultSetPointer != TSDBConstants.JNI_NULL_POINTER) {
// throw new RuntimeException("Invalid result set pointer");
// }
// if (taosResultSetPointer != TSDBConstants.JNI_NULL_POINTER) {
res
=
this
.
freeResultSetImp
(
this
.
taos
,
pSql
);
// taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER;
// }
int
res
=
this
.
freeResultSetImp
(
this
.
taos
,
pSql
);
isResultsetClosed
=
true
;
return
res
;
}
/**
* Close the open result set which is associated to the current connection. If the result set is already
* closed, return 0 for success.
*/
// public int freeResultSet() {
// int resCode = TSDBConstants.JNI_SUCCESS;
// if (!isResultsetClosed) {
// resCode = this.freeResultSetImp(this.taos, this.taosResultSetPointer);
// taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER;
// isResultsetClosed = true;
// }
// return resCode;
// }
private
native
int
freeResultSetImp
(
long
connection
,
long
result
);
/**
...
...
@@ -240,6 +220,7 @@ public class TSDBJNIConnector {
*/
public
void
closeConnection
()
throws
SQLException
{
int
code
=
this
.
closeConnectionImp
(
this
.
taos
);
if
(
code
<
0
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
else
if
(
code
==
0
)
{
...
...
@@ -247,6 +228,7 @@ public class TSDBJNIConnector {
}
else
{
throw
new
SQLException
(
"Undefined error code returned by TDengine when closing a connection"
);
}
// invoke closeConnectionImpl only here
taosInfo
.
connect_close_increment
();
}
...
...
@@ -283,7 +265,7 @@ public class TSDBJNIConnector {
private
native
void
unsubscribeImp
(
long
subscription
,
boolean
isKeep
);
/**
* Validate if a <I>create table</I>
sql
statement is correct without actually creating that table
* Validate if a <I>create table</I>
SQL
statement is correct without actually creating that table
*/
public
boolean
validateCreateTableSql
(
String
sql
)
{
int
res
=
validateCreateTableSqlImp
(
taos
,
sql
.
getBytes
());
...
...
@@ -295,7 +277,7 @@ public class TSDBJNIConnector {
public
long
prepareStmt
(
String
sql
)
throws
SQLException
{
Long
stmt
=
0L
;
try
{
stmt
=
prepareStmtImp
(
sql
,
this
.
taos
);
stmt
=
prepareStmtImp
(
sql
.
getBytes
()
,
this
.
taos
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNSUPPORTED_ENCODING
);
...
...
@@ -316,7 +298,7 @@ public class TSDBJNIConnector {
return
stmt
;
}
private
native
long
prepareStmtImp
(
String
sql
,
long
con
);
private
native
long
prepareStmtImp
(
byte
[]
sql
,
long
con
);
public
int
setBindTableName
(
long
stmt
,
String
tableName
)
{
return
setBindTableNameImp
(
stmt
,
tableName
,
this
.
taos
);
...
...
@@ -324,11 +306,11 @@ public class TSDBJNIConnector {
private
native
int
setBindTableNameImp
(
long
stmt
,
String
name
,
long
conn
);
public
int
bindColumnDataArray
(
long
stmt
,
byte
[]
data
,
int
type
,
int
numOfRows
,
int
columnIndex
)
{
return
bindColDataImp
(
stmt
,
data
,
type
,
numOfRows
,
columnIndex
,
this
.
taos
);
public
int
bindColumnDataArray
(
long
stmt
,
ByteBuffer
colList
,
ByteBuffer
lengthList
,
int
type
,
int
bytes
,
int
numOfRows
,
int
columnIndex
)
{
return
bindColDataImp
(
stmt
,
colList
.
array
(),
lengthList
.
array
(),
type
,
bytes
,
numOfRows
,
columnIndex
,
this
.
taos
);
}
private
native
int
bindColDataImp
(
long
stmt
,
byte
[]
data
,
int
type
,
int
numOfRows
,
int
columnIndex
,
long
conn
);
private
native
int
bindColDataImp
(
long
stmt
,
byte
[]
data
,
byte
[]
length
,
int
type
,
int
bytes
,
int
numOfRows
,
int
columnIndex
,
long
conn
);
public
int
executeBatch
(
long
stmt
)
{
return
executeBatchImp
(
stmt
,
this
.
taos
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
浏览文件 @
511cdbea
...
...
@@ -22,8 +22,7 @@ import java.io.Reader;
import
java.math.BigDecimal
;
import
java.net.URL
;
import
java.nio.ByteBuffer
;
import
java.nio.DoubleBuffer
;
import
java.nio.IntBuffer
;
import
java.nio.ByteOrder
;
import
java.sql.*
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
...
...
@@ -45,12 +44,12 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
private
int
type
;
private
String
tableName
;
private
long
nativeStmt
Ptr
=
0
;
private
long
nativeStmt
Handle
=
0
;
private
volatile
TSDBParameterMetaData
parameterMetaData
;
TSDBPreparedStatement
(
TSDBConnection
connection
,
TSDBJNIConnector
connector
,
String
sql
)
{
super
(
connection
,
connector
);
TSDBPreparedStatement
(
TSDBConnection
connection
,
String
sql
)
{
super
(
connection
);
init
(
sql
);
int
parameterCnt
=
0
;
...
...
@@ -64,8 +63,9 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
this
.
isPrepared
=
true
;
}
this
.
colData
=
new
ArrayList
<
ColumnInfo
>(
parameterCnt
);
this
.
colData
.
addAll
(
Collections
.
nCopies
(
parameterCnt
,
null
));
// the table name is also a parameter, so ignore it.
this
.
colData
=
new
ArrayList
<
ColumnInfo
>(
parameterCnt
-
1
);
this
.
colData
.
addAll
(
Collections
.
nCopies
(
parameterCnt
-
1
,
null
));
}
private
void
init
(
String
sql
)
{
...
...
@@ -543,12 +543,15 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
private
int
type
;
private
boolean
typeIsSet
;
public
void
C
lumnInfo
()
{
public
Co
lumnInfo
()
{
this
.
typeIsSet
=
false
;
}
public
void
setType
(
int
type
)
{
Assert
.
check
(!
this
.
typeIsSet
);
public
void
setType
(
int
type
)
throws
SQLException
{
if
(
this
.
isTypeSet
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"column data type has been set"
);
}
this
.
typeIsSet
=
true
;
this
.
type
=
type
;
}
...
...
@@ -562,106 +565,160 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
this
.
tableName
=
name
;
}
@SuppressWarnings
(
"unchecked"
)
public
void
setInt
(
int
columnIndex
,
ArrayList
<
Integer
>
list
)
throws
SQLException
{
public
<
T
>
void
setValueImpl
(
int
columnIndex
,
ArrayList
<
T
>
list
,
int
type
)
throws
SQLException
{
ColumnInfo
col
=
(
ColumnInfo
)
this
.
colData
.
get
(
columnIndex
);
if
(
col
==
null
)
{
ColumnInfo
p
=
new
ColumnInfo
();
p
.
setType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
p
.
data
=
(
ArrayList
)
list
.
clone
();
p
.
setType
(
type
);
p
.
data
=
(
ArrayList
<?>
)
list
.
clone
();
this
.
colData
.
set
(
columnIndex
,
p
);
}
else
{
if
(
col
.
type
!=
TSDBConstants
.
TSDB_DATA_TYPE_INT
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_
STATEMENT_CLOSED
);
if
(
col
.
type
!=
type
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_
UNKNOWN
,
"column data type mismatch"
);
}
col
.
data
.
addAll
(
list
);
}
}
@SuppressWarnings
(
"unchecked"
)
public
void
setFloat
(
int
columnIndex
,
ArrayList
<
Float
>
list
)
throws
SQLException
{
ColumnInfo
col
=
(
ColumnInfo
)
this
.
colData
.
get
(
columnIndex
);
if
(
col
==
null
)
{
ColumnInfo
p
=
new
ColumnInfo
();
p
.
setType
(
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
p
.
data
=
(
ArrayList
)
list
.
clone
();
this
.
colData
.
set
(
columnIndex
,
p
);
}
else
{
if
(
col
.
type
!=
TSDBConstants
.
TSDB_DATA_TYPE_INT
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
}
col
.
data
.
addAll
(
list
);
}
public
void
setInt
(
int
columnIndex
,
ArrayList
<
Integer
>
list
)
throws
SQLException
{
setValueImpl
(
columnIndex
,
list
,
TSDBConstants
.
TSDB_DATA_TYPE_INT
);
}
public
void
setFloat
(
int
columnIndex
,
ArrayList
<
Float
>
list
)
throws
SQLException
{
setValueImpl
(
columnIndex
,
list
,
TSDBConstants
.
TSDB_DATA_TYPE_FLOAT
);
}
public
void
setTimestamp
(
int
columnIndex
,
ArrayList
<
Long
>
list
)
throws
SQLException
{
setValueImpl
(
columnIndex
,
list
,
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
);
}
public
void
setLong
(
int
columnIndex
,
ArrayList
<
Long
>
list
)
throws
SQLException
{
setValueImpl
(
columnIndex
,
list
,
TSDBConstants
.
TSDB_DATA_TYPE_BIGINT
);
}
public
void
setDouble
(
int
columnIndex
,
ArrayList
<
Double
>
list
)
throws
SQLException
{
setValueImpl
(
columnIndex
,
list
,
TSDBConstants
.
TSDB_DATA_TYPE_DOUBLE
);
}
public
void
setBoolean
(
int
columnIndex
,
ArrayList
<
Boolean
>
list
)
throws
SQLException
{
setValueImpl
(
columnIndex
,
list
,
TSDBConstants
.
TSDB_DATA_TYPE_BOOL
);
}
public
void
addColumnDataBatch
()
{
public
void
setByte
(
int
columnIndex
,
ArrayList
<
Byte
>
list
)
throws
SQLException
{
setValueImpl
(
columnIndex
,
list
,
TSDBConstants
.
TSDB_DATA_TYPE_TINYINT
);
}
public
void
setShort
(
int
columnIndex
,
ArrayList
<
Short
>
list
)
throws
SQLException
{
setValueImpl
(
columnIndex
,
list
,
TSDBConstants
.
TSDB_DATA_TYPE_SMALLINT
);
}
public
void
setString
(
int
columnIndex
,
ArrayList
<
String
>
list
)
throws
SQLException
{
setValueImpl
(
columnIndex
,
list
,
TSDBConstants
.
TSDB_DATA_TYPE_BINARY
);
}
public
void
setNString
(
int
columnIndex
,
ArrayList
<
String
>
list
)
throws
SQLException
{
setValueImpl
(
columnIndex
,
list
,
TSDBConstants
.
TSDB_DATA_TYPE_NCHAR
);
}
public
void
columnDataAddBatch
()
{
// do nothing
}
public
void
columnDataExecuteBatch
()
{
int
size
=
this
.
colData
.
size
();
ColumnInfo
col
=
(
ColumnInfo
)
this
.
colData
.
get
(
0
);
int
rows
=
col
.
data
.
size
();
public
void
columnDataExecuteBatch
()
throws
SQLException
{
int
numOfCols
=
this
.
colData
.
size
();
int
rows
=
((
ColumnInfo
)
this
.
colData
.
get
(
0
)).
data
.
size
();
// pass the data block to native code
TSDBJNIConnector
conn
=
null
;
TSDBJNIConnector
conn
ector
=
null
;
try
{
conn
=
(
TSDBJNIConnector
)
this
.
getConnection
();
this
.
nativeStmtPtr
=
conn
.
prepareStmt
(
rawSql
);
conn
.
setBindTableName
(
this
.
nativeStmtPtr
,
this
.
tableName
);
connector
=
((
TSDBConnection
)
this
.
getConnection
()).
getConnector
();
this
.
nativeStmtHandle
=
connector
.
prepareStmt
(
rawSql
);
// table name is not set yet, abort
if
(
this
.
tableName
==
null
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"table name not set yet"
);
}
connector
.
setBindTableName
(
this
.
nativeStmtHandle
,
this
.
tableName
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
int
bytes
=
0
;
for
(
int
i
=
0
;
i
<
numOfCols
;
++
i
)
{
ColumnInfo
col1
=
this
.
colData
.
get
(
i
);
Assert
.
check
(
col
.
isTypeSet
());
ByteBuffer
ib
=
ByteBuffer
.
allocate
(
rows
);
if
(!
col1
.
isTypeSet
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"column data not bind"
);
}
if
(
rows
!=
col1
.
data
.
size
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_UNKNOWN
,
"the rows in column data not identical"
);
}
ByteBuffer
bbuf
=
null
;
ByteBuffer
lengthBuf
=
ByteBuffer
.
allocate
(
rows
*
Integer
.
BYTES
);
lengthBuf
.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
switch
(
col1
.
type
)
{
case
TSDBConstants
.
TSDB_DATA_TYPE_INT
:
{
bbuf
=
ByteBuffer
.
allocate
(
rows
*
Integer
.
BYTES
);
bbuf
.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
for
(
int
j
=
0
;
j
<
rows
;
++
j
)
{
Integer
val
=
(
Integer
)
col
.
data
.
get
(
j
);
Integer
val
=
(
Integer
)
col
1
.
data
.
get
(
j
);
if
(
val
==
null
)
{
ib
.
putInt
(
Integer
.
MIN_VALUE
);
bbuf
.
putInt
(
j
*
Integer
.
BYTES
,
Integer
.
MIN_VALUE
);
}
else
{
ib
.
putInt
((
int
)
col
.
data
.
get
(
j
)
);
bbuf
.
putInt
(
j
*
Integer
.
BYTES
,
val
);
}
lengthBuf
.
putInt
(
j
*
Integer
.
BYTES
,
Integer
.
BYTES
);
}
bytes
=
Integer
.
BYTES
;
break
;
}
case
TSDBConstants
.
TSDB_DATA_TYPE_TIMESTAMP
:
{
bbuf
=
ByteBuffer
.
allocate
(
rows
*
Long
.
BYTES
);
bbuf
.
order
(
ByteOrder
.
LITTLE_ENDIAN
);
for
(
int
j
=
0
;
j
<
rows
;
++
j
)
{
ib
.
putLong
((
long
)
col
.
data
.
get
(
j
));
Long
val
=
(
Long
)
col1
.
data
.
get
(
j
);
if
(
val
==
null
)
{
bbuf
.
putLong
(
j
*
Long
.
BYTES
,
Long
.
MIN_VALUE
);
}
else
{
bbuf
.
putLong
(
j
*
Long
.
BYTES
,
val
);
}
lengthBuf
.
putInt
(
j
*
Integer
.
BYTES
,
Long
.
BYTES
);
}
bytes
=
Long
.
BYTES
;
break
;
}
};
conn
.
bindColumnDataArray
(
this
.
nativeStmtPtr
,
ib
.
array
(),
col1
.
type
,
rows
,
i
);
conn
ector
.
bindColumnDataArray
(
this
.
nativeStmtHandle
,
bbuf
,
lengthBuf
,
col1
.
type
,
bytes
,
rows
,
i
);
}
conn
.
executeBatch
(
this
.
nativeStmtPtr
);
conn
ector
.
executeBatch
(
this
.
nativeStmtHandle
);
}
public
void
columnDataClearBatch
Clear
()
{
public
void
columnDataClearBatch
()
{
// TODO clear data in this.colData
}
public
void
c
lose
()
{
TSDBJNIConnector
conn
=
null
;
public
void
c
olumnDataCloseBatch
()
{
TSDBJNIConnector
conn
ector
=
null
;
try
{
conn
=
(
TSDBJNIConnector
)
this
.
getConnection
();
this
.
nativeStmtPtr
=
conn
.
prepareStmt
(
rawSql
);
conn
.
setBindTableName
(
this
.
nativeStmtPtr
,
this
.
tableName
);
connector
=
((
TSDBConnection
)
this
.
getConnection
()).
getConnector
();
connector
.
closeBatch
(
this
.
nativeStmtHandle
);
this
.
nativeStmtHandle
=
0L
;
this
.
tableName
=
null
;
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
conn
.
closeBatch
(
this
.
nativeStmtPtr
);
}
}
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
浏览文件 @
511cdbea
...
...
@@ -19,8 +19,6 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
public
class
TSDBStatement
extends
AbstractStatement
{
private
TSDBJNIConnector
connector
;
/**
* Status of current statement
*/
...
...
@@ -29,29 +27,26 @@ public class TSDBStatement extends AbstractStatement {
private
TSDBConnection
connection
;
private
TSDBResultSet
resultSet
;
public
void
setConnection
(
TSDBConnection
connection
)
{
this
.
connection
=
connection
;
}
TSDBStatement
(
TSDBConnection
connection
,
TSDBJNIConnector
connector
)
{
TSDBStatement
(
TSDBConnection
connection
)
{
this
.
connection
=
connection
;
this
.
connector
=
connector
;
}
public
ResultSet
executeQuery
(
String
sql
)
throws
SQLException
{
// check if closed
if
(
isClosed
())
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
}
//TODO: 如果在executeQuery方法中执行insert语句,那么先执行了SQL,再通过pSql来检查是否为一个insert语句,但这个insert SQL已经执行成功了
// execute query
long
pSql
=
this
.
connect
or
.
executeQuery
(
sql
);
long
pSql
=
this
.
connect
ion
.
getConnector
()
.
executeQuery
(
sql
);
// if pSql is create/insert/update/delete/alter SQL
if
(
this
.
connect
or
.
isUpdateQuery
(
pSql
))
{
this
.
connect
or
.
freeResultSet
(
pSql
);
if
(
this
.
connect
ion
.
getConnector
()
.
isUpdateQuery
(
pSql
))
{
this
.
connect
ion
.
getConnector
()
.
freeResultSet
(
pSql
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_WITH_EXECUTEQUERY
);
}
TSDBResultSet
res
=
new
TSDBResultSet
(
this
,
this
.
connect
or
,
pSql
);
TSDBResultSet
res
=
new
TSDBResultSet
(
this
,
this
.
connect
ion
.
getConnector
()
,
pSql
);
res
.
setBatchFetch
(
this
.
connection
.
getBatchFetch
());
return
res
;
}
...
...
@@ -60,14 +55,14 @@ public class TSDBStatement extends AbstractStatement {
if
(
isClosed
())
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
long
pSql
=
this
.
connect
or
.
executeQuery
(
sql
);
long
pSql
=
this
.
connect
ion
.
getConnector
()
.
executeQuery
(
sql
);
// if pSql is create/insert/update/delete/alter SQL
if
(!
this
.
connect
or
.
isUpdateQuery
(
pSql
))
{
this
.
connect
or
.
freeResultSet
(
pSql
);
if
(!
this
.
connect
ion
.
getConnector
()
.
isUpdateQuery
(
pSql
))
{
this
.
connect
ion
.
getConnector
()
.
freeResultSet
(
pSql
);
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_INVALID_WITH_EXECUTEUPDATE
);
}
int
affectedRows
=
this
.
connect
or
.
getAffectedRows
(
pSql
);
this
.
connect
or
.
freeResultSet
(
pSql
);
int
affectedRows
=
this
.
connect
ion
.
getConnector
()
.
getAffectedRows
(
pSql
);
this
.
connect
ion
.
getConnector
()
.
freeResultSet
(
pSql
);
return
affectedRows
;
}
...
...
@@ -81,30 +76,29 @@ public class TSDBStatement extends AbstractStatement {
public
boolean
execute
(
String
sql
)
throws
SQLException
{
// check if closed
if
(
isClosed
())
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
}
// execute query
long
pSql
=
this
.
connect
or
.
executeQuery
(
sql
);
long
pSql
=
this
.
connect
ion
.
getConnector
()
.
executeQuery
(
sql
);
// if pSql is create/insert/update/delete/alter SQL
if
(
this
.
connect
or
.
isUpdateQuery
(
pSql
))
{
this
.
affectedRows
=
this
.
connect
or
.
getAffectedRows
(
pSql
);
this
.
connect
or
.
freeResultSet
(
pSql
);
if
(
this
.
connect
ion
.
getConnector
()
.
isUpdateQuery
(
pSql
))
{
this
.
affectedRows
=
this
.
connect
ion
.
getConnector
()
.
getAffectedRows
(
pSql
);
this
.
connect
ion
.
getConnector
()
.
freeResultSet
(
pSql
);
return
false
;
}
this
.
resultSet
=
new
TSDBResultSet
(
this
,
this
.
connect
or
,
pSql
);
this
.
resultSet
=
new
TSDBResultSet
(
this
,
this
.
connect
ion
.
getConnector
()
,
pSql
);
this
.
resultSet
.
setBatchFetch
(
this
.
connection
.
getBatchFetch
());
return
true
;
}
public
ResultSet
getResultSet
()
throws
SQLException
{
if
(
isClosed
())
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
// long resultSetPointer = connector.getResultSet();
// TSDBResultSet resSet = null;
// if (resultSetPointer != TSDBConstants.JNI_NULL_POINTER) {
// resSet = new TSDBResultSet(connector, resultSetPointer);
// }
}
return
this
.
resultSet
;
}
...
...
@@ -115,12 +109,20 @@ public class TSDBStatement extends AbstractStatement {
}
public
Connection
getConnection
()
throws
SQLException
{
if
(
isClosed
())
if
(
isClosed
())
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_STATEMENT_CLOSED
);
if
(
this
.
connector
==
null
)
}
if
(
this
.
connection
.
getConnector
()
==
null
)
{
throw
TSDBError
.
createSQLException
(
TSDBErrorNumbers
.
ERROR_JNI_CONNECTION_NULL
);
}
return
this
.
connection
;
}
public
void
setConnection
(
TSDBConnection
connection
)
{
this
.
connection
=
connection
;
}
public
boolean
isClosed
()
throws
SQLException
{
return
isClosed
;
...
...
src/inc/taos.h
浏览文件 @
511cdbea
...
...
@@ -102,11 +102,10 @@ typedef struct TAOS_BIND {
typedef
struct
TAOS_MULTI_BIND
{
int
buffer_type
;
void
*
buffer
;
uintptr_t
buffer_length
;
// unused
uintptr_t
*
length
;
int
*
is_null
;
void
*
buffer
;
uintptr_t
buffer_length
;
uintptr_t
*
length
;
int
*
is_null
;
int
num
;
}
TAOS_MULTI_BIND
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录