提交 c8946cdd 编写于 作者: B Benguang Zhao

fix: Support backquote escape for db names

上级 0797d353
...@@ -5,6 +5,7 @@ build/ ...@@ -5,6 +5,7 @@ build/
cmake-build-debug/ cmake-build-debug/
cmake-build-release/ cmake-build-release/
cscope.out cscope.out
cscope.files
.DS_Store .DS_Store
debug/ debug/
release/ release/
......
此差异已折叠。
...@@ -1418,7 +1418,7 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue ...@@ -1418,7 +1418,7 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue
}; };
SUdfInfo* pUdfInfo = NULL; SUdfInfo* pUdfInfo = NULL;
size_t size = tscNumOfExprs(px); size_t size = tscNumOfExprs(px);
for (int32_t j = 0; j < size; ++j) { for (int32_t j = 0; j < size; ++j) {
SExprInfo* pExprInfo = tscExprGet(px, j); SExprInfo* pExprInfo = tscExprGet(px, j);
...@@ -1429,7 +1429,7 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue ...@@ -1429,7 +1429,7 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue
pSql->res.code = tscInvalidOperationMsg(pSql->cmd.payload, "only one udf allowed", NULL); pSql->res.code = tscInvalidOperationMsg(pSql->cmd.payload, "only one udf allowed", NULL);
return; return;
} }
pUdfInfo = taosArrayGet(px->pUdfInfo, -1 * functionId - 1); pUdfInfo = taosArrayGet(px->pUdfInfo, -1 * functionId - 1);
int32_t code = initUdfInfo(pUdfInfo); int32_t code = initUdfInfo(pUdfInfo);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
...@@ -1537,7 +1537,7 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue ...@@ -1537,7 +1537,7 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue
px->pQInfo->runtimeEnv.udfIsCopy = true; px->pQInfo->runtimeEnv.udfIsCopy = true;
px->pQInfo->runtimeEnv.pUdfInfo = pUdfInfo; px->pQInfo->runtimeEnv.pUdfInfo = pUdfInfo;
tfree(schema); tfree(schema);
// set the pRuntimeEnv for pSourceOperator // set the pRuntimeEnv for pSourceOperator
...@@ -2702,11 +2702,9 @@ int32_t tscExprTopBottomIndex(SQueryInfo* pQueryInfo){ ...@@ -2702,11 +2702,9 @@ int32_t tscExprTopBottomIndex(SQueryInfo* pQueryInfo){
SExprInfo* pExpr = tscExprGet(pQueryInfo, i); SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
if (pExpr == NULL) if (pExpr == NULL)
continue; continue;
if (pExpr->base.functionId == TSDB_FUNC_TOP if (pExpr->base.functionId == TSDB_FUNC_TOP || pExpr->base.functionId == TSDB_FUNC_BOTTOM ||
|| pExpr->base.functionId == TSDB_FUNC_BOTTOM pExpr->base.functionId == TSDB_FUNC_SAMPLE || pExpr->base.functionId == TSDB_FUNC_UNIQUE ||
|| pExpr->base.functionId == TSDB_FUNC_SAMPLE pExpr->base.functionId == TSDB_FUNC_TAIL) {
|| pExpr->base.functionId == TSDB_FUNC_UNIQUE
|| pExpr->base.functionId == TSDB_FUNC_TAIL) {
return i; return i;
} }
} }
...@@ -3068,6 +3066,12 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) ...@@ -3068,6 +3066,12 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded)
} }
} }
if (escapeEnabled && pToken->type == TK_ID) {
if (pToken->z[0] == TS_BACKQUOTE_CHAR) {
pToken->n = stringProcess(pToken->z, pToken->n);
firstPartQuote = true;
}
}
int32_t firstPartLen = pToken->n; int32_t firstPartLen = pToken->n;
pToken->z = sep + 1; pToken->z = sep + 1;
...@@ -4191,20 +4195,20 @@ static void tscSubqueryCompleteCallback(void* param, TAOS_RES* tres, int code) { ...@@ -4191,20 +4195,20 @@ static void tscSubqueryCompleteCallback(void* param, TAOS_RES* tres, int code) {
} }
int32_t doInitSubState(SSqlObj* pSql, int32_t numOfSubqueries) { int32_t doInitSubState(SSqlObj* pSql, int32_t numOfSubqueries) {
//bug fix. Above doInitSubState level, the loop invocation with the same SSqlObj will be fail. // bug fix. Above doInitSubState level, the loop invocation with the same SSqlObj will be fail.
//assert(pSql->subState.numOfSub == 0 && pSql->pSubs == NULL && pSql->subState.states == NULL); // assert(pSql->subState.numOfSub == 0 && pSql->pSubs == NULL && pSql->subState.states == NULL);
if(pSql->pSubs) { if(pSql->pSubs) {
free(pSql->pSubs); free(pSql->pSubs);
pSql->pSubs = NULL; pSql->pSubs = NULL;
} }
if(pSql->subState.states) { if(pSql->subState.states) {
free(pSql->subState.states); free(pSql->subState.states);
pSql->subState.states = NULL; pSql->subState.states = NULL;
} }
pSql->subState.numOfSub = numOfSubqueries; pSql->subState.numOfSub = numOfSubqueries;
pSql->pSubs = calloc(pSql->subState.numOfSub, POINTER_BYTES); pSql->pSubs = calloc(pSql->subState.numOfSub, POINTER_BYTES);
pSql->subState.states = calloc(pSql->subState.numOfSub, sizeof(int8_t)); pSql->subState.states = calloc(pSql->subState.numOfSub, sizeof(int8_t));
...@@ -4230,7 +4234,7 @@ void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo) { ...@@ -4230,7 +4234,7 @@ void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
(*pSql->fp)(pSql->param, pSql, 0); (*pSql->fp)(pSql->param, pSql, 0);
} }
return ; return ;
} }
if (pSql->cmd.command == TSDB_SQL_SELECT) { if (pSql->cmd.command == TSDB_SQL_SELECT) {
tscAddIntoSqlList(pSql); tscAddIntoSqlList(pSql);
......
...@@ -148,7 +148,7 @@ void shellInit(SShellArguments *_args) { ...@@ -148,7 +148,7 @@ void shellInit(SShellArguments *_args) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
#endif #endif
return; return;
} }
...@@ -335,7 +335,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { ...@@ -335,7 +335,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
int64_t oresult = atomic_load_64(&result); int64_t oresult = atomic_load_64(&result);
if (regex_match(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) { if (regex_match(command, "^\\s*use\\s+([a-zA-Z0-9_]+|`.+`)\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) {
fprintf(stdout, "Database changed.\n\n"); fprintf(stdout, "Database changed.\n\n");
fflush(stdout); fflush(stdout);
...@@ -1520,7 +1520,7 @@ int wsclient_print_data(int rows, TAOS_FIELD *fields, int cols, int64_t id, int ...@@ -1520,7 +1520,7 @@ int wsclient_print_data(int rows, TAOS_FIELD *fields, int cols, int64_t id, int
if (*pshowed_rows == DEFAULT_RES_SHOW_NUM) { if (*pshowed_rows == DEFAULT_RES_SHOW_NUM) {
free(recv_buffer); free(recv_buffer);
return 0; return 0;
} }
for (int c = 0; c < cols; c++) { for (int c = 0; c < cols; c++) {
pos = start; pos = start;
pos += i * fields[c].bytes; pos += i * fields[c].bytes;
......
...@@ -719,13 +719,14 @@ static int32_t monBuildMnodesTotalSql(char *sql) { ...@@ -719,13 +719,14 @@ static int32_t monBuildMnodesTotalSql(char *sql) {
static int32_t monGetVgroupsTotalStats(char *dbName, int32_t *totalVgroups, static int32_t monGetVgroupsTotalStats(char *dbName, int32_t *totalVgroups,
int32_t *totalVgroupsAlive) { int32_t *totalVgroupsAlive) {
char subsql[TSDB_DB_NAME_LEN + 14]; int bufLen = TSDB_DB_NAME_LEN + 16;
char subsql[bufLen];
memset(subsql, 0, sizeof(subsql)); memset(subsql, 0, sizeof(subsql));
snprintf(subsql, TSDB_DB_NAME_LEN + 13, "show %s.vgroups", dbName); snprintf(subsql, bufLen - 1, "show `%s`.vgroups", dbName);
TAOS_RES *result = taos_query(tsMonitor.conn, subsql); TAOS_RES *result = taos_query(tsMonitor.conn, subsql);
int32_t code = taos_errno(result); int32_t code = taos_errno(result);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
monError("failed to execute cmd: show %s.vgroups, reason:%s", dbName, tstrerror(code)); monError("failed to execute cmd: show `%s`.vgroups, reason:%s", dbName, tstrerror(code));
} }
TAOS_ROW row; TAOS_ROW row;
...@@ -1110,11 +1111,11 @@ static uint32_t monBuildVgroupsInfoSql(char *sql, char *dbName) { ...@@ -1110,11 +1111,11 @@ static uint32_t monBuildVgroupsInfoSql(char *sql, char *dbName) {
int64_t ts = taosGetTimestampUs(); int64_t ts = taosGetTimestampUs();
memset(sql, 0, SQL_LENGTH + 1); memset(sql, 0, SQL_LENGTH + 1);
snprintf(sql, SQL_LENGTH, "show %s.vgroups", dbName); snprintf(sql, SQL_LENGTH, "show `%s`.vgroups", dbName);
TAOS_RES *result = taos_query(tsMonitor.conn, sql); TAOS_RES *result = taos_query(tsMonitor.conn, sql);
int32_t code = taos_errno(result); int32_t code = taos_errno(result);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
monError("failed to execute cmd: show %s.vgroups, reason:%s", dbName, tstrerror(code)); monError("failed to execute cmd: show `%s`.vgroups, reason:%s", dbName, tstrerror(code));
} }
TAOS_ROW row; TAOS_ROW row;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册