diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index 9393a62e26..0289469221 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -2429,17 +2429,18 @@ static int32_t checkTableClauseFirstToken(SInsertParseContext* pCxt, SVnodeModif } // db.? situation,ensure that the only thing following the '.' mark is '?' - char *tbNameAfterDbName = strchr(pTbName->z, '.'); - if ((tbNameAfterDbName != NULL) && (tbNameAfterDbName + 1 - pTbName->z == pTbName->n - 1) && - (*(tbNameAfterDbName + 1) == '?')) { + char *tbNameAfterDbName = strnchr(pTbName->z, '.', pTbName->n, true); + if ((tbNameAfterDbName != NULL) && (*(tbNameAfterDbName + 1) == '?')) { char *tbName = NULL; + if (NULL == pCxt->pComCxt->pStmtCb) { + return buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", pTbName->z); + } int32_t code = (*pCxt->pComCxt->pStmtCb->getTbNameFn)(pCxt->pComCxt->pStmtCb->pStmt, &tbName); - if (TSDB_CODE_SUCCESS == code) { - pTbName->z = tbName; - pTbName->n = strlen(tbName); - } else { + if (code != TSDB_CODE_SUCCESS) { return code; } + pTbName->z = tbName; + pTbName->n = strlen(tbName); } *pHasData = true; diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 53ea19f416..cc5d2a1cdf 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -790,6 +790,16 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr, bool* pIgnoreC return t0; } + // check the table name is '?', db.?asf is not valid. + if (TK_NK_QUESTION == type) { + tGetToken(&str[*i + t0.n + 2], &type); + if (TK_NK_SPACE != type) { + t0.type = TK_NK_ILLEGAL; + t0.n = 0; + return t0; + } + } + t0.n += len + 1; } else {