diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 9005ac8acbaa77f89e2288dc15b60ca519d24432..8e4bdc8b2b436a43cde9a4649e31c0430facbc88 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -295,7 +295,7 @@ void tscSCreateCallBack(void *param, TAOS_RES *tres, int code) { taos_fetch_rows_a(tres, tscSCreateCallBack, param); builder->callStage = SCREATE_CALLBACK_RETRIEVE; } else { - char *result = calloc(1, TSDB_MAX_BINARY_LEN); + char *result = calloc(1, TSDB_MAX_SQL_LEN); pRes->code = builder->fp(builder, result); taos_free_result(pSql); @@ -359,6 +359,7 @@ TAOS_ROW tscFetchRow(void *param) { tscClearSqlOwner(pSql); return data; } + static int32_t tscGetTableTagValue(SCreateBuilder *builder, char *result) { TAOS_ROW row = tscFetchRow(builder); SSqlObj* pSql = builder->pInterSql; @@ -381,16 +382,16 @@ static int32_t tscGetTableTagValue(SCreateBuilder *builder, char *result) { int32_t ret = tscGetNthFieldResult(row, fields, lengths, i, buf); if (i == 0) { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s", "("); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "%s", "("); } if ((fields[i].type == TSDB_DATA_TYPE_NCHAR || fields[i].type == TSDB_DATA_TYPE_BINARY || fields[i].type == TSDB_DATA_TYPE_TIMESTAMP) && 0 == ret) { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "\"%s\",", buf); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "\"%s\",", buf); } else if (fields[i].type == TSDB_DATA_TYPE_JSON) { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "'%s,", buf); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "'%s,", buf); } else { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s,", buf); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "%s,", buf); } free(buf); @@ -487,14 +488,14 @@ int32_t tscRebuildCreateTableStatement(void *param,char *result) { SCreateBuilder *builder = (SCreateBuilder *)param; int32_t code = TSDB_CODE_SUCCESS; - char *buf = calloc(1,TSDB_MAX_BINARY_LEN); + char *buf = calloc(1,TSDB_MAX_SQL_LEN); if (buf == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } code = tscGetTableTagValue(builder, buf); if (code == TSDB_CODE_SUCCESS) { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "CREATE TABLE `%s` USING `%s` TAGS %s", builder->buf, builder->sTableName, buf); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "CREATE TABLE `%s` USING `%s` TAGS %s", builder->buf, builder->sTableName, buf); code = tscSCreateBuildResult(builder->pParentSql, SCREATE_BUILD_TABLE, builder->buf, result); } free(buf); @@ -537,7 +538,7 @@ static int32_t tscGetDBInfo(SCreateBuilder *builder, char *result) { int32_t* lengths = taos_fetch_lengths(pSql); int32_t ret = tscGetNthFieldResult(row, fields, lengths, 0, buf); if (0 == ret && 0 == strcmp(buf, builder->buf)) { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "CREATE DATABASE `%s`", buf); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "CREATE DATABASE `%s`", buf); for (int i = 1; i < num_fields; i++) { for (int j = 0; showColumns[j][0] != NULL; j++) { if (STR_NOCASE_EQUAL(fields[i].name, strlen(fields[i].name), showColumns[j][0], strlen(showColumns[j][0]))) { @@ -545,9 +546,9 @@ static int32_t tscGetDBInfo(SCreateBuilder *builder, char *result) { ret = tscGetNthFieldResult(row, fields, lengths, i, buf); if (ret == 0) { if (STR_NOCASE_EQUAL(showColumns[j][0], strlen(showColumns[j][0]), "PRECISION", strlen("PRECISION"))) { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), " %s '%s'", showColumns[j][1], buf); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), " %s '%s'", showColumns[j][1], buf); } else { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), " %s %s", showColumns[j][1], buf); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), " %s %s", showColumns[j][1], buf); } } } @@ -569,7 +570,7 @@ int32_t tscRebuildCreateDBStatement(void *param,char *result) { SCreateBuilder *builder = (SCreateBuilder *)param; int32_t code = TSDB_CODE_SUCCESS; - char *buf = calloc(1, TSDB_MAX_BINARY_LEN); + char *buf = calloc(1, TSDB_MAX_SQL_LEN); if (buf == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -582,7 +583,7 @@ int32_t tscRebuildCreateDBStatement(void *param,char *result) { } static int32_t tscGetTableTagColumnName(SSqlObj *pSql, char **result) { - char *buf = (char *)malloc(TSDB_MAX_BINARY_LEN); + char *buf = (char *)malloc(TSDB_MAX_SQL_LEN); if (buf == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -599,15 +600,16 @@ static int32_t tscGetTableTagColumnName(SSqlObj *pSql, char **result) { int32_t numOfTags = tscGetNumOfTags(pMeta); for (int32_t i = 0; i < numOfTags; i++) { if (i != numOfTags - 1) { - snprintf(buf + strlen(buf), TSDB_MAX_BINARY_LEN - strlen(buf), "`%s`,", pTagsSchema[i].name); + snprintf(buf + strlen(buf), TSDB_MAX_SQL_LEN - strlen(buf), "`%s`,", pTagsSchema[i].name); } else { - snprintf(buf + strlen(buf), TSDB_MAX_BINARY_LEN - strlen(buf), "`%s`", pTagsSchema[i].name); + snprintf(buf + strlen(buf), TSDB_MAX_SQL_LEN - strlen(buf), "`%s`", pTagsSchema[i].name); } } *result = buf; return TSDB_CODE_SUCCESS; } + static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, char *ddl) { SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd); @@ -640,7 +642,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch param->fp = tscRebuildCreateTableStatement; param->callStage = SCREATE_CALLBACK_QUERY; - char *query = (char *)calloc(1, TSDB_MAX_BINARY_LEN); + char *query = (char *)calloc(1, TSDB_MAX_SQL_LEN); if (query == NULL) { free(param); free(pInterSql); @@ -656,7 +658,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch return code; } - snprintf(query + strlen(query), TSDB_MAX_BINARY_LEN - strlen(query), "SELECT %s FROM %s WHERE TBNAME IN(\'%s\')", columns, fullName, tblName); + snprintf(query + strlen(query), TSDB_MAX_SQL_LEN - strlen(query), "SELECT %s FROM %s WHERE TBNAME IN(\'%s\')", columns, fullName, tblName); doAsyncQuery(pSql->pTscObj, pInterSql, tscSCreateCallBack, param, query, strlen(query)); free(query); free(columns); @@ -681,9 +683,9 @@ static int32_t tscRebuildDDLForNormalTable(SSqlObj *pSql, const char *tableName, if (type == TSDB_DATA_TYPE_NCHAR) { bytes = bytes/TSDB_NCHAR_SIZE; } - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s(%d),", pSchema[i].name, tDataTypes[pSchema[i].type].name, bytes); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "`%s` %s(%d),", pSchema[i].name, tDataTypes[pSchema[i].type].name, bytes); } else { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[pSchema[i].type].name); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[pSchema[i].type].name); } } sprintf(result + strlen(result) - 1, "%s", ")"); @@ -708,12 +710,12 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName, if (type == TSDB_DATA_TYPE_NCHAR) { bytes = bytes/TSDB_NCHAR_SIZE; } - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result),"`%s` %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result),"`%s` %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes); } else { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[type].name); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[type].name); } } - snprintf(result + strlen(result) - 1, TSDB_MAX_BINARY_LEN - strlen(result), "%s %s", ")", "TAGS ("); + snprintf(result + strlen(result) - 1, TSDB_MAX_SQL_LEN - strlen(result), "%s %s", ")", "TAGS ("); for (int32_t i = numOfRows; i < totalRows; i++) { uint8_t type = pSchema[i].type; @@ -722,9 +724,9 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName, if (type == TSDB_DATA_TYPE_NCHAR) { bytes = bytes/TSDB_NCHAR_SIZE; } - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "`%s` %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes); } else { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[type].name); + snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[type].name); } } sprintf(result + strlen(result) - 1, "%s", ")"); @@ -742,7 +744,7 @@ static int32_t tscProcessShowCreateTable(SSqlObj *pSql) { return TSDB_CODE_TSC_INVALID_VALUE; } - char *result = (char *)calloc(1, TSDB_MAX_BINARY_LEN); + char *result = (char *)calloc(1, TSDB_MAX_SQL_LEN); int32_t code = TSDB_CODE_SUCCESS; if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { code = tscRebuildDDLForSuperTable(pSql, tableName, result); diff --git a/tests/pytest/stable/insert.py b/tests/pytest/stable/insert.py index f46a6bcf4a0becf6cbee54281a9b3ecc862d63ce..2ee140debfed29189bbf7a81cb3617e831221768 100644 --- a/tests/pytest/stable/insert.py +++ b/tests/pytest/stable/insert.py @@ -96,6 +96,23 @@ class TDTestCase: tdSql.execute("drop stable if exists db.st") tdSql.execute("create table stb(ts timestamp, c1 int) tags(t1 int)") tdSql.error("create table `` using stb tags(1)") + + # TS-1760 + sql = "create table stb9 (ts timestamp" + for i in range(999): + sql += ", longcolumntest%d double" % i + sql += ") tags(t1 int)" + + tdSql.execute(sql) + tdSql.query("describe stb9") + tdSql.checkRows(1001) + tdSql.query("show create table stb9") + query = tdSql.getData(0, 1) + + tdSql.execute("drop table if exists stb9") + tdSql.execute(query) + tdSql.query("describe stb9") + tdSql.checkRows(1001) def stop(self): tdSql.close()