Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
95663f1c
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
95663f1c
编写于
9月 05, 2019
作者:
S
slguan
提交者:
GitHub
9月 05, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #416 from localvar/fix-token-parse
fix several issues in string token parsing
上级
8914c0cc
693ee662
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
49 addition
and
54 deletion
+49
-54
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+3
-8
src/inc/tstoken.h
src/inc/tstoken.h
+1
-1
src/kit/shell/src/shellEngine.c
src/kit/shell/src/shellEngine.c
+13
-0
src/util/src/tstoken.c
src/util/src/tstoken.c
+32
-45
未找到文件。
src/client/src/tscParseInsert.c
浏览文件 @
95663f1c
...
...
@@ -99,16 +99,12 @@ int tsParseTime(char *value, int32_t valuelen, int64_t *time, char **next, char
int64_t
useconds
=
0
;
char
*
pTokenEnd
=
*
next
;
tscGetToken
(
pTokenEnd
,
&
token
,
&
tokenlen
);
if
(
tokenlen
==
0
&&
strlen
(
value
)
==
0
)
{
INVALID_SQL_RET_MSG
(
error
,
"missing time stamp"
);
}
if
(
strncmp
(
value
,
"now"
,
3
)
==
0
&&
valuelen
==
3
)
{
if
(
valuelen
==
3
&&
(
strncmp
(
value
,
"now"
,
3
)
==
0
)
)
{
useconds
=
taosGetTimestamp
(
timePrec
);
}
else
if
(
strncmp
(
value
,
"0"
,
1
)
==
0
&&
valuelen
==
1
)
{
}
else
if
(
valuelen
==
1
&&
value
[
0
]
==
'0'
)
{
// do nothing
}
else
if
(
value
[
4
]
!=
'-'
)
{
}
else
if
(
value
len
<=
4
||
value
[
4
]
!=
'-'
)
{
for
(
int32_t
i
=
0
;
i
<
valuelen
;
++
i
)
{
/*
* filter illegal input.
...
...
@@ -131,7 +127,6 @@ int tsParseTime(char *value, int32_t valuelen, int64_t *time, char **next, char
for
(
int
k
=
valuelen
;
value
[
k
]
!=
'\0'
;
k
++
)
{
if
(
value
[
k
]
==
' '
||
value
[
k
]
==
'\t'
)
continue
;
if
(
value
[
k
]
==
','
)
{
*
next
=
pTokenEnd
;
*
time
=
useconds
;
return
0
;
}
...
...
src/inc/tstoken.h
浏览文件 @
95663f1c
...
...
@@ -30,7 +30,7 @@ typedef struct SSQLToken {
}
SSQLToken
;
char
*
tscGetToken
(
char
*
string
,
char
**
token
,
int
*
tokenLen
);
char
*
tscGetTokenDelimiter
(
char
*
string
,
char
**
token
,
int
*
tokenLen
,
char
*
delimiters
);
char
*
tscGetTokenDelimiter
(
char
*
string
,
char
**
token
,
int
*
tokenLen
,
c
onst
c
har
*
delimiters
);
/**
* tokenizer for sql string
...
...
src/kit/shell/src/shellEngine.c
浏览文件 @
95663f1c
...
...
@@ -111,6 +111,7 @@ TAOS *shellInit(struct arguments *args) {
void
shellReplaceCtrlChar
(
char
*
str
)
{
_Bool
ctrlOn
=
false
;
char
*
pstr
=
NULL
;
char
quote
=
0
;
for
(
pstr
=
str
;
*
str
!=
'\0'
;
++
str
)
{
if
(
ctrlOn
)
{
...
...
@@ -131,6 +132,13 @@ void shellReplaceCtrlChar(char *str) {
*
pstr
=
'\\'
;
pstr
++
;
break
;
case
'\''
:
case
'"'
:
if
(
quote
)
{
*
pstr
++
=
'\\'
;
*
pstr
++
=
*
str
;
}
break
;
default:
break
;
}
...
...
@@ -139,6 +147,11 @@ void shellReplaceCtrlChar(char *str) {
if
(
*
str
==
'\\'
)
{
ctrlOn
=
true
;
}
else
{
if
(
quote
==
*
str
)
{
quote
=
0
;
}
else
if
(
*
str
==
'\''
||
*
str
==
'"'
)
{
quote
=
*
str
;
}
*
pstr
=
*
str
;
pstr
++
;
}
...
...
src/util/src/tstoken.c
浏览文件 @
95663f1c
...
...
@@ -23,77 +23,68 @@
#include "shash.h"
#include "tstoken.h"
static
char
operator
[]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
static
c
onst
c
har
operator
[]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
'$'
,
'%'
,
'&'
,
0
,
'('
,
')'
,
'*'
,
'+'
,
0
,
'-'
,
0
,
'/'
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
'<'
,
'='
,
'>'
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
'['
,
0
,
']'
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
'|'
,
0
,
0
,
0
};
static
char
delimiter
[]
=
{
static
c
onst
c
har
delimiter
[]
=
{
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
','
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
';'
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
};
bool
isCharInDelimiter
(
char
c
,
char
*
delimiter
)
{
for
(
int
i
=
0
;
i
<
strlen
(
delimiter
);
i
++
)
{
if
(
delimiter
[
i
]
==
c
)
return
true
;
}
return
false
;
}
char
*
tscGetTokenDelimiter
(
char
*
string
,
char
**
token
,
int
*
tokenLen
,
char
*
delimiters
)
{
while
(
*
string
!=
0
)
{
if
(
isCharInDelimiter
(
*
string
,
delimiters
))
{
++
string
;
}
else
{
break
;
}
char
*
tscGetTokenDelimiter
(
char
*
string
,
char
**
token
,
int
*
tokenLen
,
const
char
*
delimiters
)
{
while
((
*
string
!=
0
)
&&
strchr
(
delimiters
,
*
string
))
{
++
string
;
}
*
token
=
string
;
char
*
str
=
string
;
*
tokenLen
=
0
;
while
(
*
str
!=
0
)
{
if
(
!
isCharInDelimiter
(
*
str
,
delimiters
))
{
*
tokenLen
=
*
tokenLen
+
1
;
str
++
;
}
else
{
break
;
}
while
((
*
str
!=
0
)
&&
(
strchr
(
delimiters
,
*
str
)
==
NULL
))
{
++
str
;
}
*
tokenLen
=
str
-
string
;
return
string
;
}
static
bool
isOperator
(
char
c
)
{
return
(
c
<
0
)
?
false
:
(
operator
[
c
]
!=
0
);
}
static
bool
isDelimiter
(
char
c
)
{
return
(
c
<
0
)
?
false
:
(
delimiter
[
c
]
!=
0
);
}
char
*
tscGetToken
(
char
*
string
,
char
**
token
,
int
*
tokenLen
)
{
char
quote
=
0
;
while
(
*
string
!=
0
)
{
if
(
delimiter
[
*
string
]
)
{
if
(
isDelimiter
(
*
string
)
)
{
++
string
;
}
else
{
break
;
}
}
char
quotaChar
=
0
;
if
(
*
string
==
'\''
||
*
string
==
'\"'
)
{
quote
=
1
;
quotaChar
=
*
string
;
quote
=
*
string
;
string
++
;
}
*
token
=
string
;
/* not in string, return token */
if
(
*
string
>
0
&&
operator
[
*
string
]
&&
quote
==
0
)
{
if
(
quote
==
0
&&
isOperator
(
*
string
)
)
{
string
++
;
/* handle the case: insert into tabx using stable1 tags(-1)/tags(+1)
* values(....) */
if
(
operator
[
*
string
]
&&
(
*
string
!=
'('
&&
*
string
!=
')'
&&
*
string
!=
'-'
&&
*
string
!=
'+'
))
if
(
isOperator
(
*
string
)
&&
(
*
string
!=
'('
&&
*
string
!=
')'
&&
*
string
!=
'-'
&&
*
string
!=
'+'
))
*
tokenLen
=
2
;
else
*
tokenLen
=
1
;
...
...
@@ -102,28 +93,24 @@ char *tscGetToken(char *string, char **token, int *tokenLen) {
while
(
*
string
!=
0
)
{
if
(
quote
)
{
// handle escape situation: '\"', the " should not be eliminated
if
(
*
string
==
quotaChar
)
{
if
(
*
(
string
-
1
)
!=
'\\'
)
{
break
;
}
else
{
if
(
*
string
==
'\''
||
*
string
==
'"'
)
{
// handle escape situation, " and ' should not be eliminated
if
(
*
(
string
-
1
)
==
'\\'
)
{
shiftStr
(
string
-
1
,
string
);
continue
;
}
else
if
(
*
string
==
quote
)
{
break
;
}
}
else
{
++
string
;
}
}
else
{
if
(
delimiter
[
*
string
])
break
;
if
(
operator
[
*
string
])
break
;
++
string
;
}
else
if
(
isDelimiter
(
*
string
)
||
isOperator
(
*
string
))
{
break
;
}
++
string
;
}
*
tokenLen
=
(
int
)(
string
-
*
token
);
if
(
quot
aChar
!=
0
&&
*
string
!=
0
&&
*
(
string
+
1
)
!=
0
)
{
if
(
quot
e
&&
*
string
!=
0
)
{
return
string
+
1
;
}
else
{
return
string
;
...
...
@@ -135,7 +122,7 @@ void shiftStr(char *dst, char *src) {
do
{
dst
[
i
]
=
src
[
i
];
i
++
;
}
while
(
delimiter
[
src
[
i
]]
==
0
);
}
while
(
!
isDelimiter
(
src
[
i
])
);
src
[
i
-
1
]
=
' '
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录