[TD-6285]<enhance>: set cloneCurrentDBName as a public util function
This commit is contained in:
parent
28d689f47d
commit
8424e83eee
|
@ -364,6 +364,8 @@ STblCond* tsGetTableFilter(SArray* filters, uint64_t uid, int16_t idx);
|
|||
|
||||
void tscRemoveCachedTableMeta(STableMetaInfo* pTableMetaInfo, uint64_t id);
|
||||
|
||||
char* cloneCurrentDBName(SSqlObj* pSql);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#include "qScript.h"
|
||||
#include "ttype.h"
|
||||
#include "qFilter.h"
|
||||
#include "httpInt.h"
|
||||
|
||||
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
|
||||
|
||||
|
@ -72,7 +71,6 @@ static int convertTimestampStrToInt64(tVariant *pVar, int32_t precision);
|
|||
static bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType, uint8_t precision);
|
||||
|
||||
static bool has(SArray* pFieldList, int32_t startIdx, const char* name);
|
||||
static char* cloneCurrentDBName(SSqlObj* pSql);
|
||||
static int32_t getDelimiterIndex(SStrToken* pTableName);
|
||||
static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd);
|
||||
static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pCmd);
|
||||
|
@ -1687,34 +1685,6 @@ static bool has(SArray* pFieldList, int32_t startIdx, const char* name) {
|
|||
|
||||
static char* getAccountId(SSqlObj* pSql) { return pSql->pTscObj->acctId; }
|
||||
|
||||
static char* cloneCurrentDBName(SSqlObj* pSql) {
|
||||
char *p = NULL;
|
||||
HttpContext *pCtx = NULL;
|
||||
|
||||
pthread_mutex_lock(&pSql->pTscObj->mutex);
|
||||
STscObj *pTscObj = pSql->pTscObj;
|
||||
switch (pTscObj->from) {
|
||||
case TAOS_REQ_FROM_HTTP:
|
||||
pCtx = pSql->param;
|
||||
if (pCtx && pCtx->db[0] != '\0') {
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN] = {0};
|
||||
int32_t len = sprintf(db, "%s%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pCtx->db);
|
||||
assert(len <= sizeof(db));
|
||||
|
||||
p = strdup(db);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (p == NULL) {
|
||||
p = strdup(pSql->pTscObj->db);
|
||||
}
|
||||
pthread_mutex_unlock(&pSql->pTscObj->mutex);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/* length limitation, strstr cannot be applied */
|
||||
static int32_t getDelimiterIndex(SStrToken* pTableName) {
|
||||
for (uint32_t i = 0; i < pTableName->n; ++i) {
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "tscUtil.h"
|
||||
#include "tsclient.h"
|
||||
#include "ttimer.h"
|
||||
#include "httpInt.h"
|
||||
|
||||
int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo) = {0};
|
||||
|
||||
|
@ -1430,14 +1429,10 @@ int32_t tscBuildSyncDbReplicaMsg(SSqlObj* pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
|
||||
int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
||||
STscObj *pObj = pSql->pTscObj;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
pCmd->msgType = TSDB_MSG_TYPE_CM_SHOW;
|
||||
pCmd->payloadLen = sizeof(SShowMsg) + 100;
|
||||
|
||||
char *p = NULL;
|
||||
HttpContext *pCtx = NULL;
|
||||
|
||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
|
||||
tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self);
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
@ -1456,28 +1451,9 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
}
|
||||
|
||||
if (tNameIsEmpty(&pTableMetaInfo->name)) {
|
||||
pthread_mutex_lock(&pObj->mutex);
|
||||
STscObj *pTscObj = pSql->pTscObj;
|
||||
switch (pTscObj->from) {
|
||||
case TAOS_REQ_FROM_HTTP:
|
||||
pCtx = pSql->param;
|
||||
if (pCtx && pCtx->db[0] != '\0') {
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN] = {0};
|
||||
int32_t len = sprintf(db, "%s%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pCtx->db);
|
||||
assert(len <= sizeof(db));
|
||||
|
||||
p = db;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (p == NULL) {
|
||||
tstrncpy(pShowMsg->db, pObj->db, sizeof(pShowMsg->db));
|
||||
} else {
|
||||
tstrncpy(pShowMsg->db, p, strlen(p) + 1);
|
||||
}
|
||||
pthread_mutex_unlock(&pObj->mutex);
|
||||
char *p = cloneCurrentDBName(pSql);
|
||||
tstrncpy(pShowMsg->db, p, sizeof(pShowMsg->db));
|
||||
tfree(p);
|
||||
} else {
|
||||
tNameGetFullDbName(&pTableMetaInfo->name, pShowMsg->db);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "tsclient.h"
|
||||
#include "ttimer.h"
|
||||
#include "ttokendef.h"
|
||||
#include "httpInt.h"
|
||||
|
||||
static void freeQueryInfoImpl(SQueryInfo* pQueryInfo);
|
||||
|
||||
|
@ -5065,3 +5066,31 @@ void tscRemoveCachedTableMeta(STableMetaInfo* pTableMetaInfo, uint64_t id) {
|
|||
taosHashRemove(tscTableMetaMap, fname, len);
|
||||
tscDebug("0x%"PRIx64" remove table meta %s, numOfRemain:%d", id, fname, (int32_t) taosHashGetSize(tscTableMetaMap));
|
||||
}
|
||||
|
||||
char* cloneCurrentDBName(SSqlObj* pSql) {
|
||||
char *p = NULL;
|
||||
HttpContext *pCtx = NULL;
|
||||
|
||||
pthread_mutex_lock(&pSql->pTscObj->mutex);
|
||||
STscObj *pTscObj = pSql->pTscObj;
|
||||
switch (pTscObj->from) {
|
||||
case TAOS_REQ_FROM_HTTP:
|
||||
pCtx = pSql->param;
|
||||
if (pCtx && pCtx->db[0] != '\0') {
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN] = {0};
|
||||
int32_t len = sprintf(db, "%s%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pCtx->db);
|
||||
assert(len <= sizeof(db));
|
||||
|
||||
p = strdup(db);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (p == NULL) {
|
||||
p = strdup(pSql->pTscObj->db);
|
||||
}
|
||||
pthread_mutex_unlock(&pSql->pTscObj->mutex);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue