TDengine/source/libs/parser/src/parser.c

63 lines
1.7 KiB
C
Raw Normal View History

2021-09-23 07:50:12 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2021-10-06 15:46:48 +00:00
*/
2022-02-28 09:02:43 +00:00
#include "parser.h"
2022-03-10 07:36:06 +00:00
#include "parInt.h"
#include "parToken.h"
2022-02-28 09:02:43 +00:00
static bool isInsertSql(const char* pStr, size_t length) {
int32_t index = 0;
do {
SToken t0 = tStrGetToken((char*) pStr, &index, false);
if (t0.type != TK_NK_LP) {
2022-02-28 09:02:43 +00:00
return t0.type == TK_INSERT || t0.type == TK_IMPORT;
}
} while (1);
}
2022-02-28 09:56:38 +00:00
static int32_t parseSqlIntoAst(SParseContext* pCxt, SQuery** pQuery) {
int32_t code = doParse(pCxt, pQuery);
if (TSDB_CODE_SUCCESS == code) {
code = doTranslate(pCxt, *pQuery);
}
return code;
}
2022-02-28 09:02:43 +00:00
int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery) {
2022-03-11 09:50:04 +00:00
int32_t code = TSDB_CODE_SUCCESS;
2022-02-28 09:02:43 +00:00
if (isInsertSql(pCxt->pSql, pCxt->sqlLen)) {
2022-03-11 09:50:04 +00:00
code = parseInsertSql(pCxt, pQuery);
2022-02-28 09:02:43 +00:00
} else {
2022-03-11 09:50:04 +00:00
code = parseSqlIntoAst(pCxt, pQuery);
2022-02-28 09:02:43 +00:00
}
2022-03-11 09:50:04 +00:00
terrno = code;
return code;
2022-02-28 09:02:43 +00:00
}
void qDestroyQuery(SQuery* pQueryNode) {
2022-03-10 07:36:06 +00:00
if (NULL == pQueryNode) {
return;
}
nodesDestroyNode(pQueryNode->pRoot);
tfree(pQueryNode->pResSchema);
if (NULL != pQueryNode->pCmdMsg) {
tfree(pQueryNode->pCmdMsg->pMsg);
tfree(pQueryNode->pCmdMsg);
}
tfree(pQueryNode);
2022-02-28 09:02:43 +00:00
}