Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fb461c7d
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看板
未验证
提交
fb461c7d
编写于
1月 21, 2022
作者:
R
robotspace
提交者:
GitHub
1月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use lua_pushlstring instead of lua_pushstring to return accurate string to Lua. (#9312)
上级
943c72d1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
33 addition
and
18 deletion
+33
-18
tests/examples/lua/OpenResty/rest/test.lua
tests/examples/lua/OpenResty/rest/test.lua
+3
-4
tests/examples/lua/OpenResty/so/luaconnector51.so
tests/examples/lua/OpenResty/so/luaconnector51.so
+0
-0
tests/examples/lua/lua51/lua_connector51.c
tests/examples/lua/lua51/lua_connector51.c
+11
-5
tests/examples/lua/lua_connector.c
tests/examples/lua/lua_connector.c
+12
-6
tests/examples/lua/test.lua
tests/examples/lua/test.lua
+7
-3
未找到文件。
tests/examples/lua/OpenResty/rest/test.lua
浏览文件 @
fb461c7d
...
...
@@ -28,7 +28,7 @@ else
ngx
.
say
(
"select db--- pass."
)
end
res
=
driver
.
query
(
conn
,
"create table m1 (ts timestamp, speed int,
owner binary(2
0))"
)
res
=
driver
.
query
(
conn
,
"create table m1 (ts timestamp, speed int,
owner binary(20), mark nchar(3
0))"
)
if
res
.
code
~=
0
then
ngx
.
say
(
"create table---failed: "
..
res
.
error
)
...
...
@@ -36,7 +36,7 @@ else
ngx
.
say
(
"create table--- pass."
)
end
res
=
driver
.
query
(
conn
,
"insert into m1 values ('2019-09-01 00:00:00.001', 0, 'robotspace'
), ('2019-09-01 00:00:00.002',1,'Hilink'),('2019-09-01 00:00:00.003',2,'Harmony
')"
)
res
=
driver
.
query
(
conn
,
"insert into m1 values ('2019-09-01 00:00:00.001', 0, 'robotspace'
, '世界人民大团结万岁'), ('2019-09-01 00:00:00.002',1,'Hilink','⾾⾿⿀⿁⿂⿃⿄⿅⿆⿇⿈⿉⿊⿋⿌⿍⿎⿏⿐⿑⿒⿓⿔⿕'),('2019-09-01 00:00:00.003',2,'Harmony', '₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵
')"
)
if
res
.
code
~=
0
then
ngx
.
say
(
"insert records failed: "
..
res
.
error
)
return
...
...
@@ -56,13 +56,12 @@ if res.code ~=0 then
else
ngx
.
say
(
cjson
.
encode
(
res
))
if
(
#
(
res
.
item
)
==
3
)
then
ngx
.
say
(
"select--- pass"
)
ngx
.
say
(
"select--- pass"
)
else
ngx
.
say
(
"select--- failed: expect 3 affected records, actually received "
..#
(
res
.
item
))
end
end
--[[
local flag = false
function query_callback(res)
...
...
tests/examples/lua/OpenResty/so/luaconnector51.so
浏览文件 @
fb461c7d
无法预览此类型文件
tests/examples/lua/lua51/lua_connector51.c
浏览文件 @
fb461c7d
...
...
@@ -35,7 +35,7 @@ static int l_connect(lua_State *L){
}
lua_getfield
(
L
,
1
,
"port"
);
if
(
lua_isnumber
(
L
,
-
1
)){
if
(
lua_isnumber
(
L
,
-
1
)){
port
=
lua_tonumber
(
L
,
-
1
);
//printf("port = %d\n", port);
}
...
...
@@ -113,7 +113,6 @@ static int l_query(lua_State *L){
int
rows
=
0
;
int
num_fields
=
taos_field_count
(
result
);
const
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
//char temp[256];
const
int
affectRows
=
taos_affected_rows
(
result
);
// printf(" affect rows:%d\r\n", affectRows);
...
...
@@ -122,7 +121,7 @@ static int l_query(lua_State *L){
lua_pushinteger
(
L
,
affectRows
);
lua_setfield
(
L
,
table_index
,
"affected"
);
lua_newtable
(
L
);
while
((
row
=
taos_fetch_row
(
result
)))
{
//printf("row index:%d\n",rows);
rows
++
;
...
...
@@ -136,17 +135,21 @@ static int l_query(lua_State *L){
}
lua_pushstring
(
L
,
fields
[
i
].
name
);
int32_t
*
length
=
taos_fetch_lengths
(
result
);
switch
(
fields
[
i
].
type
)
{
case
TSDB_DATA_TYPE_UTINYINT
:
case
TSDB_DATA_TYPE_TINYINT
:
lua_pushinteger
(
L
,
*
((
char
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
lua_pushinteger
(
L
,
*
((
short
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_INT
:
lua_pushinteger
(
L
,
*
((
int
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
case
TSDB_DATA_TYPE_BIGINT
:
lua_pushinteger
(
L
,
*
((
int64_t
*
)
row
[
i
]));
break
;
...
...
@@ -156,9 +159,11 @@ static int l_query(lua_State *L){
case
TSDB_DATA_TYPE_DOUBLE
:
lua_pushnumber
(
L
,
*
((
double
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_JSON
:
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
lua_pushstring
(
L
,(
char
*
)
row
[
i
]);
//printf("type:%d, max len:%d, current len:%d\n",fields[i].type, fields[i].bytes, length[i]);
lua_pushlstring
(
L
,(
char
*
)
row
[
i
],
length
[
i
]);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
lua_pushinteger
(
L
,
*
((
int64_t
*
)
row
[
i
]));
...
...
@@ -166,6 +171,7 @@ static int l_query(lua_State *L){
case
TSDB_DATA_TYPE_BOOL
:
lua_pushinteger
(
L
,
*
((
char
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_NULL
:
default:
lua_pushnil
(
L
);
break
;
...
...
tests/examples/lua/lua_connector.c
浏览文件 @
fb461c7d
...
...
@@ -28,14 +28,14 @@ static int l_connect(lua_State *L){
luaL_checktype
(
L
,
1
,
LUA_TTABLE
);
lua_getfield
(
L
,
1
,
"host"
);
lua_getfield
(
L
,
1
,
"host"
);
if
(
lua_isstring
(
L
,
-
1
)){
host
=
lua_tostring
(
L
,
-
1
);
// printf("host = %s\n", host);
}
lua_getfield
(
L
,
1
,
"port"
);
if
(
lua_isinteger
(
L
,
-
1
)){
if
(
lua_isinteger
(
L
,
-
1
)){
port
=
lua_tointeger
(
L
,
-
1
);
//printf("port = %d\n", port);
}
...
...
@@ -113,7 +113,6 @@ static int l_query(lua_State *L){
int
rows
=
0
;
int
num_fields
=
taos_field_count
(
result
);
const
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
//char temp[256];
const
int
affectRows
=
taos_affected_rows
(
result
);
// printf(" affect rows:%d\r\n", affectRows);
...
...
@@ -122,7 +121,7 @@ static int l_query(lua_State *L){
lua_pushinteger
(
L
,
affectRows
);
lua_setfield
(
L
,
table_index
,
"affected"
);
lua_newtable
(
L
);
while
((
row
=
taos_fetch_row
(
result
)))
{
//printf("row index:%d\n",rows);
rows
++
;
...
...
@@ -136,17 +135,21 @@ static int l_query(lua_State *L){
}
lua_pushstring
(
L
,
fields
[
i
].
name
);
int32_t
*
length
=
taos_fetch_lengths
(
result
);
switch
(
fields
[
i
].
type
)
{
case
TSDB_DATA_TYPE_UTINYINT
:
case
TSDB_DATA_TYPE_TINYINT
:
lua_pushinteger
(
L
,
*
((
char
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
lua_pushinteger
(
L
,
*
((
short
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_INT
:
lua_pushinteger
(
L
,
*
((
int
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
case
TSDB_DATA_TYPE_BIGINT
:
lua_pushinteger
(
L
,
*
((
int64_t
*
)
row
[
i
]));
break
;
...
...
@@ -156,9 +159,11 @@ static int l_query(lua_State *L){
case
TSDB_DATA_TYPE_DOUBLE
:
lua_pushnumber
(
L
,
*
((
double
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_JSON
:
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
lua_pushstring
(
L
,(
char
*
)
row
[
i
]);
//printf("type:%d, max len:%d, current len:%d\n",fields[i].type, fields[i].bytes, length[i]);
lua_pushlstring
(
L
,(
char
*
)
row
[
i
],
length
[
i
]);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
lua_pushinteger
(
L
,
*
((
int64_t
*
)
row
[
i
]));
...
...
@@ -166,6 +171,7 @@ static int l_query(lua_State *L){
case
TSDB_DATA_TYPE_BOOL
:
lua_pushinteger
(
L
,
*
((
char
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_NULL
:
default:
lua_pushnil
(
L
);
break
;
...
...
tests/examples/lua/test.lua
浏览文件 @
fb461c7d
...
...
@@ -37,7 +37,7 @@ else
print
(
"select db--- pass."
)
end
res
=
driver
.
query
(
conn
,
"create table m1 (ts timestamp, speed int,
owner binary(2
0))"
)
res
=
driver
.
query
(
conn
,
"create table m1 (ts timestamp, speed int,
owner binary(20), mark nchar(3
0))"
)
if
res
.
code
~=
0
then
print
(
"create table---failed: "
..
res
.
error
)
return
...
...
@@ -45,7 +45,7 @@ else
print
(
"create table--- pass."
)
end
res
=
driver
.
query
(
conn
,
"insert into m1 values ('2019-09-01 00:00:00.001',
0,'robotspace'), ('2019-09-01 00:00:00.002',1,'Hilink'),('2019-09-01 00:00:00.003',2,'Harmony
')"
)
res
=
driver
.
query
(
conn
,
"insert into m1 values ('2019-09-01 00:00:00.001',
0, 'robotspace', '世界人民大团结万岁'), ('2019-09-01 00:00:00.002', 1, 'Hilink', '⾾⾿⿀⿁⿂⿃⿄⿅⿆⿇⿈⿉⿊⿋⿌⿍⿎⿏⿐⿑⿒⿓⿔⿕'),('2019-09-01 00:00:00.003', 2, 'Harmony', '₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵
')"
)
if
res
.
code
~=
0
then
print
(
"insert records failed: "
..
res
.
error
)
return
...
...
@@ -64,7 +64,11 @@ if res.code ~=0 then
return
else
if
(
#
(
res
.
item
)
==
3
)
then
print
(
"select--- pass"
)
print
(
"select--- pass"
)
print
(
res
.
item
[
1
].
mark
)
print
(
res
.
item
[
2
].
mark
)
print
(
res
.
item
[
3
].
mark
)
else
print
(
"select--- failed: expect 3 affected records, actually received "
..#
(
res
.
item
))
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录