Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
adminstrot
TDengine
提交
123d4327
TDengine
项目概览
adminstrot
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
123d4327
编写于
6月 04, 2020
作者:
S
Shuaiqiang Chang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: jdbc resultset
上级
a7e7b8e2
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
75 addition
and
31 deletion
+75
-31
src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h
src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h
+1
-1
src/client/src/TSDBJNIConnector.c
src/client/src/TSDBJNIConnector.c
+11
-4
src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
...ain/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
+9
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+23
-18
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
...r/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
+9
-5
src/connector/python/linux/python3/test.py
src/connector/python/linux/python3/test.py
+21
-0
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+1
-2
未找到文件。
src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h
浏览文件 @
123d4327
...
...
@@ -71,7 +71,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp
* Signature: (J)I
*/
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp
(
JNIEnv
*
,
jobject
,
jlong
);
(
JNIEnv
*
,
jobject
,
jlong
,
jlong
);
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
...
...
src/client/src/TSDBJNIConnector.c
浏览文件 @
123d4327
...
...
@@ -305,14 +305,21 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(
return
(
jlong
)
pSql
;
}
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
con
)
{
JNIEXPORT
jint
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
con
,
jlong
tres
)
{
TAOS
*
tscon
=
(
TAOS
*
)
con
;
if
(
tscon
==
NULL
)
{
jniError
(
"jobj:%p, connection is closed"
,
jobj
);
return
(
jint
)
-
TSDB_CODE_INVALID_CONNECTION
;
return
(
jint
)
TSDB_CODE_INVALID_CONNECTION
;
}
return
(
jint
)
-
taos_errno
(
tscon
);
if
((
void
*
)
tres
==
NULL
)
{
jniError
(
"jobj:%p, conn:%p, resultset is null"
,
jobj
,
tscon
);
return
JNI_RESULT_SET_NULL
;
}
TAOS_RES
*
pSql
=
(
TAOS_RES
*
)
tres
;
return
(
jint
)
taos_errno
(
pSql
);
}
JNIEXPORT
jstring
JNICALL
Java_com_taosdata_jdbc_TSDBJNIConnector_getErrMsgImp
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
tres
)
{
...
...
@@ -464,7 +471,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn
TAOS_ROW
row
=
taos_fetch_row
(
result
);
if
(
row
==
NULL
)
{
int
tserrno
=
taos_errno
(
tscon
);
int
tserrno
=
taos_errno
(
result
);
if
(
tserrno
==
0
)
{
jniTrace
(
"jobj:%p, conn:%p, resultset:%p, fields size is %d, fetch row to the end"
,
jobj
,
tscon
,
res
,
num_fields
);
return
JNI_FETCH_END
;
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java
浏览文件 @
123d4327
...
...
@@ -18,8 +18,8 @@ import java.io.InputStream;
import
java.io.Reader
;
import
java.math.BigDecimal
;
import
java.net.URL
;
import
java.sql.*
;
import
java.sql.Date
;
import
java.sql.*
;
import
java.util.*
;
/*
...
...
@@ -102,41 +102,49 @@ public class DatabaseMetaDataResultSet implements ResultSet {
@Override
public
byte
getByte
(
int
columnIndex
)
throws
SQLException
{
columnIndex
--;
return
(
byte
)
rowCursor
.
getInt
(
columnIndex
,
columnMetaDataList
.
get
(
columnIndex
).
getColType
());
}
@Override
public
short
getShort
(
int
columnIndex
)
throws
SQLException
{
columnIndex
--;
return
(
short
)
rowCursor
.
getInt
(
columnIndex
,
columnMetaDataList
.
get
(
columnIndex
).
getColType
());
}
@Override
public
int
getInt
(
int
columnIndex
)
throws
SQLException
{
columnIndex
--;
return
rowCursor
.
getInt
(
columnIndex
,
columnMetaDataList
.
get
(
columnIndex
).
getColType
());
}
@Override
public
long
getLong
(
int
columnIndex
)
throws
SQLException
{
columnIndex
--;
return
rowCursor
.
getLong
(
columnIndex
,
columnMetaDataList
.
get
(
columnIndex
).
getColType
());
}
@Override
public
float
getFloat
(
int
columnIndex
)
throws
SQLException
{
columnIndex
--;
return
rowCursor
.
getFloat
(
columnIndex
,
columnMetaDataList
.
get
(
columnIndex
).
getColType
());
}
@Override
public
double
getDouble
(
int
columnIndex
)
throws
SQLException
{
columnIndex
--;
return
rowCursor
.
getDouble
(
columnIndex
,
columnMetaDataList
.
get
(
columnIndex
).
getColType
());
}
@Override
public
BigDecimal
getBigDecimal
(
int
columnIndex
,
int
scale
)
throws
SQLException
{
columnIndex
--;
return
new
BigDecimal
(
rowCursor
.
getDouble
(
columnIndex
,
columnMetaDataList
.
get
(
columnIndex
).
getColType
()));
}
@Override
public
byte
[]
getBytes
(
int
columnIndex
)
throws
SQLException
{
columnIndex
--;
return
(
rowCursor
.
getString
(
columnIndex
,
columnMetaDataList
.
get
(
columnIndex
).
getColType
())).
getBytes
();
}
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
浏览文件 @
123d4327
...
...
@@ -99,7 +99,7 @@ public class TSDBJNIConnector {
this
.
taos
=
this
.
connectImp
(
host
,
port
,
dbName
,
user
,
password
);
if
(
this
.
taos
==
TSDBConstants
.
JNI_NULL_POINTER
)
{
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
this
.
getErrMsg
(
)),
""
,
this
.
getErrCode
(
));
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
this
.
getErrMsg
(
null
)),
""
,
this
.
getErrCode
(
null
));
}
return
true
;
...
...
@@ -117,52 +117,57 @@ public class TSDBJNIConnector {
freeResultSet
(
taosResultSetPointer
);
}
int
code
;
long
pSql
=
0
l
;
try
{
code
=
this
.
executeQueryImp
(
sql
.
getBytes
(
TaosGlobalConfig
.
getCharset
()),
this
.
taos
);
pSql
=
this
.
executeQueryImp
(
sql
.
getBytes
(
TaosGlobalConfig
.
getCharset
()),
this
.
taos
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
this
.
freeResultSet
(
pSql
);
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
"Unsupported encoding"
));
}
int
code
=
this
.
getErrCode
(
pSql
);
affectedRows
=
code
;
if
(
code
<
0
)
{
affectedRows
=
-
1
;
if
(
code
==
TSDBConstants
.
JNI_TDENGINE_ERROR
)
{
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
this
.
getErrMsg
()),
""
,
this
.
getErrCode
());
this
.
freeResultSet
(
pSql
);
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
this
.
getErrMsg
(
pSql
)),
""
,
this
.
getErrCode
(
pSql
));
}
else
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
code
),
""
,
this
.
getErrCode
());
this
.
freeResultSet
(
pSql
);
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
code
),
""
,
this
.
getErrCode
(
pSql
));
}
}
// Try retrieving result set for the executed SQL using the current connection pointer. If the executed
// SQL is a DML/DDL which doesn't return a result set, then taosResultSetPointer should be 0L. Otherwise,
// taosResultSetPointer should be a non-zero value.
taosResultSetPointer
=
this
.
getResultSetImp
(
this
.
taos
);
taosResultSetPointer
=
this
.
getResultSetImp
(
this
.
taos
,
pSql
);
if
(
taosResultSetPointer
!=
TSDBConstants
.
JNI_NULL_POINTER
)
{
isResultsetClosed
=
false
;
}
return
code
;
}
private
native
int
executeQueryImp
(
byte
[]
sqlBytes
,
long
connection
);
private
native
long
executeQueryImp
(
byte
[]
sqlBytes
,
long
connection
);
/**
* Get recent error code by connection
*/
public
int
getErrCode
()
{
return
Math
.
abs
(
this
.
getErrCodeImp
(
this
.
taos
));
public
int
getErrCode
(
Long
pSql
)
{
return
Math
.
abs
(
this
.
getErrCodeImp
(
this
.
taos
,
pSql
));
}
private
native
int
getErrCodeImp
(
long
connection
);
private
native
int
getErrCodeImp
(
long
connection
,
Long
pSql
);
/**
* Get recent error message by connection
*/
public
String
getErrMsg
()
{
return
this
.
getErrMsgImp
(
this
.
taos
);
public
String
getErrMsg
(
Long
pSql
)
{
return
this
.
getErrMsgImp
(
this
.
taos
,
pSql
);
}
private
native
String
getErrMsgImp
(
long
connection
);
private
native
String
getErrMsgImp
(
long
connection
,
Long
pSql
);
/**
* Get resultset pointer
...
...
@@ -172,7 +177,7 @@ public class TSDBJNIConnector {
return
taosResultSetPointer
;
}
private
native
long
getResultSetImp
(
long
connection
);
private
native
long
getResultSetImp
(
long
connection
,
long
pSql
);
/**
* Free resultset operation from C to release resultset pointer by JNI
...
...
@@ -212,15 +217,15 @@ public class TSDBJNIConnector {
/**
* Get affected rows count
*/
public
int
getAffectedRows
()
{
public
int
getAffectedRows
(
Long
pSql
)
{
int
affectedRows
=
this
.
affectedRows
;
if
(
affectedRows
<
0
)
{
affectedRows
=
this
.
getAffectedRowsImp
(
this
.
taos
);
affectedRows
=
this
.
getAffectedRowsImp
(
this
.
taos
,
pSql
);
}
return
affectedRows
;
}
private
native
int
getAffectedRowsImp
(
long
connection
);
private
native
int
getAffectedRowsImp
(
long
connection
,
Long
pSql
);
/**
* Get schema metadata
...
...
@@ -248,7 +253,7 @@ public class TSDBJNIConnector {
public
void
closeConnection
()
throws
SQLException
{
int
code
=
this
.
closeConnectionImp
(
this
.
taos
);
if
(
code
<
0
)
{
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
code
),
""
,
this
.
getErrCode
());
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
code
),
""
,
this
.
getErrCode
(
null
));
}
else
if
(
code
==
0
)
{
this
.
taos
=
TSDBConstants
.
JNI_NULL_POINTER
;
}
else
{
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java
浏览文件 @
123d4327
...
...
@@ -27,6 +27,8 @@ public class TSDBStatement implements Statement {
/** Timeout for a query */
protected
int
queryTimeout
=
0
;
private
Long
pSql
=
0
l
;
/**
* Status of current statement
*/
...
...
@@ -66,21 +68,23 @@ public class TSDBStatement implements Statement {
if
(
isClosed
)
{
throw
new
SQLException
(
"Invalid method call on a closed statement."
);
}
int
res
=
this
.
connecter
.
executeQuery
(
sql
);
long
res
=
this
.
connecter
.
executeQuery
(
sql
);
long
resultSetPointer
=
this
.
connecter
.
getResultSet
();
if
(
resultSetPointer
==
TSDBConstants
.
JNI_CONNECTION_NULL
)
{
this
.
connecter
.
freeResultSet
(
res
);
throw
new
SQLException
(
TSDBConstants
.
FixErrMsg
(
TSDBConstants
.
JNI_CONNECTION_NULL
));
}
else
if
(
resultSetPointer
!=
TSDBConstants
.
JNI_NULL_POINTER
)
{
this
.
connecter
.
freeResultSet
();
throw
new
SQLException
(
"The executed SQL is not a DML or a DDL"
);
}
else
{
return
res
;
int
num
=
this
.
connecter
.
getAffectedRows
(
res
);
return
num
;
}
}
public
String
getErrorMsg
()
{
return
this
.
connecter
.
getErrMsg
();
public
String
getErrorMsg
(
long
pSql
)
{
return
this
.
connecter
.
getErrMsg
(
pSql
);
}
public
void
close
()
throws
SQLException
{
...
...
@@ -170,7 +174,7 @@ public class TSDBStatement implements Statement {
if
(
isClosed
)
{
throw
new
SQLException
(
"Invalid method call on a closed statement."
);
}
return
this
.
connecter
.
getAffectedRows
();
return
this
.
connecter
.
getAffectedRows
(
this
.
pSql
);
}
public
boolean
getMoreResults
()
throws
SQLException
{
...
...
src/connector/python/linux/python3/test.py
0 → 100644
浏览文件 @
123d4327
from
taos.cinterface
import
CTaosInterface
from
taos.error
import
*
from
taos.subscription
import
TDengineSubscription
from
taos.connection
import
TDengineConnection
if
__name__
==
'__main__'
:
conn
=
TDengineConnection
(
host
=
"127.0.0.1"
,
user
=
"root"
,
password
=
"taosdata"
,
database
=
"test"
)
# Generate a cursor object to run SQL commands
sub
=
conn
.
subscribe
(
False
,
"test"
,
"select * from log0601;"
,
1000
)
for
i
in
range
(
100
):
print
(
i
)
data
=
sub
.
consume
()
for
d
in
data
:
print
(
d
)
sub
.
close
()
conn
.
close
()
src/kit/taosdemo/taosdemo.c
浏览文件 @
123d4327
...
...
@@ -461,8 +461,7 @@ int main(int argc, char *argv[]) {
taos_init
();
TAOS
*
taos
=
taos_connect
(
ip_addr
,
user
,
pass
,
NULL
,
port
);
if
(
taos
==
NULL
)
{
fprintf
(
stderr
,
"Failed to connect to TDengine, reason:%s
\n
"
,
taos_errstr
(
taos
));
taos_close
(
taos
);
fprintf
(
stderr
,
"Failed to connect to TDengine, reason:%s
\n
"
,
taos_errstr
(
NULL
));
return
1
;
}
char
command
[
BUFFER_SIZE
]
=
"
\0
"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录