• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4506

15 Jul 2025 12:33AM UTC coverage: 62.026% (-0.7%) from 62.706%
#4506

push

travis-ci

web-flow
docs: update stream docs (#31874)

155391 of 320094 branches covered (48.55%)

Branch coverage included in aggregate %.

240721 of 318525 relevant lines covered (75.57%)

6529048.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.96
/source/libs/parser/src/parInsertStmt.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "geosWrapper.h"
17
#include "os.h"
18
#include "parInsertUtil.h"
19
#include "parInt.h"
20
#include "parToken.h"
21
#include "query.h"
22
#include "tglobal.h"
23
#include "ttime.h"
24
#include "ttypes.h"
25

26
typedef struct SKvParam {
27
  int16_t  pos;
28
  SArray*  pTagVals;
29
  SSchema* schema;
30
  char     buf[TSDB_MAX_TAGS_LEN];
31
} SKvParam;
32

33
int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData) {
40,073✔
34
  *pData = taosMemoryCalloc(1, sizeof(SSubmitTbData));
40,073!
35
  if (NULL == *pData) {
40,109!
36
    return terrno;
×
37
  }
38

39
  SSubmitTbData* pNew = *pData;
40,109✔
40

41
  *pNew = *pDataBlock->pData;
40,109✔
42

43
  int32_t code = cloneSVreateTbReq(pDataBlock->pData->pCreateTbReq, &pNew->pCreateTbReq);
40,109✔
44
  if (TSDB_CODE_SUCCESS != code) {
40,093!
45
    taosMemoryFreeClear(*pData);
×
46
    return code;
×
47
  }
48
  pNew->aCol = taosArrayDup(pDataBlock->pData->aCol, NULL);
40,093✔
49
  if (!pNew->aCol) {
40,098!
50
    code = terrno;
×
51
    taosMemoryFreeClear(*pData);
×
52
    return code;
×
53
  }
54

55
  int32_t colNum = taosArrayGetSize(pNew->aCol);
40,098✔
56
  for (int32_t i = 0; i < colNum; ++i) {
160,778✔
57
    if (pDataBlock->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
120,700✔
58
      SColData* pCol = (SColData*)taosArrayGet(pNew->aCol, i);
120,698✔
59
      tColDataDeepClear(pCol);
120,697✔
60
    } else {
61
      pNew->aCol = taosArrayInit(20, POINTER_BYTES);
2✔
62
    }
63
  }
64

65
  return TSDB_CODE_SUCCESS;
40,078✔
66
}
67

68
int32_t qAppendStmtTableOutput(SQuery* pQuery, SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx,
11,512✔
69
                               SStbInterlaceInfo* pBuildInfo, SVCreateTbReq* ctbReq) {
70
  // merge according to vgId
71
  return insAppendStmtTableDataCxt(pAllVgHash, pTbData, pTbCtx, pBuildInfo, ctbReq);
11,512✔
72
}
73

74
int32_t qBuildStmtFinOutput(SQuery* pQuery, SHashObj* pAllVgHash, SArray* pVgDataBlocks) {
8,967✔
75
  int32_t             code = TSDB_CODE_SUCCESS;
8,967✔
76
  SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)pQuery->pRoot;
8,967✔
77

78
  if (TSDB_CODE_SUCCESS == code) {
8,967!
79
    code = insBuildVgDataBlocks(pAllVgHash, pVgDataBlocks, &pStmt->pDataBlocks, true);
8,970✔
80
  }
81

82
  if (pStmt->freeArrayFunc) {
8,962!
83
    pStmt->freeArrayFunc(pVgDataBlocks);
8,968✔
84
  }
85
  return code;
8,971✔
86
}
87

88
/*
89
int32_t qBuildStmtOutputFromTbList(SQuery* pQuery, SHashObj* pVgHash, SArray* pBlockList, STableDataCxt* pTbCtx, int32_t
90
tbNum) { int32_t             code = TSDB_CODE_SUCCESS; SArray*             pVgDataBlocks = NULL; SVnodeModifyOpStmt*
91
pStmt = (SVnodeModifyOpStmt*)pQuery->pRoot;
92

93
  // merge according to vgId
94
  if (tbNum > 0) {
95
    code = insMergeStmtTableDataCxt(pTbCtx, pBlockList, &pVgDataBlocks, true, tbNum);
96
  }
97

98
  if (TSDB_CODE_SUCCESS == code) {
99
    code = insBuildVgDataBlocks(pVgHash, pVgDataBlocks, &pStmt->pDataBlocks);
100
  }
101

102
  if (pStmt->freeArrayFunc) {
103
    pStmt->freeArrayFunc(pVgDataBlocks);
104
  }
105
  return code;
106
}
107
*/
108

109
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash) {
40,068✔
110
  int32_t             code = TSDB_CODE_SUCCESS;
40,068✔
111
  SArray*             pVgDataBlocks = NULL;
40,068✔
112
  SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)pQuery->pRoot;
40,068✔
113

114
  // merge according to vgId
115
  if (taosHashGetSize(pBlockHash) > 0) {
40,068!
116
    code = insMergeTableDataCxt(pBlockHash, &pVgDataBlocks, true);
40,092✔
117
  }
118

119
  if (TSDB_CODE_SUCCESS == code) {
40,110✔
120
    code = insBuildVgDataBlocks(pVgHash, pVgDataBlocks, &pStmt->pDataBlocks, false);
40,109✔
121
  }
122

123
  if (pStmt->freeArrayFunc) {
40,077!
124
    pStmt->freeArrayFunc(pVgDataBlocks);
40,093✔
125
  }
126
  return code;
40,111✔
127
}
128

129
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName,
15✔
130
                           TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, void* charsetCxt) {
131
  STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
15✔
132
  SMsgBuf        pBuf = {.buf = msgBuf, .len = msgBufLen};
15✔
133
  int32_t        code = TSDB_CODE_SUCCESS;
15✔
134
  SBoundColInfo* tags = (SBoundColInfo*)boundTags;
15✔
135
  if (NULL == tags) {
15!
136
    return TSDB_CODE_APP_ERROR;
×
137
  }
138

139
  SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
15✔
140
  if (!pTagArray) {
15!
141
    return buildInvalidOperationMsg(&pBuf, "out of memory");
×
142
  }
143

144
  SArray* tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
15✔
145
  if (!tagName) {
15!
146
    code = buildInvalidOperationMsg(&pBuf, "out of memory");
×
147
    goto end;
×
148
  }
149

150
  SSchema* pSchema = getTableTagSchema(pDataBlock->pMeta);
15✔
151

152
  bool  isJson = false;
15✔
153
  STag* pTag = NULL;
15✔
154

155
  for (int c = 0; c < tags->numOfBound; ++c) {
65✔
156
    if (bind[c].is_null && bind[c].is_null[0]) {
50!
157
      continue;
×
158
    }
159

160
    SSchema* pTagSchema = &pSchema[tags->pColIndex[c]];
50✔
161
    int32_t  colLen = pTagSchema->bytes;
50✔
162
    if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
50!
163
      if (!bind[c].length) {
15!
164
        code = buildInvalidOperationMsg(&pBuf, "var tag length is null");
×
165
        goto end;
×
166
      }
167
      colLen = bind[c].length[0];
15✔
168
      if ((colLen + VARSTR_HEADER_SIZE) > pTagSchema->bytes) {
15!
169
        code = buildInvalidOperationMsg(&pBuf, "tag length is too big");
×
170
        goto end;
×
171
      }
172
    }
173
    if (NULL == taosArrayPush(tagName, pTagSchema->name)) {
100!
174
      code = terrno;
×
175
      goto end;
×
176
    }
177
    if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
50!
178
      if (colLen > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
×
179
        code = buildSyntaxErrMsg(&pBuf, "json string too long than 4095", bind[c].buffer);
×
180
        goto end;
×
181
      }
182

183
      isJson = true;
×
184
      char* tmp = taosMemoryCalloc(1, colLen + 1);
×
185
      if (!tmp) {
×
186
        code = terrno;
×
187
        goto end;
×
188
      }
189
      memcpy(tmp, bind[c].buffer, colLen);
×
190
      code = parseJsontoTagData(tmp, pTagArray, &pTag, &pBuf, charsetCxt);
×
191
      taosMemoryFree(tmp);
×
192
      if (code != TSDB_CODE_SUCCESS) {
×
193
        goto end;
×
194
      }
195
    } else {
196
      STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
50✔
197
      //      strcpy(val.colName, pTagSchema->name);
198
      if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
50!
199
          pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
38✔
200
        if (pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
13✔
201
          code = initCtxAsText();
1✔
202
          if (code) {
1!
203
            qError("geometry init failed:%s", tstrerror(code));
×
204
            goto end;
×
205
          }
206
          code = checkWKB(bind[c].buffer, colLen);
1✔
207
          if (code) {
1!
208
            qError("stmt bind invalid geometry tag:%s, must be WKB format", (char*)bind[c].buffer);
×
209
            goto end;
×
210
          }
211
        }
212
        val.pData = (uint8_t*)bind[c].buffer;
13✔
213
        val.nData = colLen;
13✔
214
      } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
