From c7f108181d9843953f3a7b01db5f959010803fa1 Mon Sep 17 00:00:00 2001 From: slzhou Date: Tue, 19 Mar 2024 16:31:51 +0800 Subject: [PATCH] feat:show create table and desc table --- source/libs/command/src/command.c | 12 +++++++++--- source/libs/parser/src/parTranslater.c | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index c45a8931d2..2136ef7d6d 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -113,7 +113,13 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t bytes = getSchemaBytes(pMeta->schema + i); colDataSetVal(pCol3, pBlock->info.rows, (const char*)&bytes, false); if (TSDB_VIEW_TABLE != pMeta->tableType) { - STR_TO_VARSTR(buf, i >= pMeta->tableInfo.numOfColumns ? "TAG" : ""); + if (i >= pMeta->tableInfo.numOfColumns) { + STR_TO_VARSTR(buf, "TAG"); + } else if (i == 1 && pMeta->schema[i].flags & COL_IS_KEY) { + STR_TO_VARSTR(buf, "PRIMARY KEY") + } else { + STR_TO_VARSTR(buf, ""); + } } else { STR_TO_VARSTR(buf, "VIEW COL"); } @@ -495,8 +501,8 @@ void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) { } else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) { sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)); } - - *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type); + char* pk = (pSchema->flags & COL_IS_KEY) ? "PRIMARY KEY" : ""; + *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s %s", ((i > 0) ? ", " : ""), pSchema->name, type, pk); } } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index e767bdac6e..462e14c287 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -921,7 +921,7 @@ static bool isPrimaryKey(STempTableNode* pTable, SNode* pExpr) { } static bool hasPkInTable(STableMeta* pTableMeta) { - return pTableMeta->tableInfo.numOfColumns>=2 && pTableMeta->schema[1].flags | COL_IS_KEY; + return pTableMeta->tableInfo.numOfColumns>=2 && pTableMeta->schema[1].flags & COL_IS_KEY; } static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* pColSchema, int32_t tagFlag,