diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 89647324b9e88e04034c136531abc117eb497f33..3b4a06fe4c3c7a9d2405c2253df84087ffe7045e 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1084,6 +1084,11 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC if(spd.numOfBound == 1 && pTagSchema[spd.boundedColumns[0]].type == TSDB_DATA_TYPE_JSON){ char tmp = sToken.z[sToken.n]; sToken.z[sToken.n] = 0; + if(sToken.type != TK_STRING) { + tdDestroyKVRowBuilder(&kvRowBuilder); + tscDestroyBoundColumnInfo(&spd); + return tscSQLSyntaxErrMsg(pInsertParam->msg, "json type error, should be string", NULL); + } code = parseJsontoTagData(sToken.z, &kvRowBuilder, pInsertParam->msg, pTagSchema[spd.boundedColumns[0]].colId); if (code != TSDB_CODE_SUCCESS) { tdDestroyKVRowBuilder(&kvRowBuilder); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 180e3d7443fdda08f333363c36c4f5d1eb4864f9..60fc6c2ef4c784735118cc43b81e17f2d43ccddc 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5867,6 +5867,8 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { const char* msg23 = "only column length coulbe be modified"; const char* msg24 = "invalid binary/nchar column length"; + const char* msg25 = "json type error, should be string"; + int32_t code = TSDB_CODE_SUCCESS; SSqlCmd* pCmd = &pSql->cmd; @@ -6070,6 +6072,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (tdInitKVRowBuilder(&kvRowBuilder) < 0) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } + if(pItem->pVar.nType != TSDB_DATA_TYPE_BINARY){ + tscError("json type error, should be string"); + return invalidOperationMsg(pMsg, "json type error, should be string"); + } code = parseJsontoTagData(pItem->pVar.pz, &kvRowBuilder, pMsg, pTagsSchema->colId); if (code != TSDB_CODE_SUCCESS) { tdDestroyKVRowBuilder(&kvRowBuilder); @@ -7492,6 +7498,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { const char* msg3 = "tag value too long"; const char* msg4 = "illegal value or data overflow"; const char* msg5 = "tags number not matched"; + const char* msg6 = "json type error, should be string"; SSqlCmd* pCmd = &pSql->cmd; @@ -7689,6 +7696,10 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); } tVariantListItem* pItem = taosArrayGet(pValList, 0); + if(pItem->pVar.nType != TSDB_DATA_TYPE_BINARY){ + tscError("json type error, should be string"); + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "json type error, should be string"); + } ret = parseJsontoTagData(pItem->pVar.pz, &kvRowBuilder, tscGetErrorMsgPayload(pCmd), pTagSchema[0].colId); if (ret != TSDB_CODE_SUCCESS) { tdDestroyKVRowBuilder(&kvRowBuilder); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index c21b32647628a9aeeddc3887b4050aa767171013..0f9e33991d6c47f3b91c62f431abb12e081091d4 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -5234,11 +5234,10 @@ end: } int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, int16_t startColId){ - cJSON *root = cJSON_Parse(json); + cJSON *root = cJSON_Parse(json->pz); if (root == NULL){ tscError("json parse error"); return tscSQLSyntaxErrMsg(errMsg, "json parse error", NULL); - } int retCode = 0; diff --git a/tests/pytest/stable/json_tag.py b/tests/pytest/stable/json_tag.py index 2d67b486a53dd469fa8b22fb2c16dad741d6914b..edd6649f29817e7c7461412880198839fd9562c8 100644 --- a/tests/pytest/stable/json_tag.py +++ b/tests/pytest/stable/json_tag.py @@ -49,10 +49,16 @@ class TDTestCase: print("==============step3") tdLog.info("alter stable add tag") tdSql.execute( - "ALTER STABLE db_json_tag_test.jsons1 add COLUMN tag2 nchar(20)") + "ALTER STABLE db_json_tag_test.jsons1 add tag tag2 nchar(20)") tdSql.execute( - "ALTER STABLE db_json_tag_test.jsons1 drop COLUMN jtag") + "ALTER STABLE db_json_tag_test.jsons1 drop tag jtag") + + tdSql.execute( + "ALTER TABLE db_json_tag_test.jsons1_1 SET TAG jtag=4") + + tdSql.execute( + "ALTER TABLE db_json_tag_test.jsons1_1 SET TAG jtag='{\"sex\":\"femail\",\"age\":35}'") def stop(self): tdSql.close()