37✔
215
        int32_t output = 0;
2✔
216
        void*   p = taosMemoryCalloc(1, colLen * TSDB_NCHAR_SIZE);
2!
217
        if (p == NULL) {
2!
218
          code = terrno;
×
219
          goto end;
×
220
        }
221
        if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output, charsetCxt)) {
2!
222
          if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
×
223
            taosMemoryFree(p);
×
224
            code = generateSyntaxErrMsg(&pBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
×
225
            goto end;
×
226
          }
227
          char buf[512] = {0};
×
228
          snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno));
×
229
          taosMemoryFree(p);
×
230
          code = buildSyntaxErrMsg(&pBuf, buf, bind[c].buffer);
×
231
          goto end;
×
232
        }
233
        val.pData = p;
2✔
234
        val.nData = output;
2✔
235
      } else {
236
        memcpy(&val.i64, bind[c].buffer, colLen);
35✔
237
      }
238
      if (IS_VAR_DATA_TYPE(pTagSchema->type) && val.nData > pTagSchema->bytes) {
50!
239
        code = TSDB_CODE_PAR_VALUE_TOO_LONG;
×
240
        goto end;
×
241
      }
242
      if (NULL == taosArrayPush(pTagArray, &val)) {
50!
243
        code = terrno;
×
244
        goto end;
×
245
      }
246
    }
247
  }
248

249
  if (!isJson && (code = tTagNew(pTagArray, 1, false, &pTag)) != TSDB_CODE_SUCCESS) {
15!
250
    goto end;
×
251
  }
252

253
  if (NULL == pDataBlock->pData->pCreateTbReq) {
15✔
254
    pDataBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
6!
255
    if (NULL == pDataBlock->pData->pCreateTbReq) {
6!
256
      code = terrno;
×
257
      goto end;
×
258
    }
259
  } else {
260
    SVCreateTbReq* tmp = pDataBlock->pData->pCreateTbReq;
9✔
261
    taosMemoryFreeClear(tmp->name);
9!
262
    taosMemoryFreeClear(tmp->ctb.pTag);
9!
263
    taosMemoryFreeClear(tmp->ctb.stbName);
9!
264
    taosArrayDestroy(tmp->ctb.tagName);
9✔
265
    tmp->ctb.tagName = NULL;
9✔
266
  }
267

268
  code = insBuildCreateTbReq(pDataBlock->pData->pCreateTbReq, tName, pTag, suid, sTableName, tagName,
15✔
269
                             pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL);
15✔
270
  pTag = NULL;
15✔
271

272
end:
15✔
273
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
65✔
274
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
50✔
275
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
50✔
276
      taosMemoryFreeClear(p->pData);
2!
277
    }
278
  }
279
  taosArrayDestroy(pTagArray);
15✔
280
  taosArrayDestroy(tagName);
15✔
281
  taosMemoryFree(pTag);
15!
282

283
  return code;
15✔
284
}
285

286
int32_t convertStmtNcharCol(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_MULTI_BIND* src, TAOS_MULTI_BIND* dst,
255✔
287
                            void* charsetCxt) {
288
  int32_t output = 0;
255✔
289
  int32_t newBuflen = (pSchema->bytes - VARSTR_HEADER_SIZE) * src->num;
255✔
290
  if (dst->buffer_length < newBuflen) {
255!
291
    dst->buffer = taosMemoryRealloc(dst->buffer, newBuflen);
255!
292
    if (NULL == dst->buffer) {
256!
293
      return terrno;
×
294
    }
295
  }
296

297
  if (NULL == dst->length) {
256✔
298
    dst->length = taosMemoryRealloc(dst->length, sizeof(int32_t) * src->num);
255!
299
    if (NULL == dst->length) {
255!
300
      taosMemoryFreeClear(dst->buffer);
×
301
      return terrno;
×
302
    }
303
  }
304

305
  dst->buffer_length = pSchema->bytes - VARSTR_HEADER_SIZE;
256✔
306

307
  for (int32_t i = 0; i < src->num; ++i) {
15,864✔
308
    if (src->is_null && src->is_null[i]) {
15,607✔
309
      continue;
2✔
310
    }
311

312
    if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i],
15,606!
313
                       (TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output,
15,605✔
314
                       charsetCxt)) {
315
      if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
×
316
        return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
×
317
      }
318
      char buf[512] = {0};
×
319
      snprintf(buf, tListLen(buf), "%s", strerror(terrno));
×
320
      return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
×
321
    }
322

323
    dst->length[i] = output;
15,606✔
324
  }
325

326
  dst->buffer_type = src->buffer_type;
257✔
327
  dst->is_null = src->is_null;
257✔
328
  dst->num = src->num;
257✔
329

330
  return TSDB_CODE_SUCCESS;
257✔
331
}
332

333
int32_t qBindStmtStbColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen,
5,701✔
334
                              STSchema** pTSchema, SBindInfo* pBindInfos, void* charsetCxt) {
335
  STableDataCxt*   pDataBlock = (STableDataCxt*)pBlock;
5,701✔
336
  SSchema*         pSchema = getTableColumnSchema(pDataBlock->pMeta);
5,701✔
337
  SBoundColInfo*   boundInfo = &pDataBlock->boundColsInfo;
5,704✔
338
  SMsgBuf          pBuf = {.buf = msgBuf, .len = msgBufLen};
5,704✔
339
  int32_t          rowNum = bind->num;
5,704✔
340
  TAOS_MULTI_BIND  ncharBind = {0};
5,704✔
341
  TAOS_MULTI_BIND* pBind = NULL;
5,704✔
342
  int32_t          code = 0;
5,704✔
343
  int16_t          lastColId = -1;
5,704✔
344
  bool             colInOrder = true;
5,704✔
345

346
  if (NULL == pTSchema || NULL == *pTSchema) {
5,704!
347
    *pTSchema = tBuildTSchema(pSchema, pDataBlock->pMeta->tableInfo.numOfColumns, pDataBlock->pMeta->sversion);
64✔
348
  }
349

350
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
32,448✔
351
    SSchema* pColSchema = &pSchema[boundInfo->pColIndex[c]];
26,736✔
352
    if (pColSchema->colId <= lastColId) {
26,736!
353
      colInOrder = false;
×
354
    } else {
355
      lastColId = pColSchema->colId;
26,736✔
356
    }
357
    // SColData* pCol = taosArrayGet(pCols, c);
358

359
    if (bind[c].num != rowNum) {
26,736!
360
      code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
361
      goto _return;
×
362
    }
363

364
    if ((!(rowNum == 1 && bind[c].is_null && *bind[c].is_null)) &&
26,736!
365
        bind[c].buffer_type != pColSchema->type) {  // for rowNum ==1 , connector may not set buffer_type
26,736!
366
      code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
367
      goto _return;
×
368
    }
369

370
    if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
26,736✔
371
      code = convertStmtNcharCol(&pBuf, pColSchema, bind + c, &ncharBind, charsetCxt);
168✔
372
      if (code) {
168!
373
        goto _return;
×
374
      }
375
      pBind = &ncharBind;
168✔
376
    } else {
377
      pBind = bind + c;
26,568✔
378
    }
379

380
    pBindInfos[c].columnId = pColSchema->colId;
26,736✔
381
    pBindInfos[c].bind = pBind;
26,736✔
382
    pBindInfos[c].type = pColSchema->type;
26,736✔
383

384
    // code = tColDataAddValueByBind(pCol, pBind, IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes -
385
    // VARSTR_HEADER_SIZE: -1); if (code) {
386
    //   goto _return;
387
    // }
388
  }
389

390
  code = tRowBuildFromBind(pBindInfos, boundInfo->numOfBound, colInOrder, *pTSchema, pCols, &pDataBlock->ordered,
5,712✔
391
                           &pDataBlock->duplicateTs);
