fix:add interface for taos_get_current_db
This commit is contained in:
parent
730fbe42cb
commit
e1020b7967
|
@ -208,7 +208,7 @@ DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res);
|
|||
|
||||
DLL_EXPORT const char *taos_get_server_info(TAOS *taos);
|
||||
DLL_EXPORT const char *taos_get_client_info();
|
||||
DLL_EXPORT const char *taos_get_current_db(TAOS *taos, size_t *required);
|
||||
DLL_EXPORT int taos_get_current_db(TAOS *taos, char *database, int len, int *required);
|
||||
|
||||
DLL_EXPORT const char *taos_errstr(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_errno(TAOS_RES *res);
|
||||
|
|
|
@ -686,13 +686,32 @@ const char *taos_get_server_info(TAOS *taos) {
|
|||
return pTscObj->sDetailVer;
|
||||
}
|
||||
|
||||
const char *taos_get_current_db(TAOS *taos, size_t *required) {
|
||||
int taos_get_current_db(TAOS *taos, char *database, int len, int *required) {
|
||||
STscObj *pTscObj = acquireTscObj(*(int64_t *)taos);
|
||||
if (pTscObj == NULL) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
return pTscObj->db;
|
||||
|
||||
int code = TSDB_CODE_SUCCESS;
|
||||
taosThreadMutexLock(&pTscObj->mutex);
|
||||
if(database == NULL || len <= 0){
|
||||
if(required != NULL) *required = strlen(pTscObj->db) + 1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(len < strlen(pTscObj->db) + 1){
|
||||
tstrncpy(database, pTscObj->db, len);
|
||||
if(required) *required = strlen(pTscObj->db) + 1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
code = -1;
|
||||
}else{
|
||||
strcpy(database, pTscObj->db);
|
||||
code = 0;
|
||||
}
|
||||
taosThreadMutexUnlock(&pTscObj->mutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
static void destoryTablesReq(void *p) {
|
||||
|
|
|
@ -179,7 +179,6 @@ static const SSysDbTableSchema userTagsSchema[] = {
|
|||
static const SSysDbTableSchema userColsSchema[] = {
|
||||
{.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "col_name", .bytes = TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "col_type", .bytes = 32 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "col_length", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
|
||||
|
|
|
@ -140,6 +140,9 @@ static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo,
|
|||
SMetaReader* smrChildTable, const char* dbname, const char* tableName,
|
||||
int32_t* pNumOfRows, const SSDataBlock* dataBlock);
|
||||
|
||||
static int32_t sysTableUserColsFillOneTableCols(const SSysTableScanInfo* pInfo, SMetaReader* smrTable, const char* dbname,
|
||||
int32_t* pNumOfRows, const SSDataBlock* dataBlock);
|
||||
|
||||
static void relocateAndFilterSysTagsScanResult(SSysTableScanInfo* pInfo, int32_t numOfRows, SSDataBlock* dataBlock,
|
||||
SFilterInfo* pFilterInfo);
|
||||
|
||||
|
@ -443,38 +446,26 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) {
|
|||
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(tableName, condTableName);
|
||||
|
||||
SMetaReader smrChildTable = {0};
|
||||
metaReaderInit(&smrChildTable, pInfo->readHandle.meta, 0);
|
||||
int32_t code = metaGetTableEntryByName(&smrChildTable, condTableName);
|
||||
SMetaReader smrTable = {0};
|
||||
metaReaderInit(&smrTable, pInfo->readHandle.meta, 0);
|
||||
int32_t code = metaGetTableEntryByName(&smrTable, condTableName);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
// terrno has been set by metaGetTableEntryByName, therefore, return directly
|
||||
metaReaderClear(&smrChildTable);
|
||||
metaReaderClear(&smrTable);
|
||||
blockDataDestroy(dataBlock);
|
||||
pInfo->loadInfo.totalRows = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (smrChildTable.me.type != TSDB_CHILD_TABLE) {
|
||||
metaReaderClear(&smrChildTable);
|
||||
if (smrTable.me.type == TSDB_CHILD_TABLE) {
|
||||
metaReaderClear(&smrTable);
|
||||
blockDataDestroy(dataBlock);
|
||||
pInfo->loadInfo.totalRows = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SMetaReader smrSuperTable = {0};
|
||||
metaReaderInit(&smrSuperTable, pInfo->readHandle.meta, META_READER_NOLOCK);
|
||||
code = metaGetTableEntryByUid(&smrSuperTable, smrChildTable.me.ctbEntry.suid);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
// terrno has been set by metaGetTableEntryByUid
|
||||
metaReaderClear(&smrSuperTable);
|
||||
metaReaderClear(&smrChildTable);
|
||||
blockDataDestroy(dataBlock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sysTableUserTagsFillOneTableTags(pInfo, &smrSuperTable, &smrChildTable, dbname, tableName, &numOfRows, dataBlock);
|
||||
metaReaderClear(&smrSuperTable);
|
||||
metaReaderClear(&smrChildTable);
|
||||
sysTableUserColsFillOneTableCols(pInfo, &smrTable, dbname, &numOfRows, dataBlock);
|
||||
metaReaderClear(&smrTable);
|
||||
|
||||
if (numOfRows > 0) {
|
||||
relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo);
|
||||
|
@ -492,29 +483,11 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
while ((ret = metaTbCursorNext(pInfo->pCur)) == 0) {
|
||||
if (pInfo->pCur->mr.me.type != TSDB_CHILD_TABLE) {
|
||||
if (pInfo->pCur->mr.me.type == TSDB_CHILD_TABLE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(tableName, pInfo->pCur->mr.me.name);
|
||||
|
||||
SMetaReader smrSuperTable = {0};
|
||||
metaReaderInit(&smrSuperTable, pInfo->readHandle.meta, 0);
|
||||
uint64_t suid = pInfo->pCur->mr.me.ctbEntry.suid;
|
||||
int32_t code = metaGetTableEntryByUid(&smrSuperTable, suid);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("failed to get super table meta, uid:0x%" PRIx64 ", code:%s, %s", suid, tstrerror(terrno),
|
||||
GET_TASKID(pTaskInfo));
|
||||
metaReaderClear(&smrSuperTable);
|
||||
metaCloseTbCursor(pInfo->pCur);
|
||||
pInfo->pCur = NULL;
|
||||
T_LONG_JMP(pTaskInfo->env, terrno);
|
||||
}
|
||||
|
||||
sysTableUserTagsFillOneTableTags(pInfo, &smrSuperTable, &pInfo->pCur->mr, dbname, tableName, &numOfRows, dataBlock);
|
||||
|
||||
metaReaderClear(&smrSuperTable);
|
||||
sysTableUserColsFillOneTableCols(pInfo, &pInfo->pCur->mr, dbname, &numOfRows, dataBlock);
|
||||
|
||||
if (numOfRows >= pOperator->resultInfo.capacity) {
|
||||
relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo);
|
||||
|
@ -857,6 +830,72 @@ static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t sysTableUserColsFillOneTableCols(const SSysTableScanInfo* pInfo, SMetaReader* smrTable, const char* dbname,
|
||||
int32_t* pNumOfRows, const SSDataBlock* dataBlock) {
|
||||
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(tableName, smrTable->me.name);
|
||||
|
||||
SSchemaWrapper schemaRow = {0};
|
||||
if(smrTable->me.type == TSDB_SUPER_TABLE){
|
||||
schemaRow = smrTable->me.stbEntry.schemaRow;
|
||||
}else if(smrTable->me.type == TSDB_NORMAL_TABLE){
|
||||
schemaRow = smrTable->me.ntbEntry.schemaRow;
|
||||
}
|
||||
int32_t numOfRows = *pNumOfRows;
|
||||
|
||||
int32_t numOfCols = schemaRow.nCols;
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfoData = NULL;
|
||||
|
||||
// table name
|
||||
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 0);
|
||||
colDataAppend(pColInfoData, numOfRows, tableName, tableName == NULL ? true : false);
|
||||
|
||||
// database name
|
||||
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 1);
|
||||
colDataAppend(pColInfoData, numOfRows, dbname, false);
|
||||
|
||||
// col name
|
||||
char colName[TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_TO_VARSTR(colName, schemaRow.pSchema[i].name);
|
||||
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 2);
|
||||
colDataAppend(pColInfoData, numOfRows, colName, false);
|
||||
|
||||
// col type
|
||||
int8_t colType = schemaRow.pSchema[i].type;
|
||||
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 3);
|
||||
char colTypeStr[VARSTR_HEADER_SIZE + 32];
|
||||
int colTypeLen = sprintf(varDataVal(colTypeStr), "%s", tDataTypes[colType].name);
|
||||
if (colType == TSDB_DATA_TYPE_VARCHAR) {
|
||||
colTypeLen += sprintf(varDataVal(colTypeStr) + colTypeLen, "(%d)",
|
||||
(int32_t)(schemaRow.pSchema[i].bytes - VARSTR_HEADER_SIZE));
|
||||
} else if (colType == TSDB_DATA_TYPE_NCHAR) {
|
||||
colTypeLen += sprintf(
|
||||
varDataVal(colTypeStr) + colTypeLen, "(%d)",
|
||||
(int32_t)((schemaRow.pSchema[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
|
||||
}
|
||||
varDataSetLen(colTypeStr, colTypeLen);
|
||||
colDataAppend(pColInfoData, numOfRows, (char*)colTypeStr, false);
|
||||
|
||||
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 4);
|
||||
colDataAppend(pColInfoData, numOfRows, (const char*)&schemaRow.pSchema[i].bytes, false);
|
||||
|
||||
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 5);
|
||||
colDataAppend(pColInfoData, numOfRows, NULL, true);
|
||||
|
||||
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 6);
|
||||
colDataAppend(pColInfoData, numOfRows, NULL, true);
|
||||
|
||||
pColInfoData = taosArrayGet(dataBlock->pDataBlock, 7);
|
||||
colDataAppend(pColInfoData, numOfRows, NULL, true);
|
||||
++numOfRows;
|
||||
}
|
||||
|
||||
*pNumOfRows = numOfRows;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SSDataBlock* buildInfoSchemaTableMetaBlock(char* tableName) {
|
||||
size_t size = 0;
|
||||
const SSysTableMeta* pMeta = NULL;
|
||||
|
|
|
@ -147,16 +147,6 @@ static int32_t collectMetaKeyFromInsTags(SCollectMetaKeyCxt* pCxt) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromInsCols(SCollectMetaKeyCxt* pCxt) {
|
||||
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pStmt;
|
||||
SName name = {0};
|
||||
int32_t code = getVnodeSysTableTargetName(pCxt->pParseCxt->acctId, pSelect->pWhere, &name);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = collectMetaKeyFromInsTagsImpl(pCxt, &name);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, const char* pDb, const char* pTable,
|
||||
AUTH_TYPE authType) {
|
||||
int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
|
||||
|
@ -180,11 +170,6 @@ static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, const c
|
|||
QUERY_NODE_SELECT_STMT == nodeType(pCxt->pStmt)) {
|
||||
code = collectMetaKeyFromInsTags(pCxt);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code &&
|
||||
0 == strcmp(pTable, TSDB_INS_TABLE_COLS) &&
|
||||
QUERY_NODE_SELECT_STMT == nodeType(pCxt->pStmt)) {
|
||||
code = collectMetaKeyFromInsCols(pCxt);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -490,19 +475,6 @@ static int32_t collectMetaKeyFromShowTags(SCollectMetaKeyCxt* pCxt, SShowStmt* p
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromShowCols(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
|
||||
int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_COLS,
|
||||
pCxt->pMetaCache);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pTbName) {
|
||||
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal,
|
||||
((SValueNode*)pStmt->pTbName)->literal, pCxt->pMetaCache);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromShowStableTags(SCollectMetaKeyCxt* pCxt, SShowTableTagsStmt* pStmt) {
|
||||
return collectMetaKeyFromRealTableImpl(pCxt, ((SValueNode*)pStmt->pDbName)->literal,
|
||||
((SValueNode*)pStmt->pTbName)->literal, AUTH_TYPE_READ);
|
||||
|
|
|
@ -162,13 +162,6 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
|
|||
.numOfShowCols = 1,
|
||||
.pShowCols = {"*"}
|
||||
},
|
||||
{
|
||||
.showType = QUERY_NODE_SHOW_TAGS_STMT,
|
||||
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
|
||||
.pTableName = TSDB_INS_TABLE_COLS,
|
||||
.numOfShowCols = 1,
|
||||
.pShowCols = {"*"}
|
||||
},
|
||||
{
|
||||
.showType = QUERY_NODE_SHOW_USERS_STMT,
|
||||
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
|
||||
|
|
Loading…
Reference in New Issue