Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
78707632
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
78707632
编写于
8月 25, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-255] merge develop
上级
a3a274d0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
83 addition
and
25 deletion
+83
-25
src/connector/python/taos/bind.py
src/connector/python/taos/bind.py
+27
-22
src/connector/python/taos/cinterface.py
src/connector/python/taos/cinterface.py
+1
-1
src/connector/python/taos/constants.py
src/connector/python/taos/constants.py
+5
-2
src/connector/python/tests/test-td6231.py
src/connector/python/tests/test-td6231.py
+50
-0
未找到文件。
src/connector/python/taos/bind.py
浏览文件 @
78707632
...
...
@@ -10,7 +10,8 @@ import sys
_datetime_epoch
=
datetime
.
utcfromtimestamp
(
0
)
def
_is_not_none
(
obj
):
obj
!=
None
return
obj
!=
None
class
TaosBind
(
ctypes
.
Structure
):
_fields_
=
[
(
"buffer_type"
,
c_int
),
...
...
@@ -299,27 +300,14 @@ class TaosMultiBind(ctypes.Structure):
self
.
buffer
=
cast
(
buffer
,
c_void_p
)
self
.
num
=
len
(
values
)
def
binary
(
self
,
values
):
def
_str_to_buffer
(
self
,
values
):
self
.
num
=
len
(
values
)
self
.
buffer
=
cast
(
c_char_p
(
""
.
join
(
filter
(
_is_not_none
,
values
)).
encode
(
"utf-8"
)),
c_void_p
)
self
.
length
=
(
c_int
*
len
(
values
))(
*
[
len
(
value
)
if
value
is
not
None
else
0
for
value
in
values
])
self
.
buffer_type
=
FieldType
.
C_BINARY
self
.
is_null
=
cast
((
c_byte
*
self
.
num
)(
*
[
1
if
v
==
None
else
0
for
v
in
values
]),
c_char_p
)
def
timestamp
(
self
,
values
,
precision
=
PrecisionEnum
.
Milliseconds
):
try
:
buffer
=
cast
(
values
,
c_void_p
)
except
:
buffer_type
=
c_int64
*
len
(
values
)
buffer
=
buffer_type
(
*
[
_datetime_to_timestamp
(
value
,
precision
)
for
value
in
values
])
self
.
buffer_type
=
FieldType
.
C_TIMESTAMP
self
.
buffer
=
cast
(
buffer
,
c_void_p
)
self
.
buffer_length
=
sizeof
(
c_int64
)
self
.
num
=
len
(
values
)
def
nchar
(
self
,
values
):
# type: (list[str]) -> None
is_null
=
[
1
if
v
==
None
else
0
for
v
in
values
]
self
.
is_null
=
cast
((
c_byte
*
self
.
num
)(
*
is_null
),
c_char_p
)
if
sum
(
is_null
)
==
self
.
num
:
self
.
length
=
(
c_int32
*
len
(
values
))(
0
*
self
.
num
)
return
if
sys
.
version_info
<
(
3
,
0
):
_bytes
=
[
bytes
(
value
)
if
value
is
not
None
else
None
for
value
in
values
]
buffer_length
=
max
(
len
(
b
)
+
1
for
b
in
_bytes
if
b
is
not
None
)
...
...
@@ -347,9 +335,26 @@ class TaosMultiBind(ctypes.Structure):
)
self
.
length
=
(
c_int32
*
len
(
values
))(
*
[
len
(
b
)
if
b
is
not
None
else
0
for
b
in
_bytes
])
self
.
buffer_length
=
buffer_length
def
binary
(
self
,
values
):
self
.
buffer_type
=
FieldType
.
C_BINARY
self
.
_str_to_buffer
(
values
)
def
timestamp
(
self
,
values
,
precision
=
PrecisionEnum
.
Milliseconds
):
try
:
buffer
=
cast
(
values
,
c_void_p
)
except
:
buffer_type
=
c_int64
*
len
(
values
)
buffer
=
buffer_type
(
*
[
_datetime_to_timestamp
(
value
,
precision
)
for
value
in
values
])
self
.
buffer_type
=
FieldType
.
C_TIMESTAMP
self
.
buffer
=
cast
(
buffer
,
c_void_p
)
self
.
buffer_length
=
sizeof
(
c_int64
)
self
.
num
=
len
(
values
)
self
.
is_null
=
cast
((
c_byte
*
self
.
num
)(
*
[
1
if
v
==
None
else
0
for
v
in
values
]),
c_char_p
)
def
nchar
(
self
,
values
):
# type: (list[str]) -> None
self
.
buffer_type
=
FieldType
.
C_NCHAR
self
.
_str_to_buffer
(
values
)
def
tinyint_unsigned
(
self
,
values
):
self
.
buffer_type
=
FieldType
.
C_TINYINT_UNSIGNED
...
...
src/connector/python/taos/cinterface.py
浏览文件 @
78707632
...
...
@@ -49,7 +49,7 @@ def _load_taos():
try
:
return
load_func
[
platform
.
system
()]()
except
:
sys
.
exit
(
"unsupported platform to TDengine connector"
)
raise
InterfaceError
(
'unsupported platform or failed to load taos client library'
)
_libtaos
=
_load_taos
()
...
...
src/connector/python/taos/constants.py
浏览文件 @
78707632
...
...
@@ -3,6 +3,9 @@
"""Constants in TDengine python
"""
import
ctypes
,
struct
class
FieldType
(
object
):
"""TDengine Field Types"""
...
...
@@ -33,8 +36,8 @@ class FieldType(object):
C_INT_UNSIGNED_NULL
=
4294967295
C_BIGINT_NULL
=
-
9223372036854775808
C_BIGINT_UNSIGNED_NULL
=
18446744073709551615
C_FLOAT_NULL
=
float
(
"nan"
)
C_DOUBLE_NULL
=
float
(
"nan"
)
C_FLOAT_NULL
=
ctypes
.
c_float
(
struct
.
unpack
(
"<f"
,
b
"
\x00\x00\xf0\x7f
"
)[
0
]
)
C_DOUBLE_NULL
=
ctypes
.
c_double
(
struct
.
unpack
(
"<d"
,
b
"
\x00\x00\x00\x00\x00\xff\xff\x7f
"
)[
0
]
)
C_BINARY_NULL
=
bytearray
([
int
(
"0xff"
,
16
)])
# Timestamp precision definition
C_TIMESTAMP_MILLI
=
0
...
...
src/connector/python/tests/test-td6231.py
0 → 100644
浏览文件 @
78707632
from
taos
import
*
conn
=
connect
()
dbname
=
"pytest_taos_stmt_multi"
conn
.
execute
(
"drop database if exists %s"
%
dbname
)
conn
.
execute
(
"create database if not exists %s"
%
dbname
)
conn
.
select_db
(
dbname
)
conn
.
execute
(
"create table if not exists log(ts timestamp, bo bool, nil tinyint,
\
ti tinyint, si smallint, ii int, bi bigint, tu tinyint unsigned,
\
su smallint unsigned, iu int unsigned, bu bigint unsigned,
\
ff float, dd double, bb binary(100), nn nchar(100), tt timestamp)"
,
)
stmt
=
conn
.
statement
(
"insert into log values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
)
params
=
new_multi_binds
(
16
)
params
[
0
].
timestamp
((
1626861392589
,
1626861392590
,
1626861392591
))
params
[
1
].
bool
((
True
,
None
,
False
))
params
[
2
].
tinyint
([
-
128
,
-
128
,
None
])
# -128 is tinyint null
params
[
3
].
tinyint
([
0
,
127
,
None
])
params
[
4
].
smallint
([
3
,
None
,
2
])
params
[
5
].
int
([
3
,
4
,
None
])
params
[
6
].
bigint
([
3
,
4
,
None
])
params
[
7
].
tinyint_unsigned
([
3
,
4
,
None
])
params
[
8
].
smallint_unsigned
([
3
,
4
,
None
])
params
[
9
].
int_unsigned
([
3
,
4
,
None
])
params
[
10
].
bigint_unsigned
([
3
,
4
,
None
])
params
[
11
].
float
([
3
,
None
,
1
])
params
[
12
].
double
([
3
,
None
,
1.2
])
params
[
13
].
binary
([
"abc"
,
"dddafadfadfadfadfa"
,
None
])
# params[14].nchar(["涛思数据", None, "a long string with 中文字符"])
params
[
14
].
nchar
([
None
,
None
,
None
])
params
[
15
].
timestamp
([
None
,
None
,
1626861392591
])
stmt
.
bind_param_batch
(
params
)
stmt
.
execute
()
result
=
stmt
.
use_result
()
assert
result
.
affected_rows
==
3
result
.
close
()
result
=
conn
.
query
(
"select * from log"
)
for
row
in
result
:
print
(
row
)
result
.
close
()
stmt
.
close
()
conn
.
close
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录