392

393
  parserDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum);
5,710!
394

395
_return:
5,710✔
396

397
  taosMemoryFree(ncharBind.buffer);
5,710!
398
  taosMemoryFree(ncharBind.length);
5,715!
399

400
  return code;
5,710✔
401
}
402

403
int32_t qBindStmtColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen,
40,139✔
404
                           void* charsetCxt) {
405
  STableDataCxt*   pDataBlock = (STableDataCxt*)pBlock;
40,139✔
406
  SSchema*         pSchema = getTableColumnSchema(pDataBlock->pMeta);
40,139✔
407
  SBoundColInfo*   boundInfo = &pDataBlock->boundColsInfo;
40,151✔
408
  SMsgBuf          pBuf = {.buf = msgBuf, .len = msgBufLen};
40,151✔
409
  int32_t          rowNum = bind->num;
40,151✔
410
  TAOS_MULTI_BIND  ncharBind = {0};
40,151✔
411
  TAOS_MULTI_BIND* pBind = NULL;
40,151✔
412
  int32_t          code = 0;
40,151✔
413

414
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
161,307✔
415
    SSchema*  pColSchema = &pSchema[boundInfo->pColIndex[c]];
121,140✔
416
    SColData* pCol = taosArrayGet(pCols, c);
121,140✔
417

418
    if (bind[c].num != rowNum) {
121,146✔
419
      code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
2✔
420
      goto _return;
×
421
    }
422

423
    if ((!(rowNum == 1 && bind[c].is_null && *bind[c].is_null)) &&
121,144✔
424
        bind[c].buffer_type != pColSchema->type) {  // for rowNum ==1 , connector may not set buffer_type
121,141!
425
      code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
426
      goto _return;
×
427
    }
428

429
    if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
121,144✔
430
      code = convertStmtNcharCol(&pBuf, pColSchema, bind + c, &ncharBind, charsetCxt);
63✔
431
      if (code) {
63!
432
        goto _return;
×
433
      }
434
      pBind = &ncharBind;
63✔
435
    } else {
436
      pBind = bind + c;
121,081✔
437
    }
438

439
    code = tColDataAddValueByBind(pCol, pBind,
121,144✔
440
                                  IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1,
121,144✔
441
                                  initCtxAsText, checkWKB);
442
    if (code) {
121,157✔
443
      goto _return;
1✔
444
    }
445
  }
446

447
  parserDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum);
40,167✔
448

449
_return:
40,161✔
450

451
  taosMemoryFree(ncharBind.buffer);
40,168!
452
  taosMemoryFree(ncharBind.length);
40,175!
453

454
  return code;
40,179✔
455
}
456

457
int32_t qBindStmtSingleColValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen,
450✔
458
                                int32_t colIdx, int32_t rowNum, void* charsetCxt) {
459
  STableDataCxt*   pDataBlock = (STableDataCxt*)pBlock;
450✔
460
  SSchema*         pSchema = getTableColumnSchema(pDataBlock->pMeta);
450✔
461
  SBoundColInfo*   boundInfo = &pDataBlock->boundColsInfo;
450✔
462
  SMsgBuf          pBuf = {.buf = msgBuf, .len = msgBufLen};
450✔
463
  SSchema*         pColSchema = &pSchema[boundInfo->pColIndex[colIdx]];
450✔
464
  SColData*        pCol = taosArrayGet(pCols, colIdx);
450✔
465
  TAOS_MULTI_BIND  ncharBind = {0};
450✔
466
  TAOS_MULTI_BIND* pBind = NULL;
450✔
467
  int32_t          code = 0;
450✔
468

469
  if (bind->num != rowNum) {
450!
470
    return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
471
  }
472

473
  // Column index exceeds the number of columns
474
  if (colIdx >= pCols->size && pCol == NULL) {
450!
475
    return buildInvalidOperationMsg(&pBuf, "column index exceeds the number of columns");
×
476
  }
477

478
  if (bind->buffer_type != pColSchema->type) {
450!
479
    return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
480
  }
481

482
  if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
450✔
483
    code = convertStmtNcharCol(&pBuf, pColSchema, bind, &ncharBind, charsetCxt);
25✔
484
    if (code) {
25!
485
      goto _return;
×
486
    }
487
    pBind = &ncharBind;
25✔
488
  } else {
489
    pBind = bind;
425✔
490
  }
491

492
  code = tColDataAddValueByBind(pCol, pBind,
450✔
493
                                IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1,
450!
494
                                initCtxAsText, checkWKB);
495

496
  parserDebug("stmt col %d bind %d rows data", colIdx, rowNum);
450!
497

498
_return:
450✔
499

500
  taosMemoryFree(ncharBind.buffer);
450!
501
  taosMemoryFree(ncharBind.length);
450!
502

503
  return code;
450✔
504
}
505

506
int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName,
189✔
507
                            TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen, void* charsetCxt,
508
                            SVCreateTbReq* pCreateTbReq) {
509
  STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
189✔
510
  SMsgBuf        pBuf = {.buf = msgBuf, .len = msgBufLen};
189✔
511
  int32_t        code = TSDB_CODE_SUCCESS;
189✔
512
  SBoundColInfo* tags = (SBoundColInfo*)boundTags;
189✔
513
  if (NULL == tags) {
189!
514
    return buildInvalidOperationMsg(&pBuf, "tags is null");
×
515
  }
516

517
  SArray* pTagArray;
518
  if (tags->parseredTags) {
189✔
519
    pTagArray = taosArrayDup(tags->parseredTags->pTagVals, NULL);
24✔
520
  } else {
521
    pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
165✔
522
  }
523
  if (!pTagArray) {
189!
524
    return buildInvalidOperationMsg(&pBuf, "out of memory");
×
525
  }
526

527
  SArray* tagName;
528
  if (tags->parseredTags) {
189✔
529
    tagName = taosArrayDup(tags->parseredTags->STagNames, NULL);
24✔
530
  } else {
531
    tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
165✔
532
  }
533

534
  if (!tagName) {
189!
535
    code = buildInvalidOperationMsg(&pBuf, "out of memory");
×
536
    goto end;
×
537
  }
538

539
  SSchema* pSchema = getTableTagSchema(pDataBlock->pMeta);
189✔
540

541
  bool  isJson = false;
189✔
542
  STag* pTag = NULL;
189✔
543

544
  int bindIdx = 0;
189✔
545
  for (int c = 0; c < tags->numOfBound; ++c) {
746✔
546
    if (bind == NULL) {
579✔
547
      break;
21✔
548
    }
549
    if (tags->parseredTags) {
558✔
550
      bool found = false;
264✔
551
      for (int k = 0; k < tags->parseredTags->numOfTags; k++) {
720✔
552
        if (tags->parseredTags->pTagIndex[k] == tags->pColIndex[c]) {
504✔
553
          found = true;
48✔
554
          break;
48✔
555
        }
556
      }
557
      if (found) {
264✔
558
        continue;
48✔
559
      }
560
    }
561

562
    TAOS_STMT2_BIND bindData = bind[bindIdx++];
510✔
563

564
    if (bindData.is_null && bindData.is_null[0]) {
510!
565
      continue;
×
566
    }
567

568
    SSchema* pTagSchema = &pSchema[tags->pColIndex[c]];
510✔
569
    int32_t  colLen = pTagSchema->bytes;
510✔
570
    if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
510!
571
      if (!bindData.length) {
204!
572
        code = buildInvalidOperationMsg(&pBuf, "var tag length is null");
×
573
        goto end;
1✔
574
      }
575
      colLen = bindData.length[0];
204✔
576
      if ((colLen + VARSTR_HEADER_SIZE) > pTagSchema->bytes) {
204!
577
        code = buildInvalidOperationMsg(&pBuf, "tag length is too big");
×
578
        goto end;
×
579
      }
580
    }
581
    if (NULL == taosArrayPush(tagName, pTagSchema->name)) {
1,020!
582
      code = terrno;
×
583
      goto end;
×
584
    }
585
    if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
510!
586
      if (colLen > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
×
587
        code = buildSyntaxErrMsg(&pBuf, "json string too long than 4095", bindData.buffer);
×
588
        goto end;
×
589
      }
590

591
      isJson = true;
×
592
      char* tmp = taosMemoryCalloc(1, colLen + 1);
×
593
      if (!tmp) {
×
594
        code = terrno;
×
595
        goto end;
×
596
      }
597
      memcpy(tmp, bindData.buffer, colLen);
×
598
      code = parseJsontoTagData(tmp, pTagArray, &pTag, &pBuf, charsetCxt);
×
599
      taosMemoryFree(tmp);
×
600
      if (code != TSDB_CODE_SUCCESS) {
×
601
        goto end;
×
602
      }
603
    } else {
604
      STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
510✔
605
      //      strcpy(val.colName, pTagSchema->name);
606
      if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
510!
607
          pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
377✔
608
        if (pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
164✔
609
          code = initCtxAsText();
31✔
610
          if (code) {
31!
611
            qError("geometry init failed:%s", tstrerror(code));
×
612
            goto end;
1✔
613
          }
614
          code = checkWKB(bindData.buffer, colLen);
31✔
615
          if (code) {
31✔
616
            qError("stmt2 bind invalid geometry tag:%s, must be WKB format", (char*)bindData.buffer);
1!
617
            goto end;
1✔
618
          }
619
        }
620
        val.pData = (uint8_t*)bindData.buffer;
163✔
621
        val.nData = colLen;
163✔
622
      } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
