Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
781c0ff6
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
781c0ff6
编写于
1月 13, 2020
作者:
weixin_48148422
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TBASE-1470: python3 & linux
上级
bae48b73
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
82 addition
and
1 deletion
+82
-1
src/connector/python/linux/python3/taos/cinterface.py
src/connector/python/linux/python3/taos/cinterface.py
+37
-0
src/connector/python/linux/python3/taos/connection.py
src/connector/python/linux/python3/taos/connection.py
+9
-1
src/connector/python/linux/python3/taos/subscription.py
src/connector/python/linux/python3/taos/subscription.py
+36
-0
未找到文件。
src/connector/python/linux/python3/taos/cinterface.py
浏览文件 @
781c0ff6
...
...
@@ -144,6 +144,8 @@ class CTaosInterface(object):
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
def
__init__
(
self
,
config
=
None
):
'''
...
...
@@ -252,6 +254,41 @@ class CTaosInterface(object):
"""
return
CTaosInterface
.
libtaos
.
taos_affected_rows
(
connection
)
@
staticmethod
def
subscribe
(
connection
,
restart
,
topic
,
sql
,
interval
):
"""Create a subscription
@restart boolean,
@sql string, sql statement for data query, must be a 'select' statement.
@topic string, name of this subscription
"""
return
ctypes
.
c_void_p
(
CTaosInterface
.
libtaos
.
taos_subscribe
(
connection
,
1
if
restart
else
0
,
ctypes
.
c_char_p
(
topic
.
encode
(
'utf-8'
)),
ctypes
.
c_char_p
(
sql
.
encode
(
'utf-8'
)),
None
,
None
,
interval
))
@
staticmethod
def
consume
(
sub
):
"""Consume data of a subscription
"""
result
=
ctypes
.
c_void_p
(
CTaosInterface
.
libtaos
.
taos_consume
(
sub
))
fields
=
[]
pfields
=
CTaosInterface
.
fetchFields
(
result
)
for
i
in
range
(
CTaosInterface
.
libtaos
.
taos_num_fields
(
result
)):
fields
.
append
({
'name'
:
pfields
[
i
].
name
.
decode
(
'utf-8'
),
'bytes'
:
pfields
[
i
].
bytes
,
'type'
:
ord
(
pfields
[
i
].
type
)})
return
result
,
fields
@
staticmethod
def
unsubscribe
(
sub
,
keepProgress
):
"""Cancel a subscription
"""
CTaosInterface
.
libtaos
.
taos_unsubscribe
(
sub
,
1
if
keepProgress
else
0
)
@
staticmethod
def
useResult
(
connection
):
'''Use result after calling self.query
...
...
src/connector/python/linux/python3/taos/connection.py
浏览文件 @
781c0ff6
# from .cursor import TDengineCursor
from
.cursor
import
TDengineCursor
from
.subscription
import
TDengineSubscription
from
.cinterface
import
CTaosInterface
class
TDengineConnection
(
object
):
...
...
@@ -50,6 +50,14 @@ class TDengineConnection(object):
"""
return
CTaosInterface
.
close
(
self
.
_conn
)
def
subscribe
(
self
,
restart
,
topic
,
sql
,
interval
):
"""Create a subscription.
"""
if
self
.
_conn
is
None
:
return
None
sub
=
CTaosInterface
.
subscribe
(
self
.
_conn
,
restart
,
topic
,
sql
,
interval
)
return
TDengineSubscription
(
sub
)
def
cursor
(
self
):
"""Return a new Cursor object using the connection.
"""
...
...
src/connector/python/linux/python3/taos/subscription.py
0 → 100644
浏览文件 @
781c0ff6
from
.cinterface
import
CTaosInterface
from
.error
import
*
class
TDengineSubscription
(
object
):
"""TDengine subscription object
"""
def
__init__
(
self
,
sub
):
self
.
_sub
=
sub
def
consume
(
self
):
"""Consume rows of a subscription
"""
if
self
.
_sub
is
None
:
raise
OperationalError
(
"Invalid use of consume"
)
result
,
fields
=
CTaosInterface
.
consume
(
self
.
_sub
)
buffer
=
[[]
for
i
in
range
(
len
(
fields
))]
print
(
buffer
)
while
True
:
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
result
,
fields
)
if
num_of_fields
==
0
:
break
for
i
in
range
(
len
(
fields
)):
buffer
[
i
].
extend
(
block
[
i
])
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
def
close
(
self
,
keepProgress
=
True
):
"""Close the Subscription.
"""
if
self
.
_sub
is
None
:
return
False
CTaosInterface
.
unsubscribe
(
self
.
_sub
,
keepProgress
)
return
True
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录