Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
adminstrot
TDengine
提交
cdf64f19
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,发现更多精彩内容 >>
提交
cdf64f19
编写于
6月 03, 2020
作者:
T
Tao Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-314] modify python connector to adapt the taos API change
上级
14333f31
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
76 addition
and
82 deletion
+76
-82
src/connector/python/linux/python3/taos/cinterface.py
src/connector/python/linux/python3/taos/cinterface.py
+19
-18
src/connector/python/linux/python3/taos/connection.py
src/connector/python/linux/python3/taos/connection.py
+1
-3
src/connector/python/linux/python3/taos/cursor.py
src/connector/python/linux/python3/taos/cursor.py
+8
-8
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+9
-8
src/kit/taosdump/taosdump.c
src/kit/taosdump/taosdump.c
+29
-28
tests/examples/c/demo.c
tests/examples/c/demo.c
+4
-11
tests/test/c/importOneRow.c
tests/test/c/importOneRow.c
+6
-6
未找到文件。
src/connector/python/linux/python3/taos/cinterface.py
浏览文件 @
cdf64f19
...
...
@@ -142,12 +142,13 @@ class CTaosInterface(object):
libtaos
.
taos_fetch_fields
.
restype
=
ctypes
.
POINTER
(
TaosField
)
libtaos
.
taos_init
.
restype
=
None
libtaos
.
taos_connect
.
restype
=
ctypes
.
c_void_p
libtaos
.
taos_use_result
.
restype
=
ctypes
.
c_void_p
#
libtaos.taos_use_result.restype = ctypes.c_void_p
libtaos
.
taos_fetch_row
.
restype
=
ctypes
.
POINTER
(
ctypes
.
c_void_p
)
libtaos
.
taos_errstr
.
restype
=
ctypes
.
c_char_p
libtaos
.
taos_subscribe
.
restype
=
ctypes
.
c_void_p
libtaos
.
taos_consume
.
restype
=
ctypes
.
c_void_p
libtaos
.
taos_fetch_lengths
.
restype
=
ctypes
.
c_void_p
libtaos
.
taos_free_result
.
restype
=
None
def
__init__
(
self
,
config
=
None
):
'''
...
...
@@ -249,12 +250,12 @@ class CTaosInterface(object):
raise
AttributeError
(
"sql is expected as a string"
)
# finally:
# CTaosInterface.libtaos.close(connection)
@
staticmethod
def
affectedRows
(
connection
):
def
affectedRows
(
result
):
"""The affected rows after runing query
"""
return
CTaosInterface
.
libtaos
.
taos_affected_rows
(
connection
)
return
CTaosInterface
.
libtaos
.
taos_affected_rows
(
result
)
@
staticmethod
def
subscribe
(
connection
,
restart
,
topic
,
sql
,
interval
):
...
...
@@ -292,18 +293,17 @@ class CTaosInterface(object):
CTaosInterface
.
libtaos
.
taos_unsubscribe
(
sub
,
1
if
keepProgress
else
0
)
@
staticmethod
def
useResult
(
connection
):
def
useResult
(
result
):
'''Use result after calling self.query
'''
result
=
ctypes
.
c_void_p
(
CTaosInterface
.
libtaos
.
taos_use_result
(
connection
))
fields
=
[]
pfields
=
CTaosInterface
.
fetchFields
(
result
)
for
i
in
range
(
CTaosInterface
.
fieldsCount
(
connection
)):
for
i
in
range
(
CTaosInterface
.
fieldsCount
(
result
)):
fields
.
append
({
'name'
:
pfields
[
i
].
name
.
decode
(
'utf-8'
),
'bytes'
:
pfields
[
i
].
bytes
,
'type'
:
ord
(
pfields
[
i
].
type
)})
return
result
,
fields
return
fields
@
staticmethod
def
fetchBlock
(
result
,
fields
):
...
...
@@ -337,8 +337,8 @@ class CTaosInterface(object):
result
.
value
=
None
@
staticmethod
def
fieldsCount
(
connection
):
return
CTaosInterface
.
libtaos
.
taos_field_count
(
connection
)
def
fieldsCount
(
result
):
return
CTaosInterface
.
libtaos
.
taos_field_count
(
result
)
@
staticmethod
def
fetchFields
(
result
):
...
...
@@ -386,29 +386,30 @@ class CTaosInterface(object):
# return (ctypes.cast(data, ctypes.c_char_p).value).rstrip('\x00')
@
staticmethod
def
errno
(
connection
):
def
errno
(
result
):
"""Return the error number.
"""
return
CTaosInterface
.
libtaos
.
taos_errno
(
connection
)
return
CTaosInterface
.
libtaos
.
taos_errno
(
result
)
@
staticmethod
def
errStr
(
connection
):
def
errStr
(
result
):
"""Return the error styring
"""
return
CTaosInterface
.
libtaos
.
taos_errstr
(
connection
).
decode
(
'utf-8'
)
return
CTaosInterface
.
libtaos
.
taos_errstr
(
result
).
decode
(
'utf-8'
)
if
__name__
==
'__main__'
:
cinter
=
CTaosInterface
()
conn
=
cinter
.
connect
()
result
=
cinter
.
query
(
conn
,
'show databases'
)
print
(
'Query return value: {}'
.
format
(
cinter
.
query
(
conn
,
'show databases'
)))
print
(
'Affected rows: {}'
.
format
(
cinter
.
affectedRows
(
conn
)))
print
(
'Query Affected rows: {}'
.
format
(
cinter
.
affectedRows
(
result
)))
result
,
des
=
CTaosInterface
.
useResult
(
conn
)
fields
=
CTaosInterface
.
useResult
(
result
)
data
,
num_of_rows
=
CTaosInterface
.
fetchBlock
(
result
,
de
s
)
data
,
num_of_rows
=
CTaosInterface
.
fetchBlock
(
result
,
field
s
)
print
(
data
)
cinter
.
freeresult
(
result
)
cinter
.
close
(
conn
)
\ No newline at end of file
src/connector/python/linux/python3/taos/connection.py
浏览文件 @
cdf64f19
...
...
@@ -78,9 +78,7 @@ class TDengineConnection(object):
def
clear_result_set
(
self
):
"""Clear unused result set on this connection.
"""
result
=
self
.
_chandle
.
useResult
(
self
.
_conn
)[
0
]
if
result
:
self
.
_chandle
.
freeResult
(
result
)
pass
if
__name__
==
"__main__"
:
conn
=
TDengineConnection
(
host
=
'192.168.1.107'
)
...
...
src/connector/python/linux/python3/taos/cursor.py
浏览文件 @
cdf64f19
...
...
@@ -122,26 +122,26 @@ class TDengineCursor(object):
# querySeqNum += 1
# localSeqNum = querySeqNum # avoid raice condition
# print(" >> Exec Query ({}): {}".format(localSeqNum, str(stmt)))
res
=
CTaosInterface
.
query
(
self
.
_connection
.
_conn
,
stmt
)
self
.
_result
=
CTaosInterface
.
query
(
self
.
_connection
.
_conn
,
stmt
)
# print(" << Query ({}) Exec Done".format(localSeqNum))
if
(
self
.
_logfile
):
with
open
(
self
.
_logfile
,
"a"
)
as
logfile
:
logfile
.
write
(
"%s;
\n
"
%
operation
)
if
res
==
0
:
if
CTaosInterface
.
fieldsCount
(
self
.
_
connection
.
_conn
)
==
0
:
if
self
.
_result
is
not
None
:
if
CTaosInterface
.
fieldsCount
(
self
.
_
result
)
==
0
:
self
.
_affected_rows
+=
CTaosInterface
.
affectedRows
(
self
.
_
connection
.
_conn
)
return
CTaosInterface
.
affectedRows
(
self
.
_
connection
.
_conn
)
self
.
_
result
)
return
CTaosInterface
.
affectedRows
(
self
.
_
result
)
else
:
self
.
_
result
,
self
.
_
fields
=
CTaosInterface
.
useResult
(
self
.
_
connection
.
_conn
)
self
.
_fields
=
CTaosInterface
.
useResult
(
self
.
_
result
)
return
self
.
_handle_result
()
else
:
raise
ProgrammingError
(
CTaosInterface
.
errStr
(
self
.
_
connection
.
_conn
))
self
.
_
result
))
def
executemany
(
self
,
operation
,
seq_of_parameters
):
"""Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.
...
...
src/kit/taosdemo/taosdemo.c
浏览文件 @
cdf64f19
...
...
@@ -708,13 +708,14 @@ void *readTable(void *sarg) {
sprintf
(
command
,
"select %s from %s%d where ts>= %"
PRId64
,
aggreFunc
[
j
],
tb_prefix
,
i
,
sTime
);
double
t
=
getCurrentTime
();
/*
if (taos_query(taos, command) != 0) {
fprintf(stderr, "Failed to query\n");
taos_close(taos);
exit(EXIT_FAILURE);
}
TAOS_RES
*
result
=
taos_
use_result
(
taos
)
;
*/
TAOS_RES
*
result
=
taos_
query
(
taos
,
command
)
;
if
(
result
==
NULL
)
{
fprintf
(
stderr
,
"Failed to retreive results:%s
\n
"
,
taos_errstr
(
taos
));
taos_close
(
taos
);
...
...
@@ -779,13 +780,13 @@ void *readMetric(void *sarg) {
fprintf
(
fp
,
"%s
\n
"
,
command
);
double
t
=
getCurrentTime
();
if
(
taos_query
(
taos
,
command
)
!=
0
)
{
fprintf
(
stderr
,
"Failed to query
\n
"
);
taos_close
(
taos
);
exit
(
EXIT_FAILURE
);
}
//
if (taos_query(taos, command) != 0) {
//
fprintf(stderr, "Failed to query\n");
//
taos_close(taos);
//
exit(EXIT_FAILURE);
//
}
TAOS_RES
*
result
=
taos_
use_result
(
taos
);
TAOS_RES
*
result
=
taos_
query
(
taos
,
command
);
if
(
result
==
NULL
)
{
fprintf
(
stderr
,
"Failed to retreive results:%s
\n
"
,
taos_errstr
(
taos
));
taos_close
(
taos
);
...
...
src/kit/taosdump/taosdump.c
浏览文件 @
cdf64f19
...
...
@@ -372,12 +372,13 @@ int taosGetTableRecordInfo(char *table, STableRecordInfo *pTableRecordInfo) {
memset
(
pTableRecordInfo
,
0
,
sizeof
(
STableRecordInfo
));
sprintf
(
command
,
"show tables like %s"
,
table
);
/*
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command %s\n", command);
return -1;
}
result
=
taos_
use_result
(
taos
)
;
*/
result
=
taos_
query
(
taos
,
command
)
;
if
(
result
==
NULL
)
{
fprintf
(
stderr
,
"failed to use result
\n
"
);
return
-
1
;
...
...
@@ -400,12 +401,12 @@ int taosGetTableRecordInfo(char *table, STableRecordInfo *pTableRecordInfo) {
if
(
isSet
)
return
0
;
sprintf
(
command
,
"show stables like %s"
,
table
);
if
(
taos_query
(
taos
,
command
)
!=
0
)
{
/*
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command %s\n", command);
return -1;
}
result
=
taos_
use_result
(
taos
);
*/
result
=
taos_
query
(
taos
,
command
);
if
(
result
==
NULL
)
{
fprintf
(
stderr
,
"failed to use result
\n
"
);
return
-
1
;
...
...
@@ -467,12 +468,12 @@ int taosDumpOut(SDumpArguments *arguments) {
taosDumpCharset
(
fp
);
sprintf
(
command
,
"show databases"
);
if
(
taos_query
(
taos
,
command
)
!=
0
)
{
/*
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command: %s, reason: %s\n", command, taos_errstr(taos));
goto _exit_failure;
}
}
*/
result
=
taos_
use_result
(
taos
);
result
=
taos_
query
(
taos
,
command
);
if
(
result
==
NULL
)
{
fprintf
(
stderr
,
"failed to use result
\n
"
);
goto
_exit_failure
;
...
...
@@ -551,7 +552,7 @@ int taosDumpOut(SDumpArguments *arguments) {
taosDumpCreateDbClause
(
dbInfos
[
0
],
arguments
->
with_property
,
fp
);
sprintf
(
command
,
"use %s"
,
dbInfos
[
0
]
->
name
);
if
(
taos_query
(
taos
,
command
)
!=
0
)
{
if
(
taos_query
(
taos
,
command
)
==
NULL
)
{
fprintf
(
stderr
,
"invalid database %s
\n
"
,
dbInfos
[
0
]
->
name
);
goto
_exit_failure
;
}
...
...
@@ -612,7 +613,7 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) {
taosDumpCreateDbClause
(
dbInfo
,
arguments
->
with_property
,
fp
);
sprintf
(
command
,
"use %s"
,
dbInfo
->
name
);
if
(
taos_query
(
taos
,
command
)
!=
0
)
{
if
(
taos_query
(
taos
,
command
)
==
NULL
)
{
fprintf
(
stderr
,
"invalid database %s
\n
"
,
dbInfo
->
name
);
return
-
1
;
}
...
...
@@ -620,12 +621,12 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) {
fprintf
(
fp
,
"USE %s
\n\n
"
,
dbInfo
->
name
);
sprintf
(
command
,
"show tables"
);
if
(
taos_query
(
taos
,
command
)
!=
0
)
{
/*
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command %s\n", command);
return -1;
}
}
*/
result
=
taos_
use_result
(
taos
);
result
=
taos_
query
(
taos
,
command
);
if
(
result
==
NULL
)
{
fprintf
(
stderr
,
"failed to use result
\n
"
);
return
-
1
;
...
...
@@ -725,12 +726,12 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols
TAOS_ROW
row
=
NULL
;
sprintf
(
command
,
"select %s from %s limit 1"
,
tableDes
->
cols
[
counter
].
field
,
tableDes
->
name
);
if
(
taos_query
(
taos
,
command
)
!=
0
)
{
/*
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command %s\n", command);
return;
}
}
*/
result
=
taos_
use_result
(
taos
);
result
=
taos_
query
(
taos
,
command
);
if
(
result
==
NULL
)
{
fprintf
(
stderr
,
"failed to use result
\n
"
);
return
;
...
...
@@ -806,12 +807,12 @@ int taosGetTableDes(char *table, STableDef *tableDes) {
int
count
=
0
;
sprintf
(
command
,
"describe %s"
,
table
);
if
(
taos_query
(
taos
,
command
)
!=
0
)
{
/*
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command %s\n", command);
return -1;
}
}
*/
result
=
taos_
use_result
(
taos
);
result
=
taos_
query
(
taos
,
command
);
if
(
result
==
NULL
)
{
fprintf
(
stderr
,
"failed to use result
\n
"
);
return
-
1
;
...
...
@@ -889,12 +890,12 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) {
strcpy
(
tableRecord
.
metric
,
metric
);
sprintf
(
command
,
"select tbname from %s"
,
metric
);
if
(
taos_query
(
taos
,
command
)
!=
0
)
{
/*
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command %s\n", command);
return -1;
}
}
*/
result
=
taos_
use_result
(
taos
);
result
=
taos_
query
(
taos
,
command
);
if
(
result
==
NULL
)
{
fprintf
(
stderr
,
"failed to use result
\n
"
);
return
-
1
;
...
...
@@ -942,12 +943,12 @@ int taosDumpTableData(FILE *fp, char *tbname, SDumpArguments *arguments) {
sprintf
(
command
,
"select * from %s where _c0 >= %"
PRId64
" and _c0 <= %"
PRId64
" order by _c0 asc"
,
tbname
,
arguments
->
start_time
,
arguments
->
end_time
);
if
(
taos_query
(
taos
,
command
)
!=
0
)
{
/*
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command %s, reason: %s\n", command, taos_errstr(taos));
return -1;
}
}
*/
result
=
taos_
use_result
(
taos
);
result
=
taos_
query
(
taos
,
command
);
if
(
result
==
NULL
)
{
fprintf
(
stderr
,
"failed to use result
\n
"
);
return
-
1
;
...
...
@@ -1194,7 +1195,7 @@ int taosDumpIn(SDumpArguments *arguments) {
tcommand
=
command
;
}
taosReplaceCtrlChar
(
tcommand
);
if
(
taos_query
(
taos
,
tcommand
)
!=
0
)
if
(
taos_query
(
taos
,
tcommand
)
==
NULL
)
fprintf
(
stderr
,
"linenu: %"
PRId64
" failed to run command %s reason:%s
\n
continue...
\n
"
,
linenu
,
command
,
taos_errstr
(
taos
));
...
...
@@ -1242,7 +1243,7 @@ int taosDumpIn(SDumpArguments *arguments) {
tcommand
=
command
;
}
taosReplaceCtrlChar
(
tcommand
);
if
(
taos_query
(
taos
,
tcommand
)
!=
0
)
if
(
taos_query
(
taos
,
tcommand
)
==
NULL
)
fprintf
(
stderr
,
"linenu:%"
PRId64
" failed to run command %s reason: %s
\n
continue...
\n
"
,
linenu
,
command
,
taos_errstr
(
taos
));
}
...
...
@@ -1265,7 +1266,7 @@ int taosDumpIn(SDumpArguments *arguments) {
tcommand
=
command
;
}
taosReplaceCtrlChar
(
lcommand
);
if
(
taos_query
(
taos
,
tcommand
)
!=
0
)
if
(
taos_query
(
taos
,
tcommand
)
==
NULL
)
fprintf
(
stderr
,
"linenu:%"
PRId64
" failed to run command %s reason:%s
\n
continue...
\n
"
,
linenu
,
command
,
taos_errstr
(
taos
));
}
...
...
tests/examples/c/demo.c
浏览文件 @
cdf64f19
...
...
@@ -26,13 +26,13 @@
void
taosMsleep
(
int
mseconds
);
static
int32_t
doQuery
(
TAOS
*
taos
,
const
char
*
sql
)
{
int32_t
code
=
taos_query
(
taos
,
sql
);
if
(
code
!=
0
)
{
TAOS_RES
*
res
=
taos_query
(
taos
,
sql
);
if
(
res
==
NULL
)
{
printf
(
"failed to execute query, reason:%s
\n
"
,
taos_errstr
(
taos
));
return
-
1
;
}
TAOS_RES
*
res
=
taos_use_result
(
taos
);
//
TAOS_RES* res = taos_use_result(taos);
TAOS_ROW
row
=
NULL
;
char
buf
[
512
]
=
{
0
};
...
...
@@ -167,15 +167,8 @@ int main(int argc, char *argv[]) {
// query the records
sprintf
(
qstr
,
"SELECT * FROM m1"
);
if
(
taos_query
(
taos
,
qstr
)
!=
0
)
{
printf
(
"failed to select, reason:%s
\n
"
,
taos_errstr
(
taos
));
exit
(
1
);
}
result
=
taos_use_result
(
taos
);
result
=
taos_query
(
taos
,
qstr
);
if
(
result
==
NULL
)
{
printf
(
"failed to get result, reason:%s
\n
"
,
taos_errstr
(
taos
));
exit
(
1
);
...
...
tests/test/c/importOneRow.c
浏览文件 @
cdf64f19
...
...
@@ -122,9 +122,9 @@ void* taos_execute(void *param) {
int64_t
timestamp
=
1530374400000L
;
sprintf
(
sql
,
"insert into db.t%d values(%ld, %d, %d, %d)"
,
pThread
->
index
,
timestamp
,
0
,
0
,
0
);
int
code
=
taos_query
(
taos
,
sql
);
if
(
code
!=
0
)
printf
(
"error code:%d, sql:%s
\n
"
,
code
,
sql
);
int
affectrows
=
taos_affected_rows
(
taos
);
void
*
result
=
taos_query
(
taos
,
sql
);
if
(
result
==
NULL
)
printf
(
"error , sql:%s
\n
"
,
sql
);
int
affectrows
=
taos_affected_rows
(
result
);
if
(
affectrows
!=
1
)
printf
(
"affect rows:%d, sql:%s
\n
"
,
affectrows
,
sql
);
timestamp
-=
1000
;
...
...
@@ -133,9 +133,9 @@ void* taos_execute(void *param) {
for
(
int
i
=
1
;
i
<
rowNum
;
++
i
)
{
sprintf
(
sql
,
"import into db.t%d values(%ld, %d, %d, %d)"
,
pThread
->
index
,
timestamp
,
i
,
i
,
i
);
code
=
taos_query
(
taos
,
sql
);
if
(
code
!=
0
)
printf
(
"error code:%d, sql:%s
\n
"
,
code
,
sql
);
int
affectrows
=
taos_affected_rows
(
taos
);
void
*
result
=
taos_query
(
taos
,
sql
);
if
(
result
==
NULL
)
printf
(
"error , sql:%s
\n
"
,
sql
);
int
affectrows
=
taos_affected_rows
(
result
);
if
(
affectrows
!=
1
)
printf
(
"affect rows:%d, sql:%s
\n
"
,
affectrows
,
sql
);
total_affect_rows
+=
affectrows
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录