346✔
623
        int32_t output = 0;
40✔
624
        void*   p = taosMemoryCalloc(1, colLen * TSDB_NCHAR_SIZE);
40!
625
        if (p == NULL) {
40!
626
          code = terrno;
×
627
          goto end;
×
628
        }
629
        if (!taosMbsToUcs4(bindData.buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output, charsetCxt)) {
40!
630
          if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
×
631
            taosMemoryFree(p);
×
632
            code = generateSyntaxErrMsg(&pBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
×
633
            goto end;
×
634
          }
635
          char buf[512] = {0};
×
636
          snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno));
×
637
          taosMemoryFree(p);
×
638
          code = buildSyntaxErrMsg(&pBuf, buf, bindData.buffer);
×
639
          goto end;
×
640
        }
641
        val.pData = p;
40✔
642
        val.nData = output;
40✔
643
      } else {
644
        memcpy(&val.i64, bindData.buffer, colLen);
306✔
645
      }
646
      if (IS_VAR_DATA_TYPE(pTagSchema->type) && val.nData > pTagSchema->bytes) {
509!
647
        code = TSDB_CODE_PAR_VALUE_TOO_LONG;
×
648
        goto end;
×
649
      }
650
      if (NULL == taosArrayPush(pTagArray, &val)) {
509!
651
        code = terrno;
×
652
        goto end;
×
653
      }
654
    }
655
  }
656

657
  if (!isJson && (code = tTagNew(pTagArray, 1, false, &pTag)) != TSDB_CODE_SUCCESS) {
188!
658
    goto end;
×
659
  }
660

661
  if (pCreateTbReq) {
188✔
662
    code = insBuildCreateTbReq(pCreateTbReq, tName, pTag, suid, sTableName, tagName,
83✔
663
                               pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL);
83✔
664
    pTag = NULL;
83✔
665
    goto end;
83✔
666
  }
667

668
  if (NULL == pDataBlock->pData->pCreateTbReq) {
105✔
669
    pDataBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
8!
670
    if (NULL == pDataBlock->pData->pCreateTbReq) {
8!
671
      code = terrno;
×
672
      goto end;
×
673
    }
674
  } else {
675
    SVCreateTbReq* tmp = pDataBlock->pData->pCreateTbReq;
97✔
676
    taosMemoryFreeClear(tmp->name);
97!
677
    taosMemoryFreeClear(tmp->ctb.pTag);
97!
678
    taosMemoryFreeClear(tmp->ctb.stbName);
97!
679
    taosArrayDestroy(tmp->ctb.tagName);
97✔
680
    tmp->ctb.tagName = NULL;
97✔
681
  }
682

683
  code = insBuildCreateTbReq(pDataBlock->pData->pCreateTbReq, tName, pTag, suid, sTableName, tagName,
105✔
684
                             pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL);
105✔
685
  pTag = NULL;
105✔
686

687
end:
189✔
688
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
746✔
689
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
557✔
690
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
557✔
691
      taosMemoryFreeClear(p->pData);
40!
692
    }
693
  }
694
  taosArrayDestroy(pTagArray);
189✔
695
  taosArrayDestroy(tagName);
189✔
696
  taosMemoryFree(pTag);
189!
697

698
  return code;
189✔
699
}
700

701
static int32_t convertStmtStbNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STMT2_BIND* src, TAOS_STMT2_BIND* dst,
32✔
702
                                       void* charsetCxt) {
703
  int32_t       output = 0;
32✔
704
  const int32_t max_buf_len = pSchema->bytes - VARSTR_HEADER_SIZE;
32✔
705

706
  dst->buffer = taosMemoryCalloc(src->num, max_buf_len);
32!
707
  if (NULL == dst->buffer) {
32!
708
    return terrno;
×
709
  }
710

711
  dst->length = taosMemoryCalloc(src->num, sizeof(int32_t));
32!
712
  if (NULL == dst->length) {
32!
713
    taosMemoryFreeClear(dst->buffer);
×
714
    return terrno;
×
715
  }
716

717
  char* src_buf = src->buffer;
32✔
718
  char* dst_buf = dst->buffer;
32✔
719
  for (int32_t i = 0; i < src->num; ++i) {
3,117✔
720
    if (src->is_null && src->is_null[i]) {
3,085!
721
      continue;
×
722
    }
723

724
    if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output, charsetCxt)) {
3,085!
725
      if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
×
726
        return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
×
727
      }
728
      char buf[512] = {0};
×
729
      snprintf(buf, tListLen(buf), "%s", strerror(terrno));
×
730
      return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
×
731
    }
732

733
    dst->length[i] = output;
3,085✔
734
    src_buf += src->length[i];
3,085✔
735
    dst_buf += output;
3,085✔
736
  }
737

738
  dst->buffer_type = src->buffer_type;
32✔
739
  dst->is_null = src->is_null;
32✔
740
  dst->num = src->num;
32✔
741

742
  return TSDB_CODE_SUCCESS;
32✔
743
}
744

745
int32_t qBindStmtStbColsValue2(void* pBlock, SArray* pCols, SSHashObj* parsedCols, TAOS_STMT2_BIND* bind, char* msgBuf,
5,783✔
746
                               int32_t msgBufLen, STSchema** pTSchema, SBindInfo2* pBindInfos, void* charsetCxt) {
747
  STableDataCxt*  pDataBlock = (STableDataCxt*)pBlock;
5,783✔
748
  SSchema*        pSchema = getTableColumnSchema(pDataBlock->pMeta);
5,783✔
749
  SBoundColInfo*  boundInfo = &pDataBlock->boundColsInfo;
5,786✔
750
  SMsgBuf         pBuf = {.buf = msgBuf, .len = msgBufLen};
5,786✔
751
  int32_t         rowNum = bind->num;
5,786✔
752
  SArray*         ncharBinds = NULL;
5,786✔
753
  TAOS_STMT2_BIND ncharBind = {0};
5,786✔
754
  int32_t         code = 0;
5,786✔
755
  int16_t         lastColId = -1;
5,786✔
756
  bool            colInOrder = true;
5,786✔
757
  int             ncharColNums = 0;
5,786✔
758
  int32_t         bindIdx = 0;
5,786✔
759

760
  if (NULL == pTSchema || NULL == *pTSchema) {
5,786!
761
    *pTSchema = tBuildTSchema(pSchema, pDataBlock->pMeta->tableInfo.numOfColumns, pDataBlock->pMeta->sversion);
86✔
762
  }
763

764
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
28,833✔
765
    if (TSDB_DATA_TYPE_NCHAR == pSchema[boundInfo->pColIndex[c]].type) {
23,041✔
766
      ncharColNums++;
32✔
767
    }
768
  }
769
  if (ncharColNums > 0) {
5,792✔
770
    ncharBinds = taosArrayInit(ncharColNums, sizeof(ncharBind));
28✔
771
    if (!ncharBinds) {
28✔
772
      code = terrno;
5✔
773
      goto _return;
×
774
    }
775
  }
776

777
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
28,821✔
778
    SSchema* pColSchema = &pSchema[boundInfo->pColIndex[c]];
23,034✔
779
    if (pColSchema->colId <= lastColId) {
23,034✔
780
      colInOrder = false;
7✔
781
    } else {
782
      lastColId = pColSchema->colId;
23,027✔
783
    }
784

