Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
42efe016
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
42efe016
编写于
2月 19, 2021
作者:
sangshuduo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-2971] feature: make python connector support unsigned type. fix pep8 format.
上级
8904a046
变更
25
展开全部
显示空白变更内容
内联
并排
Showing
25 changed file
with
838 addition
and
344 deletion
+838
-344
src/connector/python/linux/python2/taos/__init__.py
src/connector/python/linux/python2/taos/__init__.py
+1
-0
src/connector/python/linux/python2/taos/cinterface.py
src/connector/python/linux/python2/taos/cinterface.py
+212
-87
src/connector/python/linux/python2/taos/connection.py
src/connector/python/linux/python2/taos/connection.py
+13
-4
src/connector/python/linux/python2/taos/constants.py
src/connector/python/linux/python2/taos/constants.py
+1
-0
src/connector/python/linux/python2/taos/cursor.py
src/connector/python/linux/python2/taos/cursor.py
+15
-6
src/connector/python/linux/python2/taos/dbapi.py
src/connector/python/linux/python2/taos/dbapi.py
+7
-1
src/connector/python/linux/python2/taos/error.py
src/connector/python/linux/python2/taos/error.py
+13
-4
src/connector/python/linux/python2/taos/subscription.py
src/connector/python/linux/python2/taos/subscription.py
+14
-9
src/connector/python/linux/python3/taos/__init__.py
src/connector/python/linux/python3/taos/__init__.py
+1
-0
src/connector/python/linux/python3/taos/cinterface.py
src/connector/python/linux/python3/taos/cinterface.py
+212
-87
src/connector/python/linux/python3/taos/connection.py
src/connector/python/linux/python3/taos/connection.py
+13
-4
src/connector/python/linux/python3/taos/constants.py
src/connector/python/linux/python3/taos/constants.py
+1
-0
src/connector/python/linux/python3/taos/cursor.py
src/connector/python/linux/python3/taos/cursor.py
+20
-12
src/connector/python/linux/python3/taos/dbapi.py
src/connector/python/linux/python3/taos/dbapi.py
+7
-1
src/connector/python/linux/python3/taos/error.py
src/connector/python/linux/python3/taos/error.py
+13
-4
src/connector/python/linux/python3/taos/subscription.py
src/connector/python/linux/python3/taos/subscription.py
+13
-8
src/connector/python/osx/python3/taos/__init__.py
src/connector/python/osx/python3/taos/__init__.py
+1
-0
src/connector/python/osx/python3/taos/cinterface.py
src/connector/python/osx/python3/taos/cinterface.py
+212
-87
src/connector/python/osx/python3/taos/connection.py
src/connector/python/osx/python3/taos/connection.py
+13
-4
src/connector/python/osx/python3/taos/constants.py
src/connector/python/osx/python3/taos/constants.py
+1
-0
src/connector/python/osx/python3/taos/cursor.py
src/connector/python/osx/python3/taos/cursor.py
+20
-12
src/connector/python/osx/python3/taos/dbapi.py
src/connector/python/osx/python3/taos/dbapi.py
+7
-1
src/connector/python/osx/python3/taos/error.py
src/connector/python/osx/python3/taos/error.py
+13
-4
src/connector/python/osx/python3/taos/subscription.py
src/connector/python/osx/python3/taos/subscription.py
+13
-8
tests/pytest/insert/basic_unsigned.py
tests/pytest/insert/basic_unsigned.py
+2
-1
未找到文件。
src/connector/python/linux/python2/taos/__init__.py
浏览文件 @
42efe016
...
@@ -8,6 +8,7 @@ paramstyle = 'pyformat'
...
@@ -8,6 +8,7 @@ paramstyle = 'pyformat'
__all__
=
[
'connection'
,
'cursor'
]
__all__
=
[
'connection'
,
'cursor'
]
def
connect
(
*
args
,
**
kwargs
):
def
connect
(
*
args
,
**
kwargs
):
""" Function to return a TDengine connector object
""" Function to return a TDengine connector object
...
...
src/connector/python/linux/python2/taos/cinterface.py
浏览文件 @
42efe016
此差异已折叠。
点击以展开。
src/connector/python/linux/python2/taos/connection.py
浏览文件 @
42efe016
...
@@ -2,9 +2,11 @@ from .cursor import TDengineCursor
...
@@ -2,9 +2,11 @@ from .cursor import TDengineCursor
from
.subscription
import
TDengineSubscription
from
.subscription
import
TDengineSubscription
from
.cinterface
import
CTaosInterface
from
.cinterface
import
CTaosInterface
class
TDengineConnection
(
object
):
class
TDengineConnection
(
object
):
""" TDengine connection object
""" TDengine connection object
"""
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
_conn
=
None
self
.
_conn
=
None
self
.
_host
=
None
self
.
_host
=
None
...
@@ -43,7 +45,12 @@ class TDengineConnection(object):
...
@@ -43,7 +45,12 @@ class TDengineConnection(object):
self
.
_config
=
kwargs
[
'config'
]
self
.
_config
=
kwargs
[
'config'
]
self
.
_chandle
=
CTaosInterface
(
self
.
_config
)
self
.
_chandle
=
CTaosInterface
(
self
.
_config
)
self
.
_conn
=
self
.
_chandle
.
connect
(
self
.
_host
,
self
.
_user
,
self
.
_password
,
self
.
_database
,
self
.
_port
)
self
.
_conn
=
self
.
_chandle
.
connect
(
self
.
_host
,
self
.
_user
,
self
.
_password
,
self
.
_database
,
self
.
_port
)
def
close
(
self
):
def
close
(
self
):
"""Close current connection.
"""Close current connection.
...
@@ -55,7 +62,8 @@ class TDengineConnection(object):
...
@@ -55,7 +62,8 @@ class TDengineConnection(object):
"""
"""
if
self
.
_conn
is
None
:
if
self
.
_conn
is
None
:
return
None
return
None
sub
=
CTaosInterface
.
subscribe
(
self
.
_conn
,
restart
,
topic
,
sql
,
interval
)
sub
=
CTaosInterface
.
subscribe
(
self
.
_conn
,
restart
,
topic
,
sql
,
interval
)
return
TDengineSubscription
(
sub
)
return
TDengineSubscription
(
sub
)
def
cursor
(
self
):
def
cursor
(
self
):
...
@@ -80,6 +88,7 @@ class TDengineConnection(object):
...
@@ -80,6 +88,7 @@ class TDengineConnection(object):
"""
"""
pass
pass
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
conn
=
TDengineConnection
(
host
=
'192.168.1.107'
)
conn
=
TDengineConnection
(
host
=
'192.168.1.107'
)
conn
.
close
()
conn
.
close
()
...
...
src/connector/python/linux/python2/taos/constants.py
浏览文件 @
42efe016
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
from
.dbapi
import
*
from
.dbapi
import
*
class
FieldType
(
object
):
class
FieldType
(
object
):
"""TDengine Field Types
"""TDengine Field Types
"""
"""
...
...
src/connector/python/linux/python2/taos/cursor.py
浏览文件 @
42efe016
...
@@ -128,8 +128,8 @@ class TDengineCursor(object):
...
@@ -128,8 +128,8 @@ class TDengineCursor(object):
if
errno
==
0
:
if
errno
==
0
:
if
CTaosInterface
.
fieldsCount
(
self
.
_result
)
==
0
:
if
CTaosInterface
.
fieldsCount
(
self
.
_result
)
==
0
:
self
.
_affected_rows
+=
CTaosInterface
.
affectedRows
(
self
.
_affected_rows
+=
CTaosInterface
.
affectedRows
(
self
.
_result
)
self
.
_result
)
return
CTaosInterface
.
affectedRows
(
self
.
_result
)
return
CTaosInterface
.
affectedRows
(
self
.
_result
)
else
:
else
:
self
.
_fields
=
CTaosInterface
.
useResult
(
self
.
_fields
=
CTaosInterface
.
useResult
(
self
.
_result
)
self
.
_result
)
...
@@ -148,6 +148,7 @@ class TDengineCursor(object):
...
@@ -148,6 +148,7 @@ class TDengineCursor(object):
"""Fetch the next row of a query result set, returning a single sequence, or None when no more data is available.
"""Fetch the next row of a query result set, returning a single sequence, or None when no more data is available.
"""
"""
pass
pass
def
fetchmany
(
self
):
def
fetchmany
(
self
):
pass
pass
...
@@ -206,16 +207,20 @@ class TDengineCursor(object):
...
@@ -206,16 +207,20 @@ class TDengineCursor(object):
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
self
.
_rowcount
=
0
self
.
_rowcount
=
0
while
True
:
while
True
:
block
,
num_of_fields
=
CTaosInterface
.
fetchRow
(
self
.
_result
,
self
.
_fields
)
block
,
num_of_fields
=
CTaosInterface
.
fetchRow
(
self
.
_result
,
self
.
_fields
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
if
errno
!=
0
:
if
errno
!=
0
:
raise
ProgrammingError
(
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
raise
ProgrammingError
(
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
if
num_of_fields
==
0
:
if
num_of_fields
==
0
:
break
break
self
.
_rowcount
+=
num_of_fields
self
.
_rowcount
+=
num_of_fields
for
i
in
range
(
len
(
self
.
_fields
)):
for
i
in
range
(
len
(
self
.
_fields
)):
buffer
[
i
].
extend
(
block
[
i
])
buffer
[
i
].
extend
(
block
[
i
])
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
def
fetchall
(
self
):
def
fetchall
(
self
):
if
self
.
_result
is
None
or
self
.
_fields
is
None
:
if
self
.
_result
is
None
or
self
.
_fields
is
None
:
raise
OperationalError
(
"Invalid use of fetchall"
)
raise
OperationalError
(
"Invalid use of fetchall"
)
...
@@ -223,16 +228,20 @@ class TDengineCursor(object):
...
@@ -223,16 +228,20 @@ class TDengineCursor(object):
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
self
.
_rowcount
=
0
self
.
_rowcount
=
0
while
True
:
while
True
:
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
self
.
_result
,
self
.
_fields
)
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
self
.
_result
,
self
.
_fields
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
if
errno
!=
0
:
if
errno
!=
0
:
raise
ProgrammingError
(
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
raise
ProgrammingError
(
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
if
num_of_fields
==
0
:
if
num_of_fields
==
0
:
break
break
self
.
_rowcount
+=
num_of_fields
self
.
_rowcount
+=
num_of_fields
for
i
in
range
(
len
(
self
.
_fields
)):
for
i
in
range
(
len
(
self
.
_fields
)):
buffer
[
i
].
extend
(
block
[
i
])
buffer
[
i
].
extend
(
block
[
i
])
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
def
nextset
(
self
):
def
nextset
(
self
):
"""
"""
"""
"""
...
...
src/connector/python/linux/python2/taos/dbapi.py
浏览文件 @
42efe016
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
import
time
import
time
import
datetime
import
datetime
class
DBAPITypeObject
(
object
):
class
DBAPITypeObject
(
object
):
def
__init__
(
self
,
*
values
):
def
__init__
(
self
,
*
values
):
self
.
values
=
values
self
.
values
=
values
...
@@ -16,19 +17,24 @@ class DBAPITypeObject(object):
...
@@ -16,19 +17,24 @@ class DBAPITypeObject(object):
else
:
else
:
return
-
1
return
-
1
Date
=
datetime
.
date
Date
=
datetime
.
date
Time
=
datetime
.
time
Time
=
datetime
.
time
Timestamp
=
datetime
.
datetime
Timestamp
=
datetime
.
datetime
def
DataFromTicks
(
ticks
):
def
DataFromTicks
(
ticks
):
return
Date
(
*
time
.
localtime
(
ticks
)[:
3
])
return
Date
(
*
time
.
localtime
(
ticks
)[:
3
])
def
TimeFromTicks
(
ticks
):
def
TimeFromTicks
(
ticks
):
return
Time
(
*
time
.
localtime
(
ticks
)[
3
:
6
])
return
Time
(
*
time
.
localtime
(
ticks
)[
3
:
6
])
def
TimestampFromTicks
(
ticks
):
def
TimestampFromTicks
(
ticks
):
return
Timestamp
(
*
time
.
localtime
(
ticks
)[:
6
])
return
Timestamp
(
*
time
.
localtime
(
ticks
)[:
6
])
Binary
=
bytes
Binary
=
bytes
# STRING = DBAPITypeObject(*constants.FieldType.get_string_types())
# STRING = DBAPITypeObject(*constants.FieldType.get_string_types())
...
...
src/connector/python/linux/python2/taos/error.py
浏览文件 @
42efe016
"""Python exceptions
"""Python exceptions
"""
"""
class
Error
(
Exception
):
class
Error
(
Exception
):
def
__init__
(
self
,
msg
=
None
,
errno
=
None
):
def
__init__
(
self
,
msg
=
None
,
errno
=
None
):
self
.
msg
=
msg
self
.
msg
=
msg
...
@@ -10,26 +11,31 @@ class Error(Exception):
...
@@ -10,26 +11,31 @@ class Error(Exception):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
_full_msg
return
self
.
_full_msg
class
Warning
(
Exception
):
class
Warning
(
Exception
):
"""Exception raised for important warnings like data truncations while inserting.
"""Exception raised for important warnings like data truncations while inserting.
"""
"""
pass
pass
class
InterfaceError
(
Error
):
class
InterfaceError
(
Error
):
"""Exception raised for errors that are related to the database interface rather than the database itself.
"""Exception raised for errors that are related to the database interface rather than the database itself.
"""
"""
pass
pass
class
DatabaseError
(
Error
):
class
DatabaseError
(
Error
):
"""Exception raised for errors that are related to the database.
"""Exception raised for errors that are related to the database.
"""
"""
pass
pass
class
DataError
(
DatabaseError
):
class
DataError
(
DatabaseError
):
"""Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range.
"""Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range.
"""
"""
pass
pass
class
OperationalError
(
DatabaseError
):
class
OperationalError
(
DatabaseError
):
"""Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer
"""Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer
"""
"""
...
@@ -41,16 +47,19 @@ class IntegrityError(DatabaseError):
...
@@ -41,16 +47,19 @@ class IntegrityError(DatabaseError):
"""
"""
pass
pass
class
InternalError
(
DatabaseError
):
class
InternalError
(
DatabaseError
):
"""Exception raised when the database encounters an internal error.
"""Exception raised when the database encounters an internal error.
"""
"""
pass
pass
class
ProgrammingError
(
DatabaseError
):
class
ProgrammingError
(
DatabaseError
):
"""Exception raised for programming errors.
"""Exception raised for programming errors.
"""
"""
pass
pass
class
NotSupportedError
(
DatabaseError
):
class
NotSupportedError
(
DatabaseError
):
"""Exception raised in case a method or database API was used which is not supported by the database,.
"""Exception raised in case a method or database API was used which is not supported by the database,.
"""
"""
...
...
src/connector/python/linux/python2/taos/subscription.py
浏览文件 @
42efe016
from
.cinterface
import
CTaosInterface
from
.cinterface
import
CTaosInterface
from
.error
import
*
from
.error
import
*
class
TDengineSubscription
(
object
):
class
TDengineSubscription
(
object
):
"""TDengine subscription object
"""TDengine subscription object
"""
"""
def
__init__
(
self
,
sub
):
def
__init__
(
self
,
sub
):
self
.
_sub
=
sub
self
.
_sub
=
sub
def
consume
(
self
):
def
consume
(
self
):
"""Consume rows of a subscription
"""Consume rows of a subscription
"""
"""
...
@@ -18,15 +19,15 @@ class TDengineSubscription(object):
...
@@ -18,15 +19,15 @@ class TDengineSubscription(object):
buffer
=
[[]
for
i
in
range
(
len
(
fields
))]
buffer
=
[[]
for
i
in
range
(
len
(
fields
))]
while
True
:
while
True
:
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
result
,
fields
)
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
result
,
fields
)
if
num_of_fields
==
0
:
break
if
num_of_fields
==
0
:
break
for
i
in
range
(
len
(
fields
)):
for
i
in
range
(
len
(
fields
)):
buffer
[
i
].
extend
(
block
[
i
])
buffer
[
i
].
extend
(
block
[
i
])
self
.
fields
=
fields
self
.
fields
=
fields
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
def
close
(
self
,
keepProgress
=
True
):
def
close
(
self
,
keepProgress
=
True
):
"""Close the Subscription.
"""Close the Subscription.
"""
"""
if
self
.
_sub
is
None
:
if
self
.
_sub
is
None
:
...
@@ -38,12 +39,16 @@ class TDengineSubscription(object):
...
@@ -38,12 +39,16 @@ class TDengineSubscription(object):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
.connection
import
TDengineConnection
from
.connection
import
TDengineConnection
conn
=
TDengineConnection
(
host
=
"127.0.0.1"
,
user
=
"root"
,
password
=
"taosdata"
,
database
=
"test"
)
conn
=
TDengineConnection
(
host
=
"127.0.0.1"
,
user
=
"root"
,
password
=
"taosdata"
,
database
=
"test"
)
# Generate a cursor object to run SQL commands
# Generate a cursor object to run SQL commands
sub
=
conn
.
subscribe
(
True
,
"test"
,
"select * from meters;"
,
1000
)
sub
=
conn
.
subscribe
(
True
,
"test"
,
"select * from meters;"
,
1000
)
for
i
in
range
(
0
,
10
):
for
i
in
range
(
0
,
10
):
data
=
sub
.
consume
()
data
=
sub
.
consume
()
for
d
in
data
:
for
d
in
data
:
print
(
d
)
print
(
d
)
...
...
src/connector/python/linux/python3/taos/__init__.py
浏览文件 @
42efe016
...
@@ -8,6 +8,7 @@ paramstyle = 'pyformat'
...
@@ -8,6 +8,7 @@ paramstyle = 'pyformat'
__all__
=
[
'connection'
,
'cursor'
]
__all__
=
[
'connection'
,
'cursor'
]
def
connect
(
*
args
,
**
kwargs
):
def
connect
(
*
args
,
**
kwargs
):
""" Function to return a TDengine connector object
""" Function to return a TDengine connector object
...
...
src/connector/python/linux/python3/taos/cinterface.py
浏览文件 @
42efe016
此差异已折叠。
点击以展开。
src/connector/python/linux/python3/taos/connection.py
浏览文件 @
42efe016
...
@@ -2,9 +2,11 @@ from .cursor import TDengineCursor
...
@@ -2,9 +2,11 @@ from .cursor import TDengineCursor
from
.subscription
import
TDengineSubscription
from
.subscription
import
TDengineSubscription
from
.cinterface
import
CTaosInterface
from
.cinterface
import
CTaosInterface
class
TDengineConnection
(
object
):
class
TDengineConnection
(
object
):
""" TDengine connection object
""" TDengine connection object
"""
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
_conn
=
None
self
.
_conn
=
None
self
.
_host
=
None
self
.
_host
=
None
...
@@ -43,7 +45,12 @@ class TDengineConnection(object):
...
@@ -43,7 +45,12 @@ class TDengineConnection(object):
self
.
_config
=
kwargs
[
'config'
]
self
.
_config
=
kwargs
[
'config'
]
self
.
_chandle
=
CTaosInterface
(
self
.
_config
)
self
.
_chandle
=
CTaosInterface
(
self
.
_config
)
self
.
_conn
=
self
.
_chandle
.
connect
(
self
.
_host
,
self
.
_user
,
self
.
_password
,
self
.
_database
,
self
.
_port
)
self
.
_conn
=
self
.
_chandle
.
connect
(
self
.
_host
,
self
.
_user
,
self
.
_password
,
self
.
_database
,
self
.
_port
)
def
close
(
self
):
def
close
(
self
):
"""Close current connection.
"""Close current connection.
...
@@ -55,7 +62,8 @@ class TDengineConnection(object):
...
@@ -55,7 +62,8 @@ class TDengineConnection(object):
"""
"""
if
self
.
_conn
is
None
:
if
self
.
_conn
is
None
:
return
None
return
None
sub
=
CTaosInterface
.
subscribe
(
self
.
_conn
,
restart
,
topic
,
sql
,
interval
)
sub
=
CTaosInterface
.
subscribe
(
self
.
_conn
,
restart
,
topic
,
sql
,
interval
)
return
TDengineSubscription
(
sub
)
return
TDengineSubscription
(
sub
)
def
cursor
(
self
):
def
cursor
(
self
):
...
@@ -80,6 +88,7 @@ class TDengineConnection(object):
...
@@ -80,6 +88,7 @@ class TDengineConnection(object):
"""
"""
pass
pass
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
conn
=
TDengineConnection
(
host
=
'192.168.1.107'
)
conn
=
TDengineConnection
(
host
=
'192.168.1.107'
)
conn
.
close
()
conn
.
close
()
...
...
src/connector/python/linux/python3/taos/constants.py
浏览文件 @
42efe016
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
from
.dbapi
import
*
from
.dbapi
import
*
class
FieldType
(
object
):
class
FieldType
(
object
):
"""TDengine Field Types
"""TDengine Field Types
"""
"""
...
...
src/connector/python/linux/python3/taos/cursor.py
浏览文件 @
42efe016
...
@@ -5,6 +5,7 @@ import threading
...
@@ -5,6 +5,7 @@ import threading
# querySeqNum = 0
# querySeqNum = 0
class
TDengineCursor
(
object
):
class
TDengineCursor
(
object
):
"""Database cursor which is used to manage the context of a fetch operation.
"""Database cursor which is used to manage the context of a fetch operation.
...
@@ -137,8 +138,8 @@ class TDengineCursor(object):
...
@@ -137,8 +138,8 @@ class TDengineCursor(object):
if
errno
==
0
:
if
errno
==
0
:
if
CTaosInterface
.
fieldsCount
(
self
.
_result
)
==
0
:
if
CTaosInterface
.
fieldsCount
(
self
.
_result
)
==
0
:
self
.
_affected_rows
+=
CTaosInterface
.
affectedRows
(
self
.
_affected_rows
+=
CTaosInterface
.
affectedRows
(
self
.
_result
)
self
.
_result
)
return
CTaosInterface
.
affectedRows
(
self
.
_result
)
return
CTaosInterface
.
affectedRows
(
self
.
_result
)
else
:
else
:
self
.
_fields
=
CTaosInterface
.
useResult
(
self
.
_fields
=
CTaosInterface
.
useResult
(
self
.
_result
)
self
.
_result
)
...
@@ -216,10 +217,13 @@ class TDengineCursor(object):
...
@@ -216,10 +217,13 @@ class TDengineCursor(object):
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
self
.
_rowcount
=
0
self
.
_rowcount
=
0
while
True
:
while
True
:
block
,
num_of_fields
=
CTaosInterface
.
fetchRow
(
self
.
_result
,
self
.
_fields
)
block
,
num_of_fields
=
CTaosInterface
.
fetchRow
(
self
.
_result
,
self
.
_fields
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
if
errno
!=
0
:
if
errno
!=
0
:
raise
ProgrammingError
(
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
raise
ProgrammingError
(
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
if
num_of_fields
==
0
:
if
num_of_fields
==
0
:
break
break
self
.
_rowcount
+=
num_of_fields
self
.
_rowcount
+=
num_of_fields
...
@@ -234,15 +238,20 @@ class TDengineCursor(object):
...
@@ -234,15 +238,20 @@ class TDengineCursor(object):
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
self
.
_rowcount
=
0
self
.
_rowcount
=
0
while
True
:
while
True
:
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
self
.
_result
,
self
.
_fields
)
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
self
.
_result
,
self
.
_fields
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
if
errno
!=
0
:
if
errno
!=
0
:
raise
ProgrammingError
(
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
raise
ProgrammingError
(
if
num_of_fields
==
0
:
break
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
if
num_of_fields
==
0
:
break
self
.
_rowcount
+=
num_of_fields
self
.
_rowcount
+=
num_of_fields
for
i
in
range
(
len
(
self
.
_fields
)):
for
i
in
range
(
len
(
self
.
_fields
)):
buffer
[
i
].
extend
(
block
[
i
])
buffer
[
i
].
extend
(
block
[
i
])
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
def
nextset
(
self
):
def
nextset
(
self
):
"""
"""
"""
"""
...
@@ -283,4 +292,3 @@ class TDengineCursor(object):
...
@@ -283,4 +292,3 @@ class TDengineCursor(object):
(
ele
[
'name'
],
ele
[
'type'
],
None
,
None
,
None
,
None
,
False
))
(
ele
[
'name'
],
ele
[
'type'
],
None
,
None
,
None
,
None
,
False
))
return
self
.
_result
return
self
.
_result
src/connector/python/linux/python3/taos/dbapi.py
浏览文件 @
42efe016
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
import
time
import
time
import
datetime
import
datetime
class
DBAPITypeObject
(
object
):
class
DBAPITypeObject
(
object
):
def
__init__
(
self
,
*
values
):
def
__init__
(
self
,
*
values
):
self
.
values
=
values
self
.
values
=
values
...
@@ -16,19 +17,24 @@ class DBAPITypeObject(object):
...
@@ -16,19 +17,24 @@ class DBAPITypeObject(object):
else
:
else
:
return
-
1
return
-
1
Date
=
datetime
.
date
Date
=
datetime
.
date
Time
=
datetime
.
time
Time
=
datetime
.
time
Timestamp
=
datetime
.
datetime
Timestamp
=
datetime
.
datetime
def
DataFromTicks
(
ticks
):
def
DataFromTicks
(
ticks
):
return
Date
(
*
time
.
localtime
(
ticks
)[:
3
])
return
Date
(
*
time
.
localtime
(
ticks
)[:
3
])
def
TimeFromTicks
(
ticks
):
def
TimeFromTicks
(
ticks
):
return
Time
(
*
time
.
localtime
(
ticks
)[
3
:
6
])
return
Time
(
*
time
.
localtime
(
ticks
)[
3
:
6
])
def
TimestampFromTicks
(
ticks
):
def
TimestampFromTicks
(
ticks
):
return
Timestamp
(
*
time
.
localtime
(
ticks
)[:
6
])
return
Timestamp
(
*
time
.
localtime
(
ticks
)[:
6
])
Binary
=
bytes
Binary
=
bytes
# STRING = DBAPITypeObject(*constants.FieldType.get_string_types())
# STRING = DBAPITypeObject(*constants.FieldType.get_string_types())
...
...
src/connector/python/linux/python3/taos/error.py
浏览文件 @
42efe016
"""Python exceptions
"""Python exceptions
"""
"""
class
Error
(
Exception
):
class
Error
(
Exception
):
def
__init__
(
self
,
msg
=
None
,
errno
=
None
):
def
__init__
(
self
,
msg
=
None
,
errno
=
None
):
self
.
msg
=
msg
self
.
msg
=
msg
...
@@ -10,26 +11,31 @@ class Error(Exception):
...
@@ -10,26 +11,31 @@ class Error(Exception):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
_full_msg
return
self
.
_full_msg
class
Warning
(
Exception
):
class
Warning
(
Exception
):
"""Exception raised for important warnings like data truncations while inserting.
"""Exception raised for important warnings like data truncations while inserting.
"""
"""
pass
pass
class
InterfaceError
(
Error
):
class
InterfaceError
(
Error
):
"""Exception raised for errors that are related to the database interface rather than the database itself.
"""Exception raised for errors that are related to the database interface rather than the database itself.
"""
"""
pass
pass
class
DatabaseError
(
Error
):
class
DatabaseError
(
Error
):
"""Exception raised for errors that are related to the database.
"""Exception raised for errors that are related to the database.
"""
"""
pass
pass
class
DataError
(
DatabaseError
):
class
DataError
(
DatabaseError
):
"""Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range.
"""Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range.
"""
"""
pass
pass
class
OperationalError
(
DatabaseError
):
class
OperationalError
(
DatabaseError
):
"""Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer
"""Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer
"""
"""
...
@@ -41,16 +47,19 @@ class IntegrityError(DatabaseError):
...
@@ -41,16 +47,19 @@ class IntegrityError(DatabaseError):
"""
"""
pass
pass
class
InternalError
(
DatabaseError
):
class
InternalError
(
DatabaseError
):
"""Exception raised when the database encounters an internal error.
"""Exception raised when the database encounters an internal error.
"""
"""
pass
pass
class
ProgrammingError
(
DatabaseError
):
class
ProgrammingError
(
DatabaseError
):
"""Exception raised for programming errors.
"""Exception raised for programming errors.
"""
"""
pass
pass
class
NotSupportedError
(
DatabaseError
):
class
NotSupportedError
(
DatabaseError
):
"""Exception raised in case a method or database API was used which is not supported by the database,.
"""Exception raised in case a method or database API was used which is not supported by the database,.
"""
"""
...
...
src/connector/python/linux/python3/taos/subscription.py
浏览文件 @
42efe016
from
.cinterface
import
CTaosInterface
from
.cinterface
import
CTaosInterface
from
.error
import
*
from
.error
import
*
class
TDengineSubscription
(
object
):
class
TDengineSubscription
(
object
):
"""TDengine subscription object
"""TDengine subscription object
"""
"""
def
__init__
(
self
,
sub
):
def
__init__
(
self
,
sub
):
self
.
_sub
=
sub
self
.
_sub
=
sub
def
consume
(
self
):
def
consume
(
self
):
"""Consume rows of a subscription
"""Consume rows of a subscription
"""
"""
...
@@ -18,15 +19,15 @@ class TDengineSubscription(object):
...
@@ -18,15 +19,15 @@ class TDengineSubscription(object):
buffer
=
[[]
for
i
in
range
(
len
(
fields
))]
buffer
=
[[]
for
i
in
range
(
len
(
fields
))]
while
True
:
while
True
:
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
result
,
fields
)
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
result
,
fields
)
if
num_of_fields
==
0
:
break
if
num_of_fields
==
0
:
break
for
i
in
range
(
len
(
fields
)):
for
i
in
range
(
len
(
fields
)):
buffer
[
i
].
extend
(
block
[
i
])
buffer
[
i
].
extend
(
block
[
i
])
self
.
fields
=
fields
self
.
fields
=
fields
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
def
close
(
self
,
keepProgress
=
True
):
def
close
(
self
,
keepProgress
=
True
):
"""Close the Subscription.
"""Close the Subscription.
"""
"""
if
self
.
_sub
is
None
:
if
self
.
_sub
is
None
:
...
@@ -38,12 +39,16 @@ class TDengineSubscription(object):
...
@@ -38,12 +39,16 @@ class TDengineSubscription(object):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
.connection
import
TDengineConnection
from
.connection
import
TDengineConnection
conn
=
TDengineConnection
(
host
=
"127.0.0.1"
,
user
=
"root"
,
password
=
"taosdata"
,
database
=
"test"
)
conn
=
TDengineConnection
(
host
=
"127.0.0.1"
,
user
=
"root"
,
password
=
"taosdata"
,
database
=
"test"
)
# Generate a cursor object to run SQL commands
# Generate a cursor object to run SQL commands
sub
=
conn
.
subscribe
(
True
,
"test"
,
"select * from meters;"
,
1000
)
sub
=
conn
.
subscribe
(
True
,
"test"
,
"select * from meters;"
,
1000
)
for
i
in
range
(
0
,
10
):
for
i
in
range
(
0
,
10
):
data
=
sub
.
consume
()
data
=
sub
.
consume
()
for
d
in
data
:
for
d
in
data
:
print
(
d
)
print
(
d
)
...
...
src/connector/python/osx/python3/taos/__init__.py
浏览文件 @
42efe016
...
@@ -8,6 +8,7 @@ paramstyle = 'pyformat'
...
@@ -8,6 +8,7 @@ paramstyle = 'pyformat'
__all__
=
[
'connection'
,
'cursor'
]
__all__
=
[
'connection'
,
'cursor'
]
def
connect
(
*
args
,
**
kwargs
):
def
connect
(
*
args
,
**
kwargs
):
""" Function to return a TDengine connector object
""" Function to return a TDengine connector object
...
...
src/connector/python/osx/python3/taos/cinterface.py
浏览文件 @
42efe016
此差异已折叠。
点击以展开。
src/connector/python/osx/python3/taos/connection.py
浏览文件 @
42efe016
...
@@ -2,9 +2,11 @@ from .cursor import TDengineCursor
...
@@ -2,9 +2,11 @@ from .cursor import TDengineCursor
from
.subscription
import
TDengineSubscription
from
.subscription
import
TDengineSubscription
from
.cinterface
import
CTaosInterface
from
.cinterface
import
CTaosInterface
class
TDengineConnection
(
object
):
class
TDengineConnection
(
object
):
""" TDengine connection object
""" TDengine connection object
"""
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
_conn
=
None
self
.
_conn
=
None
self
.
_host
=
None
self
.
_host
=
None
...
@@ -43,7 +45,12 @@ class TDengineConnection(object):
...
@@ -43,7 +45,12 @@ class TDengineConnection(object):
self
.
_config
=
kwargs
[
'config'
]
self
.
_config
=
kwargs
[
'config'
]
self
.
_chandle
=
CTaosInterface
(
self
.
_config
)
self
.
_chandle
=
CTaosInterface
(
self
.
_config
)
self
.
_conn
=
self
.
_chandle
.
connect
(
self
.
_host
,
self
.
_user
,
self
.
_password
,
self
.
_database
,
self
.
_port
)
self
.
_conn
=
self
.
_chandle
.
connect
(
self
.
_host
,
self
.
_user
,
self
.
_password
,
self
.
_database
,
self
.
_port
)
def
close
(
self
):
def
close
(
self
):
"""Close current connection.
"""Close current connection.
...
@@ -55,7 +62,8 @@ class TDengineConnection(object):
...
@@ -55,7 +62,8 @@ class TDengineConnection(object):
"""
"""
if
self
.
_conn
is
None
:
if
self
.
_conn
is
None
:
return
None
return
None
sub
=
CTaosInterface
.
subscribe
(
self
.
_conn
,
restart
,
topic
,
sql
,
interval
)
sub
=
CTaosInterface
.
subscribe
(
self
.
_conn
,
restart
,
topic
,
sql
,
interval
)
return
TDengineSubscription
(
sub
)
return
TDengineSubscription
(
sub
)
def
cursor
(
self
):
def
cursor
(
self
):
...
@@ -80,6 +88,7 @@ class TDengineConnection(object):
...
@@ -80,6 +88,7 @@ class TDengineConnection(object):
"""
"""
pass
pass
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
conn
=
TDengineConnection
(
host
=
'192.168.1.107'
)
conn
=
TDengineConnection
(
host
=
'192.168.1.107'
)
conn
.
close
()
conn
.
close
()
...
...
src/connector/python/osx/python3/taos/constants.py
浏览文件 @
42efe016
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
from
.dbapi
import
*
from
.dbapi
import
*
class
FieldType
(
object
):
class
FieldType
(
object
):
"""TDengine Field Types
"""TDengine Field Types
"""
"""
...
...
src/connector/python/osx/python3/taos/cursor.py
浏览文件 @
42efe016
...
@@ -5,6 +5,7 @@ import threading
...
@@ -5,6 +5,7 @@ import threading
# querySeqNum = 0
# querySeqNum = 0
class
TDengineCursor
(
object
):
class
TDengineCursor
(
object
):
"""Database cursor which is used to manage the context of a fetch operation.
"""Database cursor which is used to manage the context of a fetch operation.
...
@@ -137,8 +138,8 @@ class TDengineCursor(object):
...
@@ -137,8 +138,8 @@ class TDengineCursor(object):
if
errno
==
0
:
if
errno
==
0
:
if
CTaosInterface
.
fieldsCount
(
self
.
_result
)
==
0
:
if
CTaosInterface
.
fieldsCount
(
self
.
_result
)
==
0
:
self
.
_affected_rows
+=
CTaosInterface
.
affectedRows
(
self
.
_affected_rows
+=
CTaosInterface
.
affectedRows
(
self
.
_result
)
self
.
_result
)
return
CTaosInterface
.
affectedRows
(
self
.
_result
)
return
CTaosInterface
.
affectedRows
(
self
.
_result
)
else
:
else
:
self
.
_fields
=
CTaosInterface
.
useResult
(
self
.
_fields
=
CTaosInterface
.
useResult
(
self
.
_result
)
self
.
_result
)
...
@@ -216,10 +217,13 @@ class TDengineCursor(object):
...
@@ -216,10 +217,13 @@ class TDengineCursor(object):
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
self
.
_rowcount
=
0
self
.
_rowcount
=
0
while
True
:
while
True
:
block
,
num_of_fields
=
CTaosInterface
.
fetchRow
(
self
.
_result
,
self
.
_fields
)
block
,
num_of_fields
=
CTaosInterface
.
fetchRow
(
self
.
_result
,
self
.
_fields
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
if
errno
!=
0
:
if
errno
!=
0
:
raise
ProgrammingError
(
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
raise
ProgrammingError
(
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
if
num_of_fields
==
0
:
if
num_of_fields
==
0
:
break
break
self
.
_rowcount
+=
num_of_fields
self
.
_rowcount
+=
num_of_fields
...
@@ -234,15 +238,20 @@ class TDengineCursor(object):
...
@@ -234,15 +238,20 @@ class TDengineCursor(object):
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
buffer
=
[[]
for
i
in
range
(
len
(
self
.
_fields
))]
self
.
_rowcount
=
0
self
.
_rowcount
=
0
while
True
:
while
True
:
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
self
.
_result
,
self
.
_fields
)
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
self
.
_result
,
self
.
_fields
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
errno
=
CTaosInterface
.
libtaos
.
taos_errno
(
self
.
_result
)
if
errno
!=
0
:
if
errno
!=
0
:
raise
ProgrammingError
(
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
raise
ProgrammingError
(
if
num_of_fields
==
0
:
break
CTaosInterface
.
errStr
(
self
.
_result
),
errno
)
if
num_of_fields
==
0
:
break
self
.
_rowcount
+=
num_of_fields
self
.
_rowcount
+=
num_of_fields
for
i
in
range
(
len
(
self
.
_fields
)):
for
i
in
range
(
len
(
self
.
_fields
)):
buffer
[
i
].
extend
(
block
[
i
])
buffer
[
i
].
extend
(
block
[
i
])
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
def
nextset
(
self
):
def
nextset
(
self
):
"""
"""
"""
"""
...
@@ -283,4 +292,3 @@ class TDengineCursor(object):
...
@@ -283,4 +292,3 @@ class TDengineCursor(object):
(
ele
[
'name'
],
ele
[
'type'
],
None
,
None
,
None
,
None
,
False
))
(
ele
[
'name'
],
ele
[
'type'
],
None
,
None
,
None
,
None
,
False
))
return
self
.
_result
return
self
.
_result
src/connector/python/osx/python3/taos/dbapi.py
浏览文件 @
42efe016
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
import
time
import
time
import
datetime
import
datetime
class
DBAPITypeObject
(
object
):
class
DBAPITypeObject
(
object
):
def
__init__
(
self
,
*
values
):
def
__init__
(
self
,
*
values
):
self
.
values
=
values
self
.
values
=
values
...
@@ -16,19 +17,24 @@ class DBAPITypeObject(object):
...
@@ -16,19 +17,24 @@ class DBAPITypeObject(object):
else
:
else
:
return
-
1
return
-
1
Date
=
datetime
.
date
Date
=
datetime
.
date
Time
=
datetime
.
time
Time
=
datetime
.
time
Timestamp
=
datetime
.
datetime
Timestamp
=
datetime
.
datetime
def
DataFromTicks
(
ticks
):
def
DataFromTicks
(
ticks
):
return
Date
(
*
time
.
localtime
(
ticks
)[:
3
])
return
Date
(
*
time
.
localtime
(
ticks
)[:
3
])
def
TimeFromTicks
(
ticks
):
def
TimeFromTicks
(
ticks
):
return
Time
(
*
time
.
localtime
(
ticks
)[
3
:
6
])
return
Time
(
*
time
.
localtime
(
ticks
)[
3
:
6
])
def
TimestampFromTicks
(
ticks
):
def
TimestampFromTicks
(
ticks
):
return
Timestamp
(
*
time
.
localtime
(
ticks
)[:
6
])
return
Timestamp
(
*
time
.
localtime
(
ticks
)[:
6
])
Binary
=
bytes
Binary
=
bytes
# STRING = DBAPITypeObject(*constants.FieldType.get_string_types())
# STRING = DBAPITypeObject(*constants.FieldType.get_string_types())
...
...
src/connector/python/osx/python3/taos/error.py
浏览文件 @
42efe016
"""Python exceptions
"""Python exceptions
"""
"""
class
Error
(
Exception
):
class
Error
(
Exception
):
def
__init__
(
self
,
msg
=
None
,
errno
=
None
):
def
__init__
(
self
,
msg
=
None
,
errno
=
None
):
self
.
msg
=
msg
self
.
msg
=
msg
...
@@ -10,26 +11,31 @@ class Error(Exception):
...
@@ -10,26 +11,31 @@ class Error(Exception):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
_full_msg
return
self
.
_full_msg
class
Warning
(
Exception
):
class
Warning
(
Exception
):
"""Exception raised for important warnings like data truncations while inserting.
"""Exception raised for important warnings like data truncations while inserting.
"""
"""
pass
pass
class
InterfaceError
(
Error
):
class
InterfaceError
(
Error
):
"""Exception raised for errors that are related to the database interface rather than the database itself.
"""Exception raised for errors that are related to the database interface rather than the database itself.
"""
"""
pass
pass
class
DatabaseError
(
Error
):
class
DatabaseError
(
Error
):
"""Exception raised for errors that are related to the database.
"""Exception raised for errors that are related to the database.
"""
"""
pass
pass
class
DataError
(
DatabaseError
):
class
DataError
(
DatabaseError
):
"""Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range.
"""Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range.
"""
"""
pass
pass
class
OperationalError
(
DatabaseError
):
class
OperationalError
(
DatabaseError
):
"""Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer
"""Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer
"""
"""
...
@@ -41,16 +47,19 @@ class IntegrityError(DatabaseError):
...
@@ -41,16 +47,19 @@ class IntegrityError(DatabaseError):
"""
"""
pass
pass
class
InternalError
(
DatabaseError
):
class
InternalError
(
DatabaseError
):
"""Exception raised when the database encounters an internal error.
"""Exception raised when the database encounters an internal error.
"""
"""
pass
pass
class
ProgrammingError
(
DatabaseError
):
class
ProgrammingError
(
DatabaseError
):
"""Exception raised for programming errors.
"""Exception raised for programming errors.
"""
"""
pass
pass
class
NotSupportedError
(
DatabaseError
):
class
NotSupportedError
(
DatabaseError
):
"""Exception raised in case a method or database API was used which is not supported by the database,.
"""Exception raised in case a method or database API was used which is not supported by the database,.
"""
"""
...
...
src/connector/python/osx/python3/taos/subscription.py
浏览文件 @
42efe016
from
.cinterface
import
CTaosInterface
from
.cinterface
import
CTaosInterface
from
.error
import
*
from
.error
import
*
class
TDengineSubscription
(
object
):
class
TDengineSubscription
(
object
):
"""TDengine subscription object
"""TDengine subscription object
"""
"""
def
__init__
(
self
,
sub
):
def
__init__
(
self
,
sub
):
self
.
_sub
=
sub
self
.
_sub
=
sub
def
consume
(
self
):
def
consume
(
self
):
"""Consume rows of a subscription
"""Consume rows of a subscription
"""
"""
...
@@ -18,15 +19,15 @@ class TDengineSubscription(object):
...
@@ -18,15 +19,15 @@ class TDengineSubscription(object):
buffer
=
[[]
for
i
in
range
(
len
(
fields
))]
buffer
=
[[]
for
i
in
range
(
len
(
fields
))]
while
True
:
while
True
:
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
result
,
fields
)
block
,
num_of_fields
=
CTaosInterface
.
fetchBlock
(
result
,
fields
)
if
num_of_fields
==
0
:
break
if
num_of_fields
==
0
:
break
for
i
in
range
(
len
(
fields
)):
for
i
in
range
(
len
(
fields
)):
buffer
[
i
].
extend
(
block
[
i
])
buffer
[
i
].
extend
(
block
[
i
])
self
.
fields
=
fields
self
.
fields
=
fields
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
return
list
(
map
(
tuple
,
zip
(
*
buffer
)))
def
close
(
self
,
keepProgress
=
True
):
def
close
(
self
,
keepProgress
=
True
):
"""Close the Subscription.
"""Close the Subscription.
"""
"""
if
self
.
_sub
is
None
:
if
self
.
_sub
is
None
:
...
@@ -38,12 +39,16 @@ class TDengineSubscription(object):
...
@@ -38,12 +39,16 @@ class TDengineSubscription(object):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
.connection
import
TDengineConnection
from
.connection
import
TDengineConnection
conn
=
TDengineConnection
(
host
=
"127.0.0.1"
,
user
=
"root"
,
password
=
"taosdata"
,
database
=
"test"
)
conn
=
TDengineConnection
(
host
=
"127.0.0.1"
,
user
=
"root"
,
password
=
"taosdata"
,
database
=
"test"
)
# Generate a cursor object to run SQL commands
# Generate a cursor object to run SQL commands
sub
=
conn
.
subscribe
(
True
,
"test"
,
"select * from meters;"
,
1000
)
sub
=
conn
.
subscribe
(
True
,
"test"
,
"select * from meters;"
,
1000
)
for
i
in
range
(
0
,
10
):
for
i
in
range
(
0
,
10
):
data
=
sub
.
consume
()
data
=
sub
.
consume
()
for
d
in
data
:
for
d
in
data
:
print
(
d
)
print
(
d
)
...
...
tests/pytest/insert/basic_unsigned.py
浏览文件 @
42efe016
...
@@ -25,7 +25,8 @@ class TDTestCase:
...
@@ -25,7 +25,8 @@ class TDTestCase:
def
run
(
self
):
def
run
(
self
):
tdSql
.
prepare
()
tdSql
.
prepare
()
ret
=
tdSql
.
execute
(
'create table tb (ts timestamp, speed int unsigned)'
)
ret
=
tdSql
.
execute
(
'create table tb (ts timestamp, speed int unsigned)'
)
insertRows
=
10
insertRows
=
10
tdLog
.
info
(
"insert %d rows"
%
(
insertRows
))
tdLog
.
info
(
"insert %d rows"
%
(
insertRows
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录