Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Tonvia
TDengine
提交
9161244c
T
TDengine
项目概览
Tonvia
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9161244c
编写于
8月 14, 2021
作者:
L
Linhe Huo
提交者:
GitHub
8月 14, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-6078]<fix>: fix binary/nchar null error in node.js [ci skip] (#7366)
上级
9976d7a0
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
57 addition
and
2 deletion
+57
-2
src/connector/nodejs/nodetaos/cinterface.js
src/connector/nodejs/nodetaos/cinterface.js
+24
-2
src/connector/nodejs/test/testnchar.js
src/connector/nodejs/test/testnchar.js
+33
-0
未找到文件。
src/connector/nodejs/nodetaos/cinterface.js
浏览文件 @
9161244c
...
...
@@ -109,6 +109,24 @@ function convertDouble(data, num_of_rows, nbytes = 0, offset = 0, precision = 0)
return
res
;
}
function
convertBinary
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
let
currOffset
=
0
;
while
(
currOffset
<
data
.
length
)
{
let
len
=
data
.
readIntLE
(
currOffset
,
2
);
let
dataEntry
=
data
.
slice
(
currOffset
+
2
,
currOffset
+
len
+
2
);
//one entry in a row under a column;
if
(
dataEntry
[
0
]
==
255
)
{
res
.
push
(
null
)
}
else
{
res
.
push
(
dataEntry
.
toString
(
"
utf-8
"
));
}
currOffset
+=
nbytes
;
}
return
res
;
}
function
convertNchar
(
data
,
num_of_rows
,
nbytes
=
0
,
offset
=
0
,
precision
=
0
)
{
data
=
ref
.
reinterpret
(
data
.
deref
(),
nbytes
*
num_of_rows
,
offset
);
let
res
=
[];
...
...
@@ -117,7 +135,11 @@ function convertNchar(data, num_of_rows, nbytes = 0, offset = 0, precision = 0)
while
(
currOffset
<
data
.
length
)
{
let
len
=
data
.
readIntLE
(
currOffset
,
2
);
let
dataEntry
=
data
.
slice
(
currOffset
+
2
,
currOffset
+
len
+
2
);
//one entry in a row under a column;
if
(
dataEntry
[
0
]
==
255
&&
dataEntry
[
1
]
==
255
)
{
res
.
push
(
null
)
}
else
{
res
.
push
(
dataEntry
.
toString
(
"
utf-8
"
));
}
currOffset
+=
nbytes
;
}
return
res
;
...
...
@@ -132,7 +154,7 @@ let convertFunctions = {
[
FieldTypes
.
C_BIGINT
]:
convertBigint
,
[
FieldTypes
.
C_FLOAT
]:
convertFloat
,
[
FieldTypes
.
C_DOUBLE
]:
convertDouble
,
[
FieldTypes
.
C_BINARY
]:
convert
Nchar
,
[
FieldTypes
.
C_BINARY
]:
convert
Binary
,
[
FieldTypes
.
C_TIMESTAMP
]:
convertTimestamp
,
[
FieldTypes
.
C_NCHAR
]:
convertNchar
}
...
...
src/connector/nodejs/test/testnchar.js
0 → 100644
浏览文件 @
9161244c
const
taos
=
require
(
'
../tdengine
'
);
var
conn
=
taos
.
connect
({
host
:
"
localhost
"
});
var
c1
=
conn
.
cursor
();
function
checkData
(
data
,
row
,
col
,
expect
)
{
let
checkdata
=
data
[
row
][
col
];
if
(
checkdata
==
expect
)
{
// console.log('check pass')
}
else
{
console
.
log
(
'
check failed, expect
'
+
expect
+
'
, but is
'
+
checkdata
)
}
}
c1
.
execute
(
'
drop database if exists testnodejsnchar
'
)
c1
.
execute
(
'
create database testnodejsnchar
'
)
c1
.
execute
(
'
use testnodejsnchar
'
);
c1
.
execute
(
'
create table tb (ts timestamp, value float, text binary(200))
'
)
c1
.
execute
(
"
insert into tb values('2021-06-10 00:00:00', 24.7, '中文10000000000000000000000');
"
)
-
c1
.
execute
(
'
insert into tb values(1623254400150, 24.7, NULL);
'
)
c1
.
execute
(
'
import into tb values(1623254400300, 24.7, "中文3中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000");
'
)
sql
=
'
select * from tb;
'
console
.
log
(
'
*******************************************
'
)
c1
.
execute
(
sql
);
data
=
c1
.
fetchall
();
console
.
log
(
data
)
//check data about insert data
checkData
(
data
,
0
,
2
,
'
中文10000000000000000000000
'
)
checkData
(
data
,
1
,
2
,
null
)
checkData
(
data
,
2
,
2
,
'
中文3中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000中文10000000000000000000000
'
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录