785
    if (parsedCols) {
23,034✔
786
      SColVal* pParsedVal = tSimpleHashGet(parsedCols, &pColSchema->colId, sizeof(int16_t));
132✔
787
      if (pParsedVal) {
132✔
788
        pBindInfos[c].columnId = pColSchema->colId;
24✔
789
        pBindInfos[c].type = pColSchema->type;
24✔
790
        pBindInfos[c].bytes = pColSchema->bytes;
24✔
791
        continue;
24✔
792
      }
793
    }
794

795
    TAOS_STMT2_BIND bindData = bind[bindIdx];
23,010✔
796

797
    if (bindData.num != rowNum) {
23,010!
798
      code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
799
      goto _return;
×
800
    }
801

802
    if ((!(rowNum == 1 && bindData.is_null && *bindData.is_null)) &&
23,010!
803
        bindData.buffer_type != pColSchema->type) {  // for rowNum ==1 , connector may not set buffer_type
23,010!
804
      code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
805
      goto _return;
×
806
    }
807

808
    if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
23,010✔
809
      code = convertStmtStbNcharCol2(&pBuf, pColSchema, bind + bindIdx, &ncharBind, charsetCxt);
32✔
810
      if (code) {
32!
811
        goto _return;
×
812
      }
813
      if (!taosArrayPush(ncharBinds, &ncharBind)) {
32!
814
        code = terrno;
×
815
        goto _return;
×
816
      }
817
      pBindInfos[c].bind = taosArrayGetLast(ncharBinds);
32✔
818
    } else if (TSDB_DATA_TYPE_GEOMETRY == pColSchema->type) {
22,978✔
819
      code = initCtxAsText();
13✔
820
      if (code) {
13!
821
        qError("geometry init failed:%s", tstrerror(code));
×
822
        goto _return;
×
823
      }
824
      uint8_t* buf = bindData.buffer;
13✔
825
      for (int j = 0; j < bindData.num; j++) {
29✔
826
        if (bindData.is_null && bindData.is_null[j]) {
16✔
827
          continue;
1✔
828
        }
829
        code = checkWKB(buf, bindData.length[j]);
15✔
830
        if (code) {
15!
831
          qError("stmt2 interlace mode geometry data[%d]:{%s},length:%d must be in WKB format", c, buf,
×
832
                 bindData.length[j]);
833
          goto _return;
×
834
        }
835
        buf += bindData.length[j];
15✔
836
      }
837
      pBindInfos[c].bind = bind + bindIdx;
13✔
838
    } else {
839
      pBindInfos[c].bind = bind + bindIdx;
22,965✔
840
    }
841

842
    pBindInfos[c].columnId = pColSchema->colId;
23,010✔
843
    pBindInfos[c].type = pColSchema->type;
23,010✔
844
    pBindInfos[c].bytes = pColSchema->bytes;
23,010✔
845

846
    bindIdx++;
23,010✔
847
  }
848

849
  code = tRowBuildFromBind2(pBindInfos, boundInfo->numOfBound, parsedCols, colInOrder, *pTSchema, pCols,
5,787✔
850
                            &pDataBlock->ordered, &pDataBlock->duplicateTs);
851

852
  parserDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum);
5,784!
853

854
_return:
5,784✔
855
  if (ncharBinds) {
5,784✔
856
    for (int i = 0; i < TARRAY_SIZE(ncharBinds); ++i) {
60✔
857
      TAOS_STMT2_BIND* ncBind = TARRAY_DATA(ncharBinds);
32✔
858
      taosMemoryFree(ncBind[i].buffer);
32!
859
      taosMemoryFree(ncBind[i].length);
32!
860
    }
861
    taosArrayDestroy(ncharBinds);
28✔
862
  }
863

864
  return code;
5,783✔
865
}
866

867
static int32_t convertStmtNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STMT2_BIND* src, TAOS_STMT2_BIND* dst,
15✔
868
                                    void* charsetCxt) {
869
  int32_t       output = 0;
15✔
870
  const int32_t max_buf_len = pSchema->bytes - VARSTR_HEADER_SIZE;
15✔
871

872
  int32_t newBuflen = (pSchema->bytes - VARSTR_HEADER_SIZE) * src->num;
15✔
873
  // if (dst->buffer_length < newBuflen) {
874
  dst->buffer = taosMemoryRealloc(dst->buffer, newBuflen);
15!
875
  if (NULL == dst->buffer) {
15!
876
    return terrno;
×
877
  }
878
  //}
879

880
  if (NULL == dst->length) {
15!
881
    dst->length = taosMemoryRealloc(dst->length, sizeof(int32_t) * src->num);
15!
882
    if (NULL == dst->length) {
15!
883
      taosMemoryFreeClear(dst->buffer);
×
884
      return terrno;
×
885
    }
886
  }
887

888
  // dst->buffer_length = pSchema->bytes - VARSTR_HEADER_SIZE;
889
  char* src_buf = src->buffer;
15✔
890
  char* dst_buf = dst->buffer;
15✔
891
  for (int32_t i = 0; i < src->num; ++i) {
30✔
892
    if (src->is_null && src->is_null[i]) {
15!
893
      continue;
×
894
    }
895

896
    /*if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i],
897
      (TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) {*/
898
    if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output, charsetCxt)) {
15!
899
      if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
×
900
        return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
×
901
      }
902
      char buf[512] = {0};
×
903
      snprintf(buf, tListLen(buf), "%s", strerror(terrno));
×
904
      return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
×
905
    }
906

907
    dst->length[i] = output;
15✔
908
    src_buf += src->length[i];
15✔
909
    dst_buf += output;
15✔
910
  }
911

912
  dst->buffer_type = src->buffer_type;
15✔
913
  dst->is_null = src->is_null;
15✔
914
  dst->num = src->num;
15✔
915

916
  return TSDB_CODE_SUCCESS;
15✔
917
}
918

919
int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, SSHashObj* parsedCols, TAOS_STMT2_BIND* bind, char* msgBuf,
123✔
920
                            int32_t msgBufLen, void* charsetCxt) {
921
  STableDataCxt*   pDataBlock = (STableDataCxt*)pBlock;
123✔
922
  SSchema*         pSchema = getTableColumnSchema(pDataBlock->pMeta);
123✔
923
  SBoundColInfo*   boundInfo = &pDataBlock->boundColsInfo;
123✔
924
  SMsgBuf          pBuf = {.buf = msgBuf, .len = msgBufLen};
123✔
925
  int32_t          rowNum = bind->num;
123✔
926
  TAOS_STMT2_BIND  ncharBind = {0};
123✔
927
  TAOS_STMT2_BIND* pBind = NULL;
123✔
928
  int32_t          code = 0;
123✔
929
  int32_t          bindIdx = 0;
123✔
930

931
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
480✔
932
    SSchema*  pColSchema = &pSchema[boundInfo->pColIndex[c]];
357✔
933
    SColData* pCol = taosArrayGet(pCols, c);
357✔
934
    if (pCol == NULL || pColSchema == NULL) {
357!
935
      code = buildInvalidOperationMsg(&pBuf, "get column schema or column data failed");
×
936
      goto _return;
×
937
    }
938

939
    if (boundInfo->pColIndex[c] == 0) {
357✔
940
      pCol->cflag |= COL_IS_KEY;
123✔
941
    }
942

943
    if (parsedCols) {
357✔
944
      SColVal* pParsedVal = tSimpleHashGet(parsedCols, &pColSchema->colId, sizeof(int16_t));
132✔
945
      if (pParsedVal) {
132✔
946
        for (int row = 0; row < rowNum; row++) {
48✔
947
          code = tColDataAppendValue(pCol, pParsedVal);
24✔
948
          if (code) {
24!
949
            goto _return;
×
950
          }
951
        }
952
        continue;
24✔
953
      }
954
    }
955
    TAOS_STMT2_BIND bindData = bind[bindIdx];
333✔
956
    if (bindData.num != rowNum) {
333!
957
      code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
958
      goto _return;
×
959
    }
960

961
    if ((!(rowNum == 1 && bindData.is_null && *bindData.is_null)) &&
333!
962
        bindData.buffer_type != pColSchema->type) {  // for rowNum ==1 , connector may not set buffer_type
333!
963
      code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
964
      goto _return;
×
965
    }
966

967
    if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
333✔
968
      code = convertStmtNcharCol2(&pBuf, pColSchema, bind + bindIdx, &ncharBind, charsetCxt);
13✔
969
      if (code) {
13!
970
        goto _return;
×
971
      }
972
      pBind = &ncharBind;
13✔
973
    } else {
974
      pBind = bind + bindIdx;
320✔
975
    }
