提交 ac5724c8 编写于 作者: G Ganlin Zhao

[TD-11220]<feature>(query): time related functions

上级 a4f78b63
...@@ -5438,21 +5438,6 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr ...@@ -5438,21 +5438,6 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr
goto err_ret; goto err_ret;
} }
//for now(),today() function used in where clause.
if (pRight->tokenId == TK_ID && (strncmp(pRight->exprToken.z, "now()", pRight->exprToken.n) == 0 ||
strncmp(pRight->exprToken.z, "today()", pRight->exprToken.n) == 0)) {
pRight->type = SQL_NODE_VALUE;
pRight->tokenId = TK_TIMESTAMP;
pRight->exprToken.type = TSDB_DATA_TYPE_TIMESTAMP;
if (strncmp(pRight->exprToken.z, "now()", pRight->exprToken.n) == 0) {
tVariantCreateExt(&pRight->value, &pRight->exprToken, TK_NOW, false);
} else {
tVariantCreateExt(&pRight->value, &pRight->exprToken, TK_TODAY, false);
}
pRight->value.nType = TSDB_DATA_TYPE_BIGINT;
pRight->flags |= 1 << EXPR_FLAG_NS_TIMESTAMP;
}
ret = handleExprInQueryCond(pCmd, pQueryInfo, pExpr, pCondExpr, type, tbIdx, parentOptr, columnExpr, tsExpr, joinQuery); ret = handleExprInQueryCond(pCmd, pQueryInfo, pExpr, pCondExpr, type, tbIdx, parentOptr, columnExpr, tsExpr, joinQuery);
if (ret) { if (ret) {
goto err_ret; goto err_ret;
......
...@@ -33,6 +33,7 @@ SSqlInfo qSqlParse(const char *pStr) { ...@@ -33,6 +33,7 @@ SSqlInfo qSqlParse(const char *pStr) {
sqlInfo.funcs = taosArrayInit(4, sizeof(SStrToken)); sqlInfo.funcs = taosArrayInit(4, sizeof(SStrToken));
int32_t i = 0; int32_t i = 0;
bool inWhere = false;
while (1) { while (1) {
SStrToken t0 = {0}; SStrToken t0 = {0};
...@@ -68,11 +69,23 @@ SSqlInfo qSqlParse(const char *pStr) { ...@@ -68,11 +69,23 @@ SSqlInfo qSqlParse(const char *pStr) {
sqlInfo.valid = false; sqlInfo.valid = false;
goto abort_parse; goto abort_parse;
} }
case TK_WHERE:{
inWhere = true;
Parse(pParser, t0.type, t0, &sqlInfo);
if (sqlInfo.valid == false) {
goto abort_parse;
}
break;
}
case TK_NOW: case TK_NOW:
case TK_TODAY: { case TK_TODAY: {
//for now(),today() function used in select clause //for now(),today() function used in select/where clause
if (pStr[i] == '(' && pStr[i + 1] == ')') { if (pStr[i] == '(' && pStr[i + 1] == ')') {
t0.type = TK_ID; if (!inWhere) {
t0.type = TK_ID;
} else {
i += 2;
}
} }
} }
default: default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册