Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
37c05411
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看板
提交
37c05411
编写于
5月 04, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-168] fix bug in handling variable nchar string
上级
d87cefab
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
27 addition
and
37 deletion
+27
-37
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+12
-7
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+1
-1
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+1
-1
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+3
-3
src/common/src/tdataformat.c
src/common/src/tdataformat.c
+2
-21
src/query/src/tvariant.c
src/query/src/tvariant.c
+2
-2
src/util/inc/tutil.h
src/util/inc/tutil.h
+1
-1
src/util/src/tutil.c
src/util/src/tutil.c
+5
-1
未找到文件。
src/client/src/tscParseInsert.c
浏览文件 @
37c05411
...
...
@@ -305,32 +305,37 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
case
TSDB_DATA_TYPE_BINARY
:
// binary data cannot be null-terminated char string, otherwise the last char of the string is lost
if
(
pToken
->
type
==
TK_NULL
)
{
*
(
int16_t
*
)
payload
=
sizeof
(
int8_t
);
payload
+=
VARSTR_HEADER_SIZE
;
*
payload
=
TSDB_DATA_BINARY_NULL
;
}
else
{
// too long values will return invalid sql, not be truncated automatically
if
(
pToken
->
n
>
pSchema
->
bytes
)
{
return
tscInvalidSQLErrMsg
(
msg
,
"string data overflow"
,
pToken
->
z
);
}
strncpy
(
payload
,
pToken
->
z
,
pToken
->
n
);
if
(
pToken
->
n
<
pSchema
->
bytes
)
{
payload
[
pToken
->
n
]
=
0
;
// add the null-terminated char if the length of the string is shorter than the available space
}
STR_WITH_SIZE_TO_VARSTR
(
payload
,
pToken
->
z
,
pToken
->
n
);
}
break
;
case
TSDB_DATA_TYPE_NCHAR
:
if
(
pToken
->
type
==
TK_NULL
)
{
*
(
uint32_t
*
)
payload
=
TSDB_DATA_NCHAR_NULL
;
*
(
int16_t
*
)
payload
=
sizeof
(
int32_t
);
payload
+=
VARSTR_HEADER_SIZE
;
*
(
uint32_t
*
)
payload
=
TSDB_DATA_NCHAR_NULL
;
}
else
{
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
if
(
!
taosMbsToUcs4
(
pToken
->
z
,
pToken
->
n
,
payload
,
pSchema
->
bytes
))
{
int32_t
resLen
=
-
1
;
if
(
!
taosMbsToUcs4
(
pToken
->
z
,
pToken
->
n
,
payload
+
VARSTR_HEADER_SIZE
,
pSchema
->
bytes
,
&
resLen
))
{
char
buf
[
512
]
=
{
0
};
snprintf
(
buf
,
512
,
"%s"
,
strerror
(
errno
));
return
tscInvalidSQLErrMsg
(
msg
,
buf
,
pToken
->
z
);
}
*
(
uint16_t
*
)
payload
=
(
uint16_t
)
(
resLen
*
TSDB_NCHAR_SIZE
);
}
break
;
...
...
src/client/src/tscPrepare.c
浏览文件 @
37c05411
...
...
@@ -300,7 +300,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) {
break
;
case
TSDB_DATA_TYPE_NCHAR
:
if
(
!
taosMbsToUcs4
(
bind
->
buffer
,
*
bind
->
length
,
data
+
param
->
offset
,
param
->
bytes
))
{
if
(
!
taosMbsToUcs4
(
bind
->
buffer
,
*
bind
->
length
,
data
+
param
->
offset
,
param
->
bytes
,
NULL
))
{
return
TSDB_CODE_INVALID_VALUE
;
}
return
TSDB_CODE_SUCCESS
;
...
...
src/client/src/tscSubquery.c
浏览文件 @
37c05411
...
...
@@ -1934,7 +1934,7 @@ static void transferNcharData(SSqlObj *pSql, int32_t columnIndex, TAOS_FIELD *pF
/* string terminated char for binary data*/
memset
(
pRes
->
buffer
[
columnIndex
],
0
,
pField
->
bytes
+
TSDB_NCHAR_SIZE
);
if
(
taosUcs4ToMbs
(
pRes
->
tsrow
[
columnIndex
],
pField
->
bytes
,
pRes
->
buffer
[
columnIndex
]))
{
if
(
taosUcs4ToMbs
(
pRes
->
tsrow
[
columnIndex
],
pField
->
bytes
-
VARSTR_HEADER_SIZE
,
pRes
->
buffer
[
columnIndex
]))
{
pRes
->
tsrow
[
columnIndex
]
=
pRes
->
buffer
[
columnIndex
];
}
else
{
tscError
(
"%p charset:%s to %s. val:%ls convert failed."
,
pSql
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
pRes
->
tsrow
);
...
...
src/client/src/tscUtil.c
浏览文件 @
37c05411
...
...
@@ -2132,12 +2132,12 @@ char* tscGetResultColumnChr(SSqlRes* pRes, SQueryInfo* pQueryInfo, int32_t colum
char
*
pData
=
((
char
*
)
pRes
->
data
)
+
pInfo
->
pSqlExpr
->
offset
*
pRes
->
numOfRows
+
bytes
*
pRes
->
row
;
if
(
type
==
TSDB_DATA_TYPE_NCHAR
||
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
realLen
=
*
(
int16_t
*
)
pData
;
if
(
realLen
<
pInfo
->
pSqlExpr
->
resBytes
-
sizeof
(
int16_t
)
)
{
// todo refactor
int32_t
realLen
=
varDataLen
(
pData
)
;
if
(
realLen
<
pInfo
->
pSqlExpr
->
resBytes
-
VARSTR_HEADER_SIZE
)
{
// todo refactor
*
(
char
*
)
(
pData
+
realLen
+
sizeof
(
int16_t
))
=
0
;
}
return
pData
+
sizeof
(
int16_t
)
;
// head is the length of binary/nchar data
return
pData
+
VARSTR_HEADER_SIZE
;
// head is the length of binary/nchar data
}
else
{
return
pData
;
}
...
...
src/common/src/tdataformat.c
浏览文件 @
37c05411
...
...
@@ -172,28 +172,9 @@ int tdAppendColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int32_
switch
(
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
// set offset
*
(
VarDataOffsetT
*
)
POINTER_DRIFT
(
row
,
toffset
)
=
dataRowLen
(
row
);
// set length
VarDataLenT
slen
=
0
;
if
(
isNull
(
value
,
type
))
{
slen
=
(
type
==
TSDB_DATA_TYPE_BINARY
)
?
sizeof
(
int8_t
)
:
sizeof
(
int32_t
);
}
else
{
if
(
type
==
TSDB_DATA_TYPE_BINARY
)
{
slen
=
strnlen
((
char
*
)
value
,
bytes
);
}
else
{
slen
=
wcsnlen
((
wchar_t
*
)
value
,
(
bytes
)
/
TSDB_NCHAR_SIZE
)
*
TSDB_NCHAR_SIZE
;
}
}
ASSERT
(
slen
<=
bytes
);
*
(
VarDataLenT
*
)
ptr
=
slen
;
ptr
=
POINTER_DRIFT
(
ptr
,
sizeof
(
VarDataLenT
));
memcpy
((
void
*
)
ptr
,
value
,
slen
);
dataRowLen
(
row
)
+=
(
sizeof
(
int16_t
)
+
slen
);
memcpy
(
ptr
,
value
,
varDataTLen
(
value
));
dataRowLen
(
row
)
+=
varDataTLen
(
value
);
break
;
default:
memcpy
(
POINTER_DRIFT
(
row
,
toffset
),
value
,
TYPE_BYTES
[
type
]);
...
...
src/query/src/tvariant.c
浏览文件 @
37c05411
...
...
@@ -408,7 +408,7 @@ static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
if
(
*
pDest
==
pVariant
->
pz
)
{
wchar_t
*
pWStr
=
calloc
(
1
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
);
taosMbsToUcs4
(
pDst
,
nLen
,
(
char
*
)
pWStr
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
);
taosMbsToUcs4
(
pDst
,
nLen
,
(
char
*
)
pWStr
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
,
NULL
);
// free the binary buffer in the first place
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
...
...
@@ -424,7 +424,7 @@ static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
pVariant
->
wpz
=
(
wchar_t
*
)
tmp
;
}
else
{
taosMbsToUcs4
(
pDst
,
nLen
,
*
pDest
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
);
taosMbsToUcs4
(
pDst
,
nLen
,
*
pDest
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
,
NULL
);
}
return
0
;
...
...
src/util/inc/tutil.h
浏览文件 @
37c05411
...
...
@@ -144,7 +144,7 @@ void getTmpfilePath(const char *fileNamePattern, char *dstPath);
int32_t
taosInitTimer
(
void
(
*
callback
)(
int
),
int32_t
ms
);
void
taosUninitTimer
();
bool
taosMbsToUcs4
(
char
*
mbs
,
int32_t
mbs_len
,
char
*
ucs4
,
int32_t
ucs4_max_len
);
bool
taosMbsToUcs4
(
char
*
mbs
,
int32_t
mbs_len
,
char
*
ucs4
,
int32_t
ucs4_max_len
,
int32_t
*
len
);
int
tasoUcs4Compare
(
void
*
f1_ucs4
,
void
*
f2_ucs4
,
int
bytes
);
...
...
src/util/src/tutil.c
浏览文件 @
37c05411
...
...
@@ -490,7 +490,7 @@ bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
#endif
}
bool
taosMbsToUcs4
(
char
*
mbs
,
int32_t
mbs_len
,
char
*
ucs4
,
int32_t
ucs4_max_len
)
{
bool
taosMbsToUcs4
(
char
*
mbs
,
int32_t
mbs_len
,
char
*
ucs4
,
int32_t
ucs4_max_len
,
int32_t
*
len
)
{
memset
(
ucs4
,
0
,
ucs4_max_len
);
#ifdef USE_LIBICONV
iconv_t
cd
=
iconv_open
(
DEFAULT_UNICODE_ENCODEC
,
tsCharset
);
...
...
@@ -501,6 +501,10 @@ bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len)
return
false
;
}
iconv_close
(
cd
);
if
(
len
!=
NULL
)
{
*
len
=
outLen
;
}
return
true
;
#else
mbstate_t
state
=
{
0
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录