976

977
    code = tColDataAddValueByBind2(pCol, pBind,
333✔
978
                                   IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1,
333!
979
                                   initCtxAsText, checkWKB);
980
    if (code) {
333!
981
      goto _return;
×
982
    }
983
    bindIdx++;
333✔
984
  }
985

986
  parserDebug("stmt2 all %d columns bind %d rows data as col format", boundInfo->numOfBound, rowNum);
123!
987

988
_return:
123✔
989

990
  taosMemoryFree(ncharBind.buffer);
123!
991
  taosMemoryFree(ncharBind.length);
123!
992

993
  return code;
123✔
994
}
995

996
int32_t qBindStmtSingleColValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen,
6✔
997
                                 int32_t colIdx, int32_t rowNum, void* charsetCxt) {
998
  STableDataCxt*   pDataBlock = (STableDataCxt*)pBlock;
6✔
999
  SSchema*         pSchema = getTableColumnSchema(pDataBlock->pMeta);
6✔
1000
  SBoundColInfo*   boundInfo = &pDataBlock->boundColsInfo;
6✔
1001
  SMsgBuf          pBuf = {.buf = msgBuf, .len = msgBufLen};
6✔
1002
  SSchema*         pColSchema = &pSchema[boundInfo->pColIndex[colIdx]];
6✔
1003
  SColData*        pCol = taosArrayGet(pCols, colIdx);
6✔
1004
  TAOS_STMT2_BIND  ncharBind = {0};
6✔
1005
  TAOS_STMT2_BIND* pBind = NULL;
6✔
1006
  int32_t          code = 0;
6✔
1007

1008
  if (bind->num != rowNum) {
6!
1009
    return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
1010
  }
1011

1012
  // Column index exceeds the number of columns
1013
  if (colIdx >= pCols->size && pCol == NULL) {
6!
1014
    return buildInvalidOperationMsg(&pBuf, "column index exceeds the number of columns");
×
1015
  }
1016

1017
  if (bind->buffer_type != pColSchema->type) {
6!
1018
    return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
1019
  }
1020

1021
  if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
6!
1022
    code = convertStmtNcharCol2(&pBuf, pColSchema, bind, &ncharBind, charsetCxt);
×
1023
    if (code) {
×
1024
      goto _return;
×
1025
    }
1026
    pBind = &ncharBind;
×
1027
  } else {
1028
    pBind = bind;
6✔
1029
  }
1030

1031
  code = tColDataAddValueByBind2(pCol, pBind,
6✔
1032
                                 IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1,
6!
1033
                                 initCtxAsText, checkWKB);
1034

1035
  parserDebug("stmt col %d bind %d rows data", colIdx, rowNum);
6!
1036

1037
_return:
6✔
1038

1039
  taosMemoryFree(ncharBind.buffer);
6!
1040
  taosMemoryFree(ncharBind.length);
6!
1041

1042
  return code;
6✔
1043
}
1044

1045
int32_t qBindStmt2RowValue(void* pBlock, SArray* pCols, SSHashObj* parsedCols, TAOS_STMT2_BIND* bind, char* msgBuf,
2✔
1046
                           int32_t msgBufLen, STSchema** pTSchema, SBindInfo2* pBindInfos, void* charsetCxt) {
1047
  STableDataCxt*   pDataBlock = (STableDataCxt*)pBlock;
2✔
1048
  SSchema*         pSchema = getTableColumnSchema(pDataBlock->pMeta);
2✔
1049
  SBoundColInfo*   boundInfo = &pDataBlock->boundColsInfo;
2✔
1050
  SMsgBuf          pBuf = {.buf = msgBuf, .len = msgBufLen};
2✔
1051
  int32_t          rowNum = bind->num;
2✔
1052
  TAOS_STMT2_BIND  ncharBind = {0};
2✔
1053
  TAOS_STMT2_BIND* pBind = NULL;
2✔
1054
  int32_t          code = 0;
2✔
1055
  int16_t          lastColId = -1;
2✔
1056
  bool             colInOrder = true;
2✔
1057

1058
  if (NULL == pTSchema || NULL == *pTSchema) {
2!
1059
    *pTSchema = tBuildTSchema(pSchema, pDataBlock->pMeta->tableInfo.numOfColumns, pDataBlock->pMeta->sversion);
1✔
1060
  }
1061

1062
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
24✔
1063
    SSchema* pColSchema = &pSchema[boundInfo->pColIndex[c]];
22✔
1064
    if (pColSchema->colId <= lastColId) {
22!
1065
      colInOrder = false;
×
1066
    } else {
1067
      lastColId = pColSchema->colId;
22✔
1068
    }
1069

1070
    if (bind[c].num != rowNum) {
22!
1071
      code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
1072
      goto _return;
×
1073
    }
1074

1075
    if ((!(rowNum == 1 && bind[c].is_null && *bind[c].is_null)) &&
22!
1076
        bind[c].buffer_type != pColSchema->type) {  // for rowNum ==1 , connector may not set buffer_type
22!
1077
      code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
1078
      goto _return;
×
1079
    }
1080

1081
    if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
22✔
1082
      code = convertStmtNcharCol2(&pBuf, pColSchema, bind + c, &ncharBind, charsetCxt);
2✔
1083
      if (code) {
2!
1084
        goto _return;
×
1085
      }
1086
      pBindInfos[c].bind = &ncharBind;
2✔
1087
    } else if (TSDB_DATA_TYPE_GEOMETRY == pColSchema->type) {
20✔
1088
      code = initCtxAsText();
2✔
1089
      if (code) {
2!
1090
        qError("geometry init failed:%s", tstrerror(code));
×
1091
        goto _return;
×
1092
      }
1093
      uint8_t* buf = bind[c].buffer;
2✔
1094
      for (int j = 0; j < bind[c].num; j++) {
4✔
1095
        if (bind[c].is_null && bind[c].is_null[j]) {
2!
1096
          continue;
×
1097
        }
1098
        code = checkWKB(buf, bind[c].length[j]);
2✔
1099
        if (code) {
2!
1100
          qError("stmt2 row bind geometry data[%d]:{%s},length:%d must be in WKB format", c, buf, bind[c].length[j]);
×
1101
          goto _return;
×
1102
        }
1103
        buf += bind[c].length[j];
2✔
1104
      }
1105
      pBindInfos[c].bind = bind + c;
2✔
1106
    } else {
1107
      pBindInfos[c].bind = bind + c;
18✔
1108
    }
1109

1110
    pBindInfos[c].columnId = pColSchema->colId;
22✔
1111
    pBindInfos[c].type = pColSchema->type;
22✔
1112
    pBindInfos[c].bytes = pColSchema->bytes;
22✔
1113

1114
    if (code) {
22!
1115
      goto _return;
×
1116
    }
1117
  }
1118

1119
  pDataBlock->pData->flags &= ~SUBMIT_REQ_COLUMN_DATA_FORMAT;
2✔
1120
  if (pDataBlock->pData->pCreateTbReq != NULL) {
2!
1121
    pDataBlock->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE;
2✔
1122
  }
1123

1124
  code = tRowBuildFromBind2(pBindInfos, boundInfo->numOfBound, parsedCols, colInOrder, *pTSchema, pCols,
2✔
1125
                            &pDataBlock->ordered, &pDataBlock->duplicateTs);
1126
  qDebug("stmt2 all %d columns bind %d rows data as row format", boundInfo->numOfBound, rowNum);
2!
1127

1128
_return:
2✔
1129

1130
  taosMemoryFree(ncharBind.buffer);
2!
1131
  taosMemoryFree(ncharBind.length);
2!
1132

1133
  return code;
2✔
1134
}
1135

1136
int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSchema, int32_t* fieldNum,
1,060✔
1137
                         TAOS_FIELD_E** fields, uint8_t timePrec) {
1138
  if (fields != NULL) {
1,060✔
1139
    *fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_E));
1,059!
1140
    if (NULL == *fields) {
1,059!
1141
      return terrno;
×
1142
    }
1143

1144
    SSchema* schema = &pSchema[boundColumns[0]];
1,059✔
1145
    if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
1,059✔
1146
      (*fields)[0].precision = timePrec;
1,058✔
1147
    }
1148

