fix: failed to identify dbName when only ? exists

This commit is contained in:
xjzhou 2024-06-26 16:38:21 +08:00
parent 1a32279f7f
commit 42361fcd45
1 changed files with 6 additions and 6 deletions

View File

@ -49,7 +49,7 @@ bool qIsInsertValuesSql(const char* pStr, size_t length) {
} }
bool qParseDbName(const char* pStr, size_t length, char** pDbName) { bool qParseDbName(const char* pStr, size_t length, char** pDbName) {
(void)length; (void) length;
int32_t index = 0; int32_t index = 0;
SToken t; SToken t;
@ -58,28 +58,28 @@ bool qParseDbName(const char* pStr, size_t length, char** pDbName) {
return false; return false;
} }
t = tStrGetToken((char *)pStr, &index, false, NULL); t = tStrGetToken((char *) pStr, &index, false, NULL);
if (TK_INSERT != t.type && TK_IMPORT != t.type) { if (TK_INSERT != t.type && TK_IMPORT != t.type) {
*pDbName = NULL; *pDbName = NULL;
return false; return false;
} }
t = tStrGetToken((char *)pStr, &index, false, NULL); t = tStrGetToken((char *) pStr, &index, false, NULL);
if (TK_INTO != t.type) { if (TK_INTO != t.type) {
*pDbName = NULL; *pDbName = NULL;
return false; return false;
} }
t = tStrGetToken((char *)pStr, &index, false, NULL); t = tStrGetToken((char *) pStr, &index, false, NULL);
if (t.n == 0 || t.z == NULL) { if (t.n == 0 || t.z == NULL) {
*pDbName = NULL; *pDbName = NULL;
return false; return false;
} }
char *dotPos = strchr(t.z, '.'); char *dotPos = strnchr(t.z, '.', t.n, true);
if (dotPos != NULL) { if (dotPos != NULL) {
int dbNameLen = dotPos - t.z; int dbNameLen = dotPos - t.z;
*pDbName = taosMemoryMalloc(dbNameLen + 1); *pDbName = taosMemoryMalloc(dbNameLen + 1);
if (NULL == *pDbName) { if (*pDbName == NULL) {
return false; return false;
} }
strncpy(*pDbName, t.z, dbNameLen); strncpy(*pDbName, t.z, dbNameLen);