1149
    for (int32_t i = 0; i < numOfBound; ++i) {
12,187✔
1150
      schema = &pSchema[boundColumns[i]];
11,128✔
1151
      tstrncpy((*fields)[i].name, schema->name, 65);
11,128✔
1152
      (*fields)[i].type = schema->type;
11,128✔
1153
      (*fields)[i].bytes = calcTypeBytesFromSchemaBytes(schema->type, schema->bytes, true);
11,128✔
1154
    }
1155
  }
1156

1157
  *fieldNum = numOfBound;
1,060✔
1158

1159
  return TSDB_CODE_SUCCESS;
1,060✔
1160
}
1161

1162
int32_t buildStbBoundFields(SBoundColInfo boundColsInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD_ALL** fields,
47✔
1163
                            STableMeta* pMeta, void* boundTags, SSHashObj* parsedCols, uint8_t tbNameFlag) {
1164
  SBoundColInfo* tags = (SBoundColInfo*)boundTags;
47✔
1165
  bool           hastag = (tags != NULL) && !(tbNameFlag & IS_FIXED_TAG);
47!
1166
  bool           hasPreBindTbname =
47✔
1167
      (tbNameFlag & IS_FIXED_VALUE) == 0 && ((tbNameFlag & USING_CLAUSE) != 0 || pMeta->tableType == TSDB_NORMAL_TABLE);
47!
1168
  int32_t numOfBound = boundColsInfo.numOfBound + (hasPreBindTbname ? 1 : 0);
47✔
1169
  if (hastag) {
47✔
1170
    numOfBound += tags->mixTagsCols ? 0 : tags->numOfBound;
28✔
1171
  }
1172

1173
  // Adjust the number of bound fields if there are parsed tags or parsed columns
1174
  if (tags->parseredTags) {
47✔
1175
    numOfBound -= tags->parseredTags->numOfTags;
2✔
1176
  }
1177
  if (parsedCols) {
47✔
1178
    numOfBound -= tSimpleHashGetSize(parsedCols);
4✔
1179
  }
1180

1181
  int32_t idx = 0;
47✔
1182
  if (fields != NULL) {
47!
1183
    *fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_ALL));
47!
1184
    if (NULL == *fields) {
47!
1185
      return terrno;
×
1186
    }
1187

1188
    if (hasPreBindTbname) {
47✔
1189
      (*fields)[idx].field_type = TAOS_FIELD_TBNAME;
31✔
1190
      tstrncpy((*fields)[idx].name, "tbname", sizeof((*fields)[idx].name));
31✔
1191
      (*fields)[idx].type = TSDB_DATA_TYPE_BINARY;
31✔
1192
      (*fields)[idx].bytes = TSDB_TABLE_FNAME_LEN;
31✔
1193
      idx++;
31✔
1194
    }
1195

1196
    if (hastag && tags->numOfBound > 0 && !tags->mixTagsCols) {
47✔
1197
      SSchema* tagSchema = getTableTagSchema(pMeta);
13✔
1198

1199
      for (int32_t i = 0; i < tags->numOfBound; ++i) {
52✔
1200
        SSchema* schema = &tagSchema[tags->pColIndex[i]];
39✔
1201

1202
        if (tags->parseredTags && tags->parseredTags->numOfTags > 0) {
39!
1203
          int32_t tag_idx = schema->colId - 1 - pMeta->tableInfo.numOfColumns;
2✔
1204
          bool    found = false;
2✔
1205
          for (int k = 0; k < tags->parseredTags->numOfTags; k++) {
3✔
1206
            if (tags->parseredTags->pTagIndex[k] == tag_idx) {
2✔
1207
              found = true;
1✔
1208
              break;
1✔
1209
            }
1210
          }
1211
          if (found) {
2✔
1212
            continue;
1✔
1213
          }
1214
        }
1215

1216
        (*fields)[idx].field_type = TAOS_FIELD_TAG;
38✔
1217

1218
        tstrncpy((*fields)[idx].name, schema->name, sizeof((*fields)[i].name));
38✔
1219
        (*fields)[idx].type = schema->type;
38✔
1220
        (*fields)[idx].bytes = schema->bytes;
38✔
1221
        if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
38✔
1222
          (*fields)[idx].precision = pMeta->tableInfo.precision;
1✔
1223
        }
1224
        idx++;
38✔
1225
      }
1226
    }
1227

1228
    if (boundColsInfo.numOfBound > 0) {
47!
1229
      SSchema* schema = &pSchema[boundColsInfo.pColIndex[0]];
47✔
1230

1231
      for (int32_t i = 0; i < boundColsInfo.numOfBound; ++i) {
214✔
1232
        int16_t idxCol = boundColsInfo.pColIndex[i];
167✔
1233

1234
        if (idxCol == pMeta->tableInfo.numOfColumns + pMeta->tableInfo.numOfTags) {
167✔
1235
          (*fields)[idx].field_type = TAOS_FIELD_TBNAME;
9✔
1236
          tstrncpy((*fields)[idx].name, "tbname", sizeof((*fields)[idx].name));
9✔
1237
          (*fields)[idx].type = TSDB_DATA_TYPE_BINARY;
9✔
1238
          (*fields)[idx].bytes = TSDB_TABLE_FNAME_LEN;
9✔
1239

1240
          idx++;
9✔
1241
          continue;
9✔
1242
        } else if (idxCol < pMeta->tableInfo.numOfColumns) {
158✔
1243
          if (parsedCols && tSimpleHashGet(parsedCols, &pSchema[idxCol].colId, sizeof(int16_t))) {
130✔
1244
            continue;
5✔
1245
          }
1246
          (*fields)[idx].field_type = TAOS_FIELD_COL;
125✔
1247
        } else {
1248
          if (tags->parseredTags && tags->parseredTags->numOfTags > 0) {
28!
1249
            int32_t tag_idx = idxCol - pMeta->tableInfo.numOfColumns;
2✔
1250
            bool    found = false;
2✔
1251
            for (int k = 0; k < tags->parseredTags->numOfTags; k++) {
3✔
1252
              if (tags->parseredTags->pTagIndex[k] == tag_idx) {
2✔
1253
                found = true;
1✔
1254
                break;
1✔
1255
              }
1256
            }
1257
            if (found) {
2✔
1258
              continue;
1✔
1259
            }
1260
          }
1261
          (*fields)[idx].field_type = TAOS_FIELD_TAG;
27✔
1262
        }
1263

1264
        schema = &pSchema[idxCol];
152✔
1265
        tstrncpy((*fields)[idx].name, schema->name, sizeof((*fields)[idx].name));
152✔
1266
        (*fields)[idx].type = schema->type;
152✔
1267
        (*fields)[idx].bytes = schema->bytes;
152✔
1268
        if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
152✔
1269
          (*fields)[idx].precision = pMeta->tableInfo.precision;
46✔
1270
        }
1271
        idx++;
152✔
1272
      }
1273
    }
1274
  }
1275

1276
  *fieldNum = numOfBound;
47✔
1277

1278
  return TSDB_CODE_SUCCESS;
47✔
1279
}
1280

1281
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields) {
1✔
1282
  STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
1✔
1283
  SBoundColInfo* tags = (SBoundColInfo*)boundTags;
1✔
1284
  if (NULL == tags) {
1!
1285
    return TSDB_CODE_APP_ERROR;
×
1286
  }
1287

1288
  if (pDataBlock->pMeta->tableType != TSDB_SUPER_TABLE && pDataBlock->pMeta->tableType != TSDB_CHILD_TABLE) {
1!
1289
    return TSDB_CODE_TSC_STMT_API_ERROR;
×
1290
  }
1291

1292
  SSchema* pSchema = getTableTagSchema(pDataBlock->pMeta);
1✔
1293
  if (tags->numOfBound <= 0) {
1!
1294
    *fieldNum = 0;
×
1295
    *fields = NULL;
×
1296

1297
    return TSDB_CODE_SUCCESS;
×
1298
  }
1299

1300
  CHECK_CODE(buildBoundFields(tags->numOfBound, tags->pColIndex, pSchema, fieldNum, fields, 0));
1!
1301

1302
  return TSDB_CODE_SUCCESS;
1✔
1303
}
1304

1305
int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_E** fields) {
1,059✔
1306
  STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
1,059✔
1307
  SSchema*       pSchema = getTableColumnSchema(pDataBlock->pMeta);
1,059✔
1308
  if (pDataBlock->boundColsInfo.numOfBound <= 0) {
1,059!
1309
    *fieldNum = 0;
×
1310
    if (fields != NULL) {
×
1311
      *fields = NULL;
×
1312
    }
1313

1314
    return TSDB_CODE_SUCCESS;
×
1315
  }
1316

1317
  CHECK_CODE(buildBoundFields(pDataBlock->boundColsInfo.numOfBound, pDataBlock->boundColsInfo.pColIndex, pSchema,
1,059!
1318
                              fieldNum, fields, pDataBlock->pMeta->tableInfo.precision));
1319

1320
  return TSDB_CODE_SUCCESS;
1,059✔
1321
}
1322

1323
int32_t qBuildStmtStbColFields(void* pBlock, void* boundTags, SSHashObj* parsedCols, uint8_t tbNameFlag,
47✔
1324
                               int32_t* fieldNum, TAOS_FIELD_ALL** fields) {
1325
  STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
47✔
1326
  SSchema*       pSchema = getTableColumnSchema(pDataBlock->pMeta);
47✔
1327
  if (pDataBlock->boundColsInfo.numOfBound <= 0) {
47!
1328
    *fieldNum = 0;
×
1329
    if (fields != NULL) {
×
1330
      *fields = NULL;
×
1331
    }
1332

1333
    return TSDB_CODE_SUCCESS;
×
1334
  }
1335

1336
  CHECK_CODE(buildStbBoundFields(pDataBlock->boundColsInfo, pSchema, fieldNum, fields, pDataBlock->pMeta, boundTags,
47!
1337
                                 parsedCols, tbNameFlag));
1338

1339
  return TSDB_CODE_SUCCESS;
47✔
1340
}
1341

1342
int32_t qResetStmtColumns(SArray* pCols, bool deepClear) {
×
1343
  int32_t colNum = taosArrayGetSize(pCols);
×
1344

1345
  for (int32_t i = 0; i < colNum; ++i) {
×
1346
    SColData* pCol = (SColData*)taosArrayGet(pCols, i);
×
1347
    if (pCol == NULL) {
×
1348
      parserError("qResetStmtColumns column:%d is NULL", i);
×
1349
      return terrno;
×
1350
    }
1351
    if (deepClear) {
×
1352
      tColDataDeepClear(pCol);
×
1353
    } else {
1354
      tColDataClear(pCol);
×
1355
    }
1356
  }
1357

1358
  return TSDB_CODE_SUCCESS;
×
1359
}
1360

1361
int32_t qResetStmtDataBlock(STableDataCxt* block, bool deepClear) {
60,301✔
1362
  STableDataCxt* pBlock = (STableDataCxt*)block;
60,301✔
1363
  int32_t        colNum = taosArrayGetSize(pBlock->pData->aCol);
60,301✔
1364

1365
  for (int32_t i = 0; i < colNum; ++i) {
242,189✔
1366
    if (pBlock->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
181,903✔
1367
      SColData* pCol = (SColData*)taosArrayGet(pBlock->pData->aCol, i);
181,902✔
1368
      if (pCol == NULL) {
181,904!
1369
        parserError("qResetStmtDataBlock column:%d is NULL", i);
×
1370
        return terrno;
×
1371
      }
1372
      if (deepClear) {
181,930✔
1373
        tColDataDeepClear(pCol);
61,228✔
1374
      } else {
1375
        tColDataClear(pCol);
120,702✔
1376
      }
1377
    } else {
1378
      pBlock->pData->aRowP = taosArrayInit(20, POINTER_BYTES);
1✔
1379
    }
1380
  }
1381

1382
  return TSDB_CODE_SUCCESS;
60,286✔
1383
}
1384

1385
int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset) {
20,286✔
1386
  int32_t code = 0;
20,286✔
1387

1388
  *pDst = taosMemoryCalloc(1, sizeof(STableDataCxt));
20,286!
1389
  if (NULL == *pDst) {
20,305!
1390
    return terrno;
×
1391
  }
1392

1393
  STableDataCxt* pNewCxt = (STableDataCxt*)*pDst;
20,305✔
1394
  STableDataCxt* pCxt = (STableDataCxt*)pSrc;
20,305✔
1395
  pNewCxt->pSchema = NULL;
20,305✔
1396
  pNewCxt->pValues = NULL;
20,305✔
1397

1398
  if (pCxt->pMeta) {
20,305!
1399
    void* pNewMeta = taosMemoryMalloc(TABLE_META_SIZE(pCxt->pMeta));
20,310!
1400
    if (NULL == pNewMeta) {
20,297!
1401
      insDestroyTableDataCxt(*pDst);
×
1402
      return terrno;
×
1403
    }
1404
    memcpy(pNewMeta, pCxt->pMeta, TABLE_META_SIZE(pCxt->pMeta));
20,297✔
1405
    pNewCxt->pMeta = pNewMeta;
20,297✔
1406
  }
1407

1408
  memcpy(&pNewCxt->boundColsInfo, &pCxt->boundColsInfo, sizeof(pCxt->boundColsInfo));
20,292✔
1409
  pNewCxt->boundColsInfo.pColIndex = NULL;
20,292✔
1410

1411
  if (pCxt->boundColsInfo.pColIndex) {
20,292✔
1412
    void* pNewColIdx = taosMemoryMalloc(pCxt->boundColsInfo.numOfBound * sizeof(*pCxt->boundColsInfo.pColIndex));
20,291!
1413
    if (NULL == pNewColIdx) {
20,310!
1414
      insDestroyTableDataCxt(*pDst);
×
1415
      return terrno;
×
1416
    }
1417
    memcpy(pNewColIdx, pCxt->boundColsInfo.pColIndex,
20,310✔
1418
           pCxt->boundColsInfo.numOfBound * sizeof(*pCxt->boundColsInfo.pColIndex));
20,310✔
1419
    pNewCxt->boundColsInfo.pColIndex = pNewColIdx;
20,310✔
1420
  }
1421

1422
  if (pCxt->pData) {
20,311✔
1423
    SSubmitTbData* pNewTb = (SSubmitTbData*)taosMemoryMalloc(sizeof(SSubmitTbData));
20,299!
1424
    if (NULL == pNewTb) {
20,309!
1425
      insDestroyTableDataCxt(*pDst);
×
1426
      return terrno;
×
1427
    }
1428

1429
    memcpy(pNewTb, pCxt->pData, sizeof(*pCxt->pData));
20,309✔
1430
    pNewTb->pCreateTbReq = NULL;
20,309✔
1431

1432
    pNewTb->aCol = taosArrayDup(pCxt->pData->aCol, NULL);
20,309✔
1433
    if (NULL == pNewTb->aCol) {
20,302!
1434
      insDestroyTableDataCxt(*pDst);
×
1435
      return terrno;
×
1436
    }
1437

1438
    pNewCxt->pData = pNewTb;
20,302✔
1439

1440
    if (reset) {
20,302✔
1441
      code = qResetStmtDataBlock(*pDst, true);
20,219✔
1442
    }
1443
  }
1444

1445
  return code;
20,295✔
1446
}
1447

1448
int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId,
85✔
1449
                              bool rebuildCreateTb) {
1450
  int32_t code = qCloneStmtDataBlock(pDst, pSrc, false);
85✔
1451
  if (code) {
85!
1452
    return code;
×
1453
  }
1454

1455
  STableDataCxt* pBlock = (STableDataCxt*)*pDst;
85✔
1456
  if (pBlock->pMeta) {
85!
1457
    pBlock->pMeta->uid = uid;
85✔
1458
    pBlock->pMeta->vgId = vgId;
85✔
1459
    pBlock->pMeta->suid = suid;
85✔
1460
  }
1461

1462
  pBlock->pData->suid = suid;
85✔
1463
  pBlock->pData->uid = uid;
85✔
1464

1465
  if (rebuildCreateTb && NULL == pBlock->pData->pCreateTbReq) {
85!
1466
    pBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
65!
1467
    if (NULL == pBlock->pData->pCreateTbReq) {
65!
1468
      return terrno;
×
1469
    }
1470
  }
1471

1472
  return TSDB_CODE_SUCCESS;
85✔
1473
}
1474

1475
STableMeta* qGetTableMetaInDataBlock(STableDataCxt* pDataBlock) { return ((STableDataCxt*)pDataBlock)->pMeta; }
60,269✔
1476

1477
void qDestroyStmtDataBlock(STableDataCxt* pBlock) {
60,703✔
1478
  if (pBlock == NULL) {
60,703✔
1479
    return;
20,125✔
1480
  }
1481

1482
  STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
40,578✔
1483
  insDestroyTableDataCxt(pDataBlock);
40,578✔
1484
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc