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

taosdata / TDengine / #4113

17 May 2025 06:43AM UTC coverage: 62.054% (-0.8%) from 62.857%
#4113

push

travis-ci

web-flow
Merge pull request #31115 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

154737 of 318088 branches covered (48.65%)

Branch coverage included in aggregate %.

175 of 225 new or added lines in 20 files covered. (77.78%)

5853 existing lines in 216 files now uncovered.

239453 of 317147 relevant lines covered (75.5%)

15121865.73 hits per line

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

27.27
/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,605✔
34
  *pData = taosMemoryCalloc(1, sizeof(SSubmitTbData));
40,605!
35
  if (NULL == *pData) {
40,649!
36
    return terrno;
×
37
  }
38

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

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

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

55
  int32_t colNum = taosArrayGetSize(pNew->aCol);
40,657✔
56
  for (int32_t i = 0; i < colNum; ++i) {
165,563✔
57
    if (pDataBlock->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
124,943!
58
      SColData* pCol = (SColData*)taosArrayGet(pNew->aCol, i);
124,943✔
59
      tColDataDeepClear(pCol);
124,938✔
60
    } else {
UNCOV
61
      pNew->aCol = taosArrayInit(20, POINTER_BYTES);
×
62
    }
63
  }
64

65
  return TSDB_CODE_SUCCESS;
40,620✔
66
}
67

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

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

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

82
  if (pStmt->freeArrayFunc) {
22,056!
83
    pStmt->freeArrayFunc(pVgDataBlocks);
22,073✔
84
  }
85
  return code;
22,076✔
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,621✔
110
  int32_t             code = TSDB_CODE_SUCCESS;
40,621✔
111
  SArray*             pVgDataBlocks = NULL;
40,621✔
112
  SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)pQuery->pRoot;
40,621✔
113

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

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

123
  if (pStmt->freeArrayFunc) {
40,621!
124
    pStmt->freeArrayFunc(pVgDataBlocks);
40,644✔
125
  }
126
  return code;
40,657✔
127
}
128

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

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

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

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

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

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

160
    SSchema* pTagSchema = &pSchema[tags->pColIndex[c]];
1✔
161
    int32_t  colLen = pTagSchema->bytes;
1✔
162
    if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
1!
UNCOV
163
      if (!bind[c].length) {
×
164
        code = buildInvalidOperationMsg(&pBuf, "var tag length is null");
×
165
        goto end;
×
166
      }
UNCOV
167
      colLen = bind[c].length[0];
×
UNCOV
168
      if ((colLen + VARSTR_HEADER_SIZE) > pTagSchema->bytes) {
×
169
        code = buildInvalidOperationMsg(&pBuf, "tag length is too big");
×
170
        goto end;
×
171
      }
172
    }
173
    if (NULL == taosArrayPush(tagName, pTagSchema->name)) {
2!
174
      code = terrno;
×
175
      goto end;
×
176
    }
177
    if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
1!
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};
1✔
197
      //      strcpy(val.colName, pTagSchema->name);
198
      if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
1!
199
          pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
1!
UNCOV
200
        if (pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
×
UNCOV
201
          code = initCtxAsText();
×
UNCOV
202
          if (code) {
×
203
            qError("geometry init failed:%s", tstrerror(code));
×
204
            goto end;
×
205
          }
UNCOV
206
          code = checkWKB(bind[c].buffer, colLen);
×
UNCOV
207
          if (code) {
×
208
            qError("stmt bind invalid geometry tag:%s, must be WKB format", (char*)bind[c].buffer);
×
209
            goto end;
×
210
          }
211
        }
UNCOV
212
        val.pData = (uint8_t*)bind[c].buffer;
×
UNCOV
213
        val.nData = colLen;
×
214
      } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
1!
UNCOV
215
        int32_t output = 0;
×
UNCOV
216
        void*   p = taosMemoryCalloc(1, colLen * TSDB_NCHAR_SIZE);
×
UNCOV
217
        if (p == NULL) {
×
218
          code = terrno;
×
219
          goto end;
×
220
        }
UNCOV
221
        if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output, charsetCxt)) {
×
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
        }
UNCOV
233
        val.pData = p;
×
UNCOV
234
        val.nData = output;
×
235
      } else {
236
        memcpy(&val.i64, bind[c].buffer, colLen);
1✔
237
      }
238
      if (IS_VAR_DATA_TYPE(pTagSchema->type) && val.nData > pTagSchema->bytes) {
1!
239
        code = TSDB_CODE_PAR_VALUE_TOO_LONG;
×
240
        goto end;
×
241
      }
242
      if (NULL == taosArrayPush(pTagArray, &val)) {
1!
243
        code = terrno;
×
244
        goto end;
×
245
      }
246
    }
247
  }
248

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

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

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

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

283
  return code;
1✔
284
}
285

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

296
  if (NULL == dst->length) {
967,058!
297
    dst->length = taosMemoryRealloc(dst->length, sizeof(int32_t) * src->num);
968,142!
298
    if (NULL == dst->length) {
985,124!
299
      taosMemoryFreeClear(dst->buffer);
×
300
      return terrno;
×
301
    }
302
  }
303

304
  dst->buffer_length = pSchema->bytes - VARSTR_HEADER_SIZE;
984,040✔
305

306
  for (int32_t i = 0; i < src->num; ++i) {
2,005,701✔
307
    if (src->is_null && src->is_null[i]) {
999,082✔
308
      continue;
51,139✔
309
    }
310

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

321
    dst->length[i] = output;
970,522✔
322
  }
323

324
  dst->buffer_type = src->buffer_type;
1,006,619✔
325
  dst->is_null = src->is_null;
1,006,619✔
326
  dst->num = src->num;
1,006,619✔
327

328
  return TSDB_CODE_SUCCESS;
1,006,619✔
329
}
330

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

344
  if (NULL == pTSchema || NULL == *pTSchema) {
50,428✔
345
    *pTSchema = tBuildTSchema(pSchema, pDataBlock->pMeta->tableInfo.numOfColumns, pDataBlock->pMeta->sversion);
124✔
346
  }
347

348
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
253,594✔
349
    SSchema* pColSchema = &pSchema[boundInfo->pColIndex[c]];
203,189✔
350
    if (pColSchema->colId <= lastColId) {
203,189!
351
      colInOrder = false;
×
352
    } else {
353
      lastColId = pColSchema->colId;
203,189✔
354
    }
355
    // SColData* pCol = taosArrayGet(pCols, c);
356

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

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

368
    if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
203,189✔
369
      code = convertStmtNcharCol(&pBuf, pColSchema, bind + c, &ncharBind, charsetCxt);
168✔
370
      if (code) {
168!
371
        goto _return;
×
372
      }
373
      pBind = &ncharBind;
168✔
374
    } else {
375
      pBind = bind + c;
203,021✔
376
    }
377

378
    pBindInfos[c].columnId = pColSchema->colId;
203,189✔
379
    pBindInfos[c].bind = pBind;
203,189✔
380
    pBindInfos[c].type = pColSchema->type;
203,189✔
381

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

388
  code = tRowBuildFromBind(pBindInfos, boundInfo->numOfBound, colInOrder, *pTSchema, pCols, &pDataBlock->ordered, &pDataBlock->duplicateTs);
50,405✔
389

390
  parserDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum);
50,737!
391

392
_return:
50,737✔
393

394
  taosMemoryFree(ncharBind.buffer);
50,737!
395
  taosMemoryFree(ncharBind.length);
50,684!
396

397
  return code;
50,634✔
398
}
399

400
int32_t qBindStmtColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, void* charsetCxt) {
1,032,868✔
401
  STableDataCxt*   pDataBlock = (STableDataCxt*)pBlock;
1,032,868✔
402
  SSchema*         pSchema = getTableColumnSchema(pDataBlock->pMeta);
1,032,868✔
403
  SBoundColInfo*   boundInfo = &pDataBlock->boundColsInfo;
1,017,718✔
404
  SMsgBuf          pBuf = {.buf = msgBuf, .len = msgBufLen};
1,017,718✔
405
  int32_t          rowNum = bind->num;
1,017,718✔
406
  TAOS_MULTI_BIND  ncharBind = {0};
1,017,718✔
407
  TAOS_MULTI_BIND* pBind = NULL;
1,017,718✔
408
  int32_t          code = 0;
1,017,718✔
409

410
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
9,221,537✔
411
    SSchema*  pColSchema = &pSchema[boundInfo->pColIndex[c]];
8,117,821✔
412
    SColData* pCol = taosArrayGet(pCols, c);
8,117,821✔
413

414
    if (bind[c].num != rowNum) {
7,959,269!
415
      code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
416
      goto _return;
×
417
    }
418

419
    if ((!(rowNum == 1 && bind[c].is_null && *bind[c].is_null)) &&
8,533,395✔
420
        bind[c].buffer_type != pColSchema->type) {  // for rowNum ==1 , connector may not set buffer_type
7,954,592!
421
      code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
422
      goto _return;
×
423
    }
424

425
    if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
8,533,395✔
426
      code = convertStmtNcharCol(&pBuf, pColSchema, bind + c, &ncharBind, charsetCxt);
954,979✔
427
      if (code) {
991,089!
428
        goto _return;
×
429
      }
430
      pBind = &ncharBind;
991,089✔
431
    } else {
432
      pBind = bind + c;
7,578,416✔
433
    }
434

435
    code = tColDataAddValueByBind(pCol, pBind,
8,569,505✔
436
                                  IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1,
8,569,505!
437
                                  initCtxAsText, checkWKB);
438
    if (code) {
8,203,819!
UNCOV
439
      goto _return;
×
440
    }
441
  }
442

443
  parserDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum);
1,103,716✔
444

445
_return:
1,103,712✔
446

447
  taosMemoryFree(ncharBind.buffer);
1,103,716!
448
  taosMemoryFree(ncharBind.length);
994,503!
449

450
  return code;
1,022,293✔
451
}
452

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

UNCOV
465
  if (bind->num != rowNum) {
×
466
    return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
467
  }
468

469
  // Column index exceeds the number of columns
UNCOV
470
  if (colIdx >= pCols->size && pCol == NULL) {
×
471
    return buildInvalidOperationMsg(&pBuf, "column index exceeds the number of columns");
×
472
  }
473

UNCOV
474
  if (bind->buffer_type != pColSchema->type) {
×
475
    return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
476
  }
477

UNCOV
478
  if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
×
UNCOV
479
    code = convertStmtNcharCol(&pBuf, pColSchema, bind, &ncharBind, charsetCxt);
×
UNCOV
480
    if (code) {
×
481
      goto _return;
×
482
    }
UNCOV
483
    pBind = &ncharBind;
×
484
  } else {
UNCOV
485
    pBind = bind;
×
486
  }
487

UNCOV
488
  code = tColDataAddValueByBind(pCol, pBind,
×
UNCOV
489
                                IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1,
×
490
                                initCtxAsText, checkWKB);
491

UNCOV
492
  parserDebug("stmt col %d bind %d rows data", colIdx, rowNum);
×
493

UNCOV
494
_return:
×
495

UNCOV
496
  taosMemoryFree(ncharBind.buffer);
×
UNCOV
497
  taosMemoryFree(ncharBind.length);
×
498

UNCOV
499
  return code;
×
500
}
501

UNCOV
502
int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName,
×
503
                            TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen, void* charsetCxt,
504
                            SVCreateTbReq* pCreateTbReq) {
UNCOV
505
  STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
×
UNCOV
506
  SMsgBuf        pBuf = {.buf = msgBuf, .len = msgBufLen};
×
UNCOV
507
  int32_t        code = TSDB_CODE_SUCCESS;
×
UNCOV
508
  SBoundColInfo* tags = (SBoundColInfo*)boundTags;
×
UNCOV
509
  if (NULL == tags) {
×
510
    return TSDB_CODE_APP_ERROR;
×
511
  }
512

UNCOV
513
  SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
×
UNCOV
514
  if (!pTagArray) {
×
515
    return buildInvalidOperationMsg(&pBuf, "out of memory");
×
516
  }
517

UNCOV
518
  SArray* tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
×
UNCOV
519
  if (!tagName) {
×
520
    code = buildInvalidOperationMsg(&pBuf, "out of memory");
×
521
    goto end;
×
522
  }
523

UNCOV
524
  SSchema* pSchema = getTableTagSchema(pDataBlock->pMeta);
×
525

UNCOV
526
  bool  isJson = false;
×
UNCOV
527
  STag* pTag = NULL;
×
528

UNCOV
529
  for (int c = 0; c < tags->numOfBound; ++c) {
×
UNCOV
530
    if (bind == NULL) {
×
531
      break;
×
532
    }
UNCOV
533
    if (bind[c].is_null && bind[c].is_null[0]) {
×
534
      continue;
×
535
    }
536

UNCOV
537
    SSchema* pTagSchema = &pSchema[tags->pColIndex[c]];
×
UNCOV
538
    int32_t  colLen = pTagSchema->bytes;
×
UNCOV
539
    if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
×
UNCOV
540
      if (!bind[c].length) {
×
541
        code = buildInvalidOperationMsg(&pBuf, "var tag length is null");
×
542
        goto end;
×
543
      }
UNCOV
544
      colLen = bind[c].length[0];
×
UNCOV
545
      if ((colLen + VARSTR_HEADER_SIZE) > pTagSchema->bytes) {
×
546
        code = buildInvalidOperationMsg(&pBuf, "tag length is too big");
×
547
        goto end;
×
548
      }
549
    }
UNCOV
550
    if (NULL == taosArrayPush(tagName, pTagSchema->name)) {
×
551
      code = terrno;
×
552
      goto end;
×
553
    }
UNCOV
554
    if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
×
555
      if (colLen > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
×
556
        code = buildSyntaxErrMsg(&pBuf, "json string too long than 4095", bind[c].buffer);
×
557
        goto end;
×
558
      }
559

560
      isJson = true;
×
561
      char* tmp = taosMemoryCalloc(1, colLen + 1);
×
562
      if (!tmp) {
×
563
        code = terrno;
×
564
        goto end;
×
565
      }
566
      memcpy(tmp, bind[c].buffer, colLen);
×
567
      code = parseJsontoTagData(tmp, pTagArray, &pTag, &pBuf, charsetCxt);
×
568
      taosMemoryFree(tmp);
×
569
      if (code != TSDB_CODE_SUCCESS) {
×
570
        goto end;
×
571
      }
572
    } else {
UNCOV
573
      STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
×
574
      //      strcpy(val.colName, pTagSchema->name);
UNCOV
575
      if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY ||
×
UNCOV
576
          pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
×
UNCOV
577
        if (pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) {
×
UNCOV
578
          code = initCtxAsText();
×
UNCOV
579
          if (code) {
×
580
            qError("geometry init failed:%s", tstrerror(code));
×
UNCOV
581
            goto end;
×
582
          }
UNCOV
583
          code = checkWKB(bind[c].buffer, colLen);
×
UNCOV
584
          if (code) {
×
UNCOV
585
            qError("stmt2 bind invalid geometry tag:%s, must be WKB format", (char*)bind[c].buffer);
×
UNCOV
586
            goto end;
×
587
          }
588
        }
UNCOV
589
        val.pData = (uint8_t*)bind[c].buffer;
×
UNCOV
590
        val.nData = colLen;
×
UNCOV
591
      } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
×
UNCOV
592
        int32_t output = 0;
×
UNCOV
593
        void*   p = taosMemoryCalloc(1, colLen * TSDB_NCHAR_SIZE);
×
UNCOV
594
        if (p == NULL) {
×
595
          code = terrno;
×
596
          goto end;
×
597
        }
UNCOV
598
        if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output, charsetCxt)) {
×
599
          if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
×
600
            taosMemoryFree(p);
×
601
            code = generateSyntaxErrMsg(&pBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
×
602
            goto end;
×
603
          }
604
          char buf[512] = {0};
×
605
          snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno));
×
606
          taosMemoryFree(p);
×
607
          code = buildSyntaxErrMsg(&pBuf, buf, bind[c].buffer);
×
608
          goto end;
×
609
        }
UNCOV
610
        val.pData = p;
×
UNCOV
611
        val.nData = output;
×
612
      } else {
UNCOV
613
        memcpy(&val.i64, bind[c].buffer, colLen);
×
614
      }
UNCOV
615
      if (IS_VAR_DATA_TYPE(pTagSchema->type) && val.nData > pTagSchema->bytes) {
×
616
        code = TSDB_CODE_PAR_VALUE_TOO_LONG;
×
617
        goto end;
×
618
      }
UNCOV
619
      if (NULL == taosArrayPush(pTagArray, &val)) {
×
620
        code = terrno;
×
621
        goto end;
×
622
      }
623
    }
624
  }
625

UNCOV
626
  if (!isJson && (code = tTagNew(pTagArray, 1, false, &pTag)) != TSDB_CODE_SUCCESS) {
×
627
    goto end;
×
628
  }
629

UNCOV
630
  if (pCreateTbReq){
×
UNCOV
631
    code = insBuildCreateTbReq(pCreateTbReq, tName, pTag, suid, sTableName, tagName,
×
UNCOV
632
                               pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL);
×
UNCOV
633
    pTag = NULL;
×
UNCOV
634
    goto end;
×
635
  }
636

UNCOV
637
  if (NULL == pDataBlock->pData->pCreateTbReq) {
×
UNCOV
638
    pDataBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
×
UNCOV
639
    if (NULL == pDataBlock->pData->pCreateTbReq) {
×
640
      code = terrno;
×
641
      goto end;
×
642
    }
643
  } else {
UNCOV
644
    SVCreateTbReq* tmp = pDataBlock->pData->pCreateTbReq;
×
UNCOV
645
    taosMemoryFreeClear(tmp->name);
×
UNCOV
646
    taosMemoryFreeClear(tmp->ctb.pTag);
×
UNCOV
647
    taosMemoryFreeClear(tmp->ctb.stbName);
×
UNCOV
648
    taosArrayDestroy(tmp->ctb.tagName);
×
UNCOV
649
    tmp->ctb.tagName = NULL;
×
650
  }
651

UNCOV
652
  code = insBuildCreateTbReq(pDataBlock->pData->pCreateTbReq, tName, pTag, suid, sTableName, tagName,
×
UNCOV
653
                             pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL);
×
UNCOV
654
  pTag = NULL;
×
655

UNCOV
656
end:
×
UNCOV
657
  for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
×
UNCOV
658
    STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
×
UNCOV
659
    if (p->type == TSDB_DATA_TYPE_NCHAR) {
×
UNCOV
660
      taosMemoryFreeClear(p->pData);
×
661
    }
662
  }
UNCOV
663
  taosArrayDestroy(pTagArray);
×
UNCOV
664
  taosArrayDestroy(tagName);
×
UNCOV
665
  taosMemoryFree(pTag);
×
666

UNCOV
667
  return code;
×
668
}
669

670
static int32_t convertStmtStbNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STMT2_BIND* src, TAOS_STMT2_BIND* dst, void *charsetCxt) {
3✔
671
  int32_t       output = 0;
3✔
672
  const int32_t max_buf_len = pSchema->bytes - VARSTR_HEADER_SIZE;
3✔
673

674
  dst->buffer = taosMemoryCalloc(src->num, max_buf_len);
3!
675
  if (NULL == dst->buffer) {
3!
676
    return terrno;
×
677
  }
678

679
  dst->length = taosMemoryCalloc(src->num, sizeof(int32_t));
3!
680
  if (NULL == dst->length) {
3!
681
    taosMemoryFreeClear(dst->buffer);
×
682
    return terrno;
×
683
  }
684

685
  char* src_buf = src->buffer;
3✔
686
  char* dst_buf = dst->buffer;
3✔
687
  for (int32_t i = 0; i < src->num; ++i) {
2,997✔
688
    if (src->is_null && src->is_null[i]) {
2,994!
689
      continue;
×
690
    }
691

692
    if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output, charsetCxt)) {
2,994!
693
      if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
×
694
        return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
×
695
      }
696
      char buf[512] = {0};
×
697
      snprintf(buf, tListLen(buf), "%s", strerror(terrno));
×
698
      return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
×
699
    }
700

701
    dst->length[i] = output;
2,994✔
702
    src_buf += src->length[i];
2,994✔
703
    dst_buf += output;
2,994✔
704
  }
705

706
  dst->buffer_type = src->buffer_type;
3✔
707
  dst->is_null = src->is_null;
3✔
708
  dst->num = src->num;
3✔
709

710
  return TSDB_CODE_SUCCESS;
3✔
711
}
712

713
int32_t qBindStmtStbColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen,
5,174✔
714
                               STSchema** pTSchema, SBindInfo2* pBindInfos, void *charsetCxt) {
715
  STableDataCxt*  pDataBlock = (STableDataCxt*)pBlock;
5,174✔
716
  SSchema*        pSchema = getTableColumnSchema(pDataBlock->pMeta);
5,174✔
717
  SBoundColInfo*  boundInfo = &pDataBlock->boundColsInfo;
5,172✔
718
  SMsgBuf         pBuf = {.buf = msgBuf, .len = msgBufLen};
5,172✔
719
  int32_t         rowNum = bind->num;
5,172✔
720
  SArray*         ncharBinds = NULL;
5,172✔
721
  TAOS_STMT2_BIND ncharBind = {0};
5,172✔
722
  int32_t         code = 0;
5,172✔
723
  int16_t         lastColId = -1;
5,172✔
724
  bool            colInOrder = true;
5,172✔
725
  int             ncharColNums = 0;
5,172✔
726

727
  if (NULL == pTSchema || NULL == *pTSchema) {
5,172!
728
    *pTSchema = tBuildTSchema(pSchema, pDataBlock->pMeta->tableInfo.numOfColumns, pDataBlock->pMeta->sversion);
54✔
729
  }
730

731
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
34,297✔
732
    if (TSDB_DATA_TYPE_NCHAR == pSchema[boundInfo->pColIndex[c]].type) {
29,119✔
733
      ncharColNums++;
3✔
734
    }
735
  }
736
  if (ncharColNums > 0) {
5,178✔
737
    ncharBinds = taosArrayInit(ncharColNums, sizeof(ncharBind));
3✔
738
    if (!ncharBinds) {
3✔
739
      code = terrno;
2✔
740
      goto _return;
×
741
    }
742
  }
743

744
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
33,933✔
745
    SSchema* pColSchema = &pSchema[boundInfo->pColIndex[c]];
28,757✔
746
    if (pColSchema->colId <= lastColId) {
28,757!
UNCOV
747
      colInOrder = false;
×
748
    } else {
749
      lastColId = pColSchema->colId;
28,757✔
750
    }
751

752
    if (bind[c].num != rowNum) {
28,757!
753
      code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
754
      goto _return;
×
755
    }
756

757
    if ((!(rowNum == 1 && bind[c].is_null && *bind[c].is_null)) &&
28,757!
758
        bind[c].buffer_type != pColSchema->type) {  // for rowNum ==1 , connector may not set buffer_type
28,761!
759
      code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
760
      goto _return;
×
761
    }
762

763
    if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
28,757✔
764
      code = convertStmtStbNcharCol2(&pBuf, pColSchema, bind + c, &ncharBind, charsetCxt);
3✔
765
      if (code) {
3!
766
        goto _return;
×
767
      }
768
      if (!taosArrayPush(ncharBinds, &ncharBind)) {
3!
769
        code = terrno;
×
770
        goto _return;
×
771
      }
772
      pBindInfos[c].bind = taosArrayGetLast(ncharBinds);
3✔
773
    } else if (TSDB_DATA_TYPE_GEOMETRY == pColSchema->type) {
28,754!
UNCOV
774
      code = initCtxAsText();
×
UNCOV
775
      if (code) {
×
776
        qError("geometry init failed:%s", tstrerror(code));
×
777
        goto _return;
×
778
      }
UNCOV
779
      uint8_t* buf = bind[c].buffer;
×
UNCOV
780
      for (int j = 0; j < bind[c].num; j++) {
×
UNCOV
781
        if (bind[c].is_null && bind[c].is_null[j]) {
×
UNCOV
782
          continue;
×
783
        }
UNCOV
784
        code = checkWKB(buf, bind[c].length[j]);
×
UNCOV
785
        if (code) {
×
786
          qError("stmt2 interlace mode geometry data[%d]:{%s},length:%d must be in WKB format", c, buf,
×
787
                 bind[c].length[j]);
788
          goto _return;
×
789
        }
UNCOV
790
        buf += bind[c].length[j];
×
791
      }
UNCOV
792
      pBindInfos[c].bind = bind + c;
×
793
    } else {
794
      pBindInfos[c].bind = bind + c;
28,754✔
795
    }
796

797
    pBindInfos[c].columnId = pColSchema->colId;
28,757✔
798
    pBindInfos[c].type = pColSchema->type;
28,757✔
799
    pBindInfos[c].bytes = pColSchema->bytes;
28,757✔
800
  }
801

802
  code = tRowBuildFromBind2(pBindInfos, boundInfo->numOfBound, colInOrder, *pTSchema, pCols, &pDataBlock->ordered, &pDataBlock->duplicateTs);
5,176✔
803

804
  parserDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum);
5,177!
805

806
_return:
5,177✔
807
  if (ncharBinds) {
5,177✔
808
    for (int i = 0; i < TARRAY_SIZE(ncharBinds); ++i) {
6✔
809
      TAOS_STMT2_BIND* ncBind = TARRAY_DATA(ncharBinds);
3✔
810
      taosMemoryFree(ncBind[i].buffer);
3!
811
      taosMemoryFree(ncBind[i].length);
3!
812
    }
813
    taosArrayDestroy(ncharBinds);
3✔
814
  }
815

816
  return code;
5,177✔
817
}
818

UNCOV
819
static int32_t convertStmtNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STMT2_BIND* src, TAOS_STMT2_BIND* dst, void *charsetCxt) {
×
UNCOV
820
  int32_t       output = 0;
×
UNCOV
821
  const int32_t max_buf_len = pSchema->bytes - VARSTR_HEADER_SIZE;
×
822

UNCOV
823
  int32_t newBuflen = (pSchema->bytes - VARSTR_HEADER_SIZE) * src->num;
×
824
  // if (dst->buffer_length < newBuflen) {
UNCOV
825
  dst->buffer = taosMemoryRealloc(dst->buffer, newBuflen);
×
UNCOV
826
  if (NULL == dst->buffer) {
×
827
    return terrno;
×
828
  }
829
  //}
830

UNCOV
831
  if (NULL == dst->length) {
×
UNCOV
832
    dst->length = taosMemoryRealloc(dst->length, sizeof(int32_t) * src->num);
×
UNCOV
833
    if (NULL == dst->length) {
×
834
      taosMemoryFreeClear(dst->buffer);
×
835
      return terrno;
×
836
    }
837
  }
838

839
  // dst->buffer_length = pSchema->bytes - VARSTR_HEADER_SIZE;
UNCOV
840
  char* src_buf = src->buffer;
×
UNCOV
841
  char* dst_buf = dst->buffer;
×
UNCOV
842
  for (int32_t i = 0; i < src->num; ++i) {
×
UNCOV
843
    if (src->is_null && src->is_null[i]) {
×
844
      continue;
×
845
    }
846

847
    /*if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i],
848
      (TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) {*/
UNCOV
849
    if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output, charsetCxt)) {
×
850
      if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) {
×
851
        return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
×
852
      }
853
      char buf[512] = {0};
×
854
      snprintf(buf, tListLen(buf), "%s", strerror(terrno));
×
855
      return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
×
856
    }
857

UNCOV
858
    dst->length[i] = output;
×
UNCOV
859
    src_buf += src->length[i];
×
UNCOV
860
    dst_buf += output;
×
861
  }
862

UNCOV
863
  dst->buffer_type = src->buffer_type;
×
UNCOV
864
  dst->is_null = src->is_null;
×
UNCOV
865
  dst->num = src->num;
×
866

UNCOV
867
  return TSDB_CODE_SUCCESS;
×
868
}
869

UNCOV
870
int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen,
×
871
                            void* charsetCxt) {
UNCOV
872
  STableDataCxt*   pDataBlock = (STableDataCxt*)pBlock;
×
UNCOV
873
  SSchema*         pSchema = getTableColumnSchema(pDataBlock->pMeta);
×
UNCOV
874
  SBoundColInfo*   boundInfo = &pDataBlock->boundColsInfo;
×
UNCOV
875
  SMsgBuf          pBuf = {.buf = msgBuf, .len = msgBufLen};
×
UNCOV
876
  int32_t          rowNum = bind->num;
×
UNCOV
877
  TAOS_STMT2_BIND  ncharBind = {0};
×
UNCOV
878
  TAOS_STMT2_BIND* pBind = NULL;
×
UNCOV
879
  int32_t          code = 0;
×
880

UNCOV
881
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
×
UNCOV
882
    SSchema*  pColSchema = &pSchema[boundInfo->pColIndex[c]];
×
UNCOV
883
    SColData* pCol = taosArrayGet(pCols, c);
×
UNCOV
884
    if (pCol == NULL || pColSchema == NULL) {
×
885
      code = buildInvalidOperationMsg(&pBuf, "get column schema or column data failed");
×
886
      goto _return;
×
887
    }
888

UNCOV
889
    if (boundInfo->pColIndex[c] == 0) {
×
UNCOV
890
      pCol->cflag |= COL_IS_KEY;
×
891
    }
892

UNCOV
893
    if (bind[c].num != rowNum) {
×
894
      code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
895
      goto _return;
×
896
    }
897

UNCOV
898
    if ((!(rowNum == 1 && bind[c].is_null && *bind[c].is_null)) &&
×
UNCOV
899
        bind[c].buffer_type != pColSchema->type) {  // for rowNum ==1 , connector may not set buffer_type
×
900
      code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
901
      goto _return;
×
902
    }
903

UNCOV
904
    if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
×
UNCOV
905
      code = convertStmtNcharCol2(&pBuf, pColSchema, bind + c, &ncharBind, charsetCxt);
×
UNCOV
906
      if (code) {
×
907
        goto _return;
×
908
      }
UNCOV
909
      pBind = &ncharBind;
×
910
    } else {
UNCOV
911
      pBind = bind + c;
×
912
    }
913

UNCOV
914
    code = tColDataAddValueByBind2(pCol, pBind,
×
UNCOV
915
                                   IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1,
×
916
                                   initCtxAsText, checkWKB);
UNCOV
917
    if (code) {
×
918
      goto _return;
×
919
    }
920
  }
921

UNCOV
922
  parserDebug("stmt2 all %d columns bind %d rows data as col format", boundInfo->numOfBound, rowNum);
×
923

UNCOV
924
_return:
×
925

UNCOV
926
  taosMemoryFree(ncharBind.buffer);
×
UNCOV
927
  taosMemoryFree(ncharBind.length);
×
928

UNCOV
929
  return code;
×
930
}
931

UNCOV
932
int32_t qBindStmtSingleColValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen,
×
933
                                 int32_t colIdx, int32_t rowNum, void *charsetCxt) {
UNCOV
934
  STableDataCxt*   pDataBlock = (STableDataCxt*)pBlock;
×
UNCOV
935
  SSchema*         pSchema = getTableColumnSchema(pDataBlock->pMeta);
×
UNCOV
936
  SBoundColInfo*   boundInfo = &pDataBlock->boundColsInfo;
×
UNCOV
937
  SMsgBuf          pBuf = {.buf = msgBuf, .len = msgBufLen};
×
UNCOV
938
  SSchema*         pColSchema = &pSchema[boundInfo->pColIndex[colIdx]];
×
UNCOV
939
  SColData*        pCol = taosArrayGet(pCols, colIdx);
×
UNCOV
940
  TAOS_STMT2_BIND  ncharBind = {0};
×
UNCOV
941
  TAOS_STMT2_BIND* pBind = NULL;
×
UNCOV
942
  int32_t          code = 0;
×
943

UNCOV
944
  if (bind->num != rowNum) {
×
945
    return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
946
  }
947

948
  // Column index exceeds the number of columns
UNCOV
949
  if (colIdx >= pCols->size && pCol == NULL) {
×
950
    return buildInvalidOperationMsg(&pBuf, "column index exceeds the number of columns");
×
951
  }
952

UNCOV
953
  if (bind->buffer_type != pColSchema->type) {
×
954
    return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
955
  }
956

UNCOV
957
  if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
×
958
    code = convertStmtNcharCol2(&pBuf, pColSchema, bind, &ncharBind, charsetCxt);
×
959
    if (code) {
×
960
      goto _return;
×
961
    }
962
    pBind = &ncharBind;
×
963
  } else {
UNCOV
964
    pBind = bind;
×
965
  }
966

UNCOV
967
  code = tColDataAddValueByBind2(pCol, pBind,
×
UNCOV
968
                                 IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1,
×
969
                                 initCtxAsText, checkWKB);
970

UNCOV
971
  parserDebug("stmt col %d bind %d rows data", colIdx, rowNum);
×
972

UNCOV
973
_return:
×
974

UNCOV
975
  taosMemoryFree(ncharBind.buffer);
×
UNCOV
976
  taosMemoryFree(ncharBind.length);
×
977

UNCOV
978
  return code;
×
979
}
980

UNCOV
981
int32_t qBindStmt2RowValue(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen,
×
982
                            STSchema** pTSchema, SBindInfo2* pBindInfos, void* charsetCxt) {
UNCOV
983
  STableDataCxt*   pDataBlock = (STableDataCxt*)pBlock;
×
UNCOV
984
  SSchema*         pSchema = getTableColumnSchema(pDataBlock->pMeta);
×
UNCOV
985
  SBoundColInfo*   boundInfo = &pDataBlock->boundColsInfo;
×
UNCOV
986
  SMsgBuf          pBuf = {.buf = msgBuf, .len = msgBufLen};
×
UNCOV
987
  int32_t          rowNum = bind->num;
×
UNCOV
988
  TAOS_STMT2_BIND  ncharBind = {0};
×
UNCOV
989
  TAOS_STMT2_BIND* pBind = NULL;
×
UNCOV
990
  int32_t          code = 0;
×
UNCOV
991
  int16_t          lastColId = -1;
×
UNCOV
992
  bool             colInOrder = true;
×
993

UNCOV
994
  if (NULL == pTSchema || NULL == *pTSchema) {
×
UNCOV
995
    *pTSchema = tBuildTSchema(pSchema, pDataBlock->pMeta->tableInfo.numOfColumns, pDataBlock->pMeta->sversion);
×
996
  }
997

UNCOV
998
  for (int c = 0; c < boundInfo->numOfBound; ++c) {
×
UNCOV
999
    SSchema*  pColSchema = &pSchema[boundInfo->pColIndex[c]];
×
UNCOV
1000
    if (pColSchema->colId <= lastColId) {
×
1001
      colInOrder = false;
×
1002
    } else {
UNCOV
1003
      lastColId = pColSchema->colId;
×
1004
    }
1005

UNCOV
1006
    if (bind[c].num != rowNum) {
×
1007
      code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
×
1008
      goto _return;
×
1009
    }
1010

UNCOV
1011
    if ((!(rowNum == 1 && bind[c].is_null && *bind[c].is_null)) &&
×
UNCOV
1012
        bind[c].buffer_type != pColSchema->type) {  // for rowNum ==1 , connector may not set buffer_type
×
1013
      code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
×
1014
      goto _return;
×
1015
    }
1016

UNCOV
1017
    if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
×
UNCOV
1018
      code = convertStmtNcharCol2(&pBuf, pColSchema, bind + c, &ncharBind, charsetCxt);
×
UNCOV
1019
      if (code) {
×
1020
        goto _return;
×
1021
      }
UNCOV
1022
      pBindInfos[c].bind = &ncharBind;
×
UNCOV
1023
    } else if (TSDB_DATA_TYPE_GEOMETRY == pColSchema->type) {
×
UNCOV
1024
      code = initCtxAsText();
×
UNCOV
1025
      if (code) {
×
1026
        qError("geometry init failed:%s", tstrerror(code));
×
1027
        goto _return;
×
1028
      }
UNCOV
1029
      uint8_t *buf = bind[c].buffer;
×
UNCOV
1030
      for (int j = 0; j < bind[c].num; j++) {
×
UNCOV
1031
        if (bind[c].is_null && bind[c].is_null[j]) {
×
1032
          continue;
×
1033
        }
UNCOV
1034
        code = checkWKB(buf, bind[c].length[j]);
×
UNCOV
1035
        if (code) {
×
1036
          qError("stmt2 row bind geometry data[%d]:{%s},length:%d must be in WKB format", c, buf, bind[c].length[j]);
×
1037
          goto _return;
×
1038
        }
UNCOV
1039
        buf += bind[c].length[j];
×
1040
      }
UNCOV
1041
      pBindInfos[c].bind = bind + c;
×
1042
    } else {
UNCOV
1043
      pBindInfos[c].bind = bind + c;
×
1044
    }
1045

UNCOV
1046
    pBindInfos[c].columnId = pColSchema->colId;
×
UNCOV
1047
    pBindInfos[c].type = pColSchema->type;
×
UNCOV
1048
    pBindInfos[c].bytes = pColSchema->bytes;
×
1049

UNCOV
1050
    if (code) {
×
1051
      goto _return;
×
1052
    }
1053
  }
1054

UNCOV
1055
  pDataBlock->pData->flags &= ~SUBMIT_REQ_COLUMN_DATA_FORMAT;
×
UNCOV
1056
  if (pDataBlock->pData->pCreateTbReq != NULL) {
×
UNCOV
1057
    pDataBlock->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE;
×
1058
  }
1059

UNCOV
1060
  code = tRowBuildFromBind2(pBindInfos, boundInfo->numOfBound, colInOrder, *pTSchema, pCols, &pDataBlock->ordered,
×
1061
                            &pDataBlock->duplicateTs);
UNCOV
1062
  qDebug("stmt2 all %d columns bind %d rows data as row format", boundInfo->numOfBound, rowNum);
×
1063

UNCOV
1064
_return:
×
1065

UNCOV
1066
  taosMemoryFree(ncharBind.buffer);
×
UNCOV
1067
  taosMemoryFree(ncharBind.length);
×
1068

UNCOV
1069
  return code;
×
1070
}
1071

UNCOV
1072
int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSchema, int32_t* fieldNum,
×
1073
                         TAOS_FIELD_E** fields, uint8_t timePrec) {
UNCOV
1074
  if (fields != NULL) {
×
UNCOV
1075
    *fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_E));
×
UNCOV
1076
    if (NULL == *fields) {
×
1077
      return terrno;
×
1078
    }
1079

UNCOV
1080
    SSchema* schema = &pSchema[boundColumns[0]];
×
UNCOV
1081
    if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
×
UNCOV
1082
      (*fields)[0].precision = timePrec;
×
1083
    }
1084

UNCOV
1085
    for (int32_t i = 0; i < numOfBound; ++i) {
×
UNCOV
1086
      schema = &pSchema[boundColumns[i]];
×
UNCOV
1087
      tstrncpy((*fields)[i].name, schema->name, 65);
×
UNCOV
1088
      (*fields)[i].type = schema->type;
×
UNCOV
1089
      (*fields)[i].bytes = calcTypeBytesFromSchemaBytes(schema->type, schema->bytes, true);
×
1090
    }
1091
  }
1092

UNCOV
1093
  *fieldNum = numOfBound;
×
1094

UNCOV
1095
  return TSDB_CODE_SUCCESS;
×
1096
}
1097

UNCOV
1098
int32_t buildStbBoundFields(SBoundColInfo boundColsInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD_ALL** fields,
×
1099
                            STableMeta* pMeta, void* boundTags, uint8_t tbNameFlag) {
UNCOV
1100
  SBoundColInfo* tags = (SBoundColInfo*)boundTags;
×
UNCOV
1101
  bool           hastag = (tags != NULL) && !(tbNameFlag & IS_FIXED_TAG);
×
UNCOV
1102
  bool           hasPreBindTbname =
×
UNCOV
1103
      (tbNameFlag & IS_FIXED_VALUE) == 0 && ((tbNameFlag & USING_CLAUSE) != 0 || pMeta->tableType == TSDB_NORMAL_TABLE);
×
UNCOV
1104
  int32_t numOfBound = boundColsInfo.numOfBound + (hasPreBindTbname ? 1 : 0);
×
UNCOV
1105
  if (hastag) {
×
UNCOV
1106
    numOfBound += tags->mixTagsCols ? 0 : tags->numOfBound;
×
1107
  }
UNCOV
1108
  int32_t idx = 0;
×
UNCOV
1109
  if (fields != NULL) {
×
UNCOV
1110
    *fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_ALL));
×
UNCOV
1111
    if (NULL == *fields) {
×
1112
      return terrno;
×
1113
    }
1114

UNCOV
1115
    if (hasPreBindTbname) {
×
UNCOV
1116
      (*fields)[idx].field_type = TAOS_FIELD_TBNAME;
×
UNCOV
1117
      tstrncpy((*fields)[idx].name, "tbname", sizeof((*fields)[idx].name));
×
UNCOV
1118
      (*fields)[idx].type = TSDB_DATA_TYPE_BINARY;
×
UNCOV
1119
      (*fields)[idx].bytes = TSDB_TABLE_FNAME_LEN;
×
UNCOV
1120
      idx++;
×
1121
    }
1122

UNCOV
1123
    if (hastag && tags->numOfBound > 0 && !tags->mixTagsCols) {
×
UNCOV
1124
      SSchema* tagSchema = getTableTagSchema(pMeta);
×
1125

UNCOV
1126
      for (int32_t i = 0; i < tags->numOfBound; ++i) {
×
UNCOV
1127
        (*fields)[idx].field_type = TAOS_FIELD_TAG;
×
1128

UNCOV
1129
        SSchema* schema = &tagSchema[tags->pColIndex[i]];
×
UNCOV
1130
        tstrncpy((*fields)[idx].name, schema->name, sizeof((*fields)[i].name));
×
UNCOV
1131
        (*fields)[idx].type = schema->type;
×
UNCOV
1132
        (*fields)[idx].bytes = schema->bytes;
×
UNCOV
1133
        if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
×
UNCOV
1134
          (*fields)[idx].precision = pMeta->tableInfo.precision;
×
1135
        }
UNCOV
1136
        idx++;
×
1137
      }
1138
    }
1139

UNCOV
1140
    if (boundColsInfo.numOfBound > 0) {
×
UNCOV
1141
      SSchema* schema = &pSchema[boundColsInfo.pColIndex[0]];
×
1142

UNCOV
1143
      for (int32_t i = 0; i < boundColsInfo.numOfBound; ++i) {
×
UNCOV
1144
        int16_t idxCol = boundColsInfo.pColIndex[i];
×
1145

UNCOV
1146
        if (idxCol == pMeta->tableInfo.numOfColumns + pMeta->tableInfo.numOfTags) {
×
UNCOV
1147
          (*fields)[idx].field_type = TAOS_FIELD_TBNAME;
×
UNCOV
1148
          tstrncpy((*fields)[i].name, "tbname", sizeof((*fields)[idx].name));
×
UNCOV
1149
          (*fields)[idx].type = TSDB_DATA_TYPE_BINARY;
×
UNCOV
1150
          (*fields)[idx].bytes = TSDB_TABLE_FNAME_LEN;
×
1151

UNCOV
1152
          idx++;
×
UNCOV
1153
          continue;
×
UNCOV
1154
        } else if (idxCol < pMeta->tableInfo.numOfColumns) {
×
UNCOV
1155
          (*fields)[idx].field_type = TAOS_FIELD_COL;
×
1156
        } else {
UNCOV
1157
          (*fields)[idx].field_type = TAOS_FIELD_TAG;
×
1158
        }
1159

UNCOV
1160
        schema = &pSchema[idxCol];
×
UNCOV
1161
        tstrncpy((*fields)[idx].name, schema->name, sizeof((*fields)[idx].name));
×
UNCOV
1162
        (*fields)[idx].type = schema->type;
×
UNCOV
1163
        (*fields)[idx].bytes = schema->bytes;
×
UNCOV
1164
        if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
×
UNCOV
1165
          (*fields)[idx].precision = pMeta->tableInfo.precision;
×
1166
        }
UNCOV
1167
        idx++;
×
1168
      }
1169
    }
1170
  }
1171

UNCOV
1172
  *fieldNum = numOfBound;
×
1173

UNCOV
1174
  return TSDB_CODE_SUCCESS;
×
1175
}
1176

UNCOV
1177
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields) {
×
UNCOV
1178
  STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
×
UNCOV
1179
  SBoundColInfo* tags = (SBoundColInfo*)boundTags;
×
UNCOV
1180
  if (NULL == tags) {
×
1181
    return TSDB_CODE_APP_ERROR;
×
1182
  }
1183

UNCOV
1184
  if (pDataBlock->pMeta->tableType != TSDB_SUPER_TABLE && pDataBlock->pMeta->tableType != TSDB_CHILD_TABLE) {
×
1185
    return TSDB_CODE_TSC_STMT_API_ERROR;
×
1186
  }
1187

UNCOV
1188
  SSchema* pSchema = getTableTagSchema(pDataBlock->pMeta);
×
UNCOV
1189
  if (tags->numOfBound <= 0) {
×
1190
    *fieldNum = 0;
×
1191
    *fields = NULL;
×
1192

1193
    return TSDB_CODE_SUCCESS;
×
1194
  }
1195

UNCOV
1196
  CHECK_CODE(buildBoundFields(tags->numOfBound, tags->pColIndex, pSchema, fieldNum, fields, 0));
×
1197

UNCOV
1198
  return TSDB_CODE_SUCCESS;
×
1199
}
1200

UNCOV
1201
int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_E** fields) {
×
UNCOV
1202
  STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
×
UNCOV
1203
  SSchema*       pSchema = getTableColumnSchema(pDataBlock->pMeta);
×
UNCOV
1204
  if (pDataBlock->boundColsInfo.numOfBound <= 0) {
×
1205
    *fieldNum = 0;
×
1206
    if (fields != NULL) {
×
1207
      *fields = NULL;
×
1208
    }
1209

1210
    return TSDB_CODE_SUCCESS;
×
1211
  }
1212

UNCOV
1213
  CHECK_CODE(buildBoundFields(pDataBlock->boundColsInfo.numOfBound, pDataBlock->boundColsInfo.pColIndex, pSchema,
×
1214
                              fieldNum, fields, pDataBlock->pMeta->tableInfo.precision));
1215

UNCOV
1216
  return TSDB_CODE_SUCCESS;
×
1217
}
1218

UNCOV
1219
int32_t qBuildStmtStbColFields(void* pBlock, void* boundTags, uint8_t tbNameFlag, int32_t* fieldNum,
×
1220
                               TAOS_FIELD_ALL** fields) {
UNCOV
1221
  STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
×
UNCOV
1222
  SSchema*       pSchema = getTableColumnSchema(pDataBlock->pMeta);
×
UNCOV
1223
  if (pDataBlock->boundColsInfo.numOfBound <= 0) {
×
1224
    *fieldNum = 0;
×
1225
    if (fields != NULL) {
×
1226
      *fields = NULL;
×
1227
    }
1228

1229
    return TSDB_CODE_SUCCESS;
×
1230
  }
1231

UNCOV
1232
  CHECK_CODE(buildStbBoundFields(pDataBlock->boundColsInfo, pSchema, fieldNum, fields, pDataBlock->pMeta, boundTags,
×
1233
                                 tbNameFlag));
1234

UNCOV
1235
  return TSDB_CODE_SUCCESS;
×
1236
}
1237

1238
int32_t qResetStmtColumns(SArray* pCols, bool deepClear) {
×
1239
  int32_t colNum = taosArrayGetSize(pCols);
×
1240

1241
  for (int32_t i = 0; i < colNum; ++i) {
×
1242
    SColData* pCol = (SColData*)taosArrayGet(pCols, i);
×
1243
    if (pCol == NULL) {
×
1244
      parserError("qResetStmtColumns column:%d is NULL", i);
×
1245
      return terrno;
×
1246
    }
1247
    if (deepClear) {
×
1248
      tColDataDeepClear(pCol);
×
1249
    } else {
1250
      tColDataClear(pCol);
×
1251
    }
1252
  }
1253

1254
  return TSDB_CODE_SUCCESS;
×
1255
}
1256

1257
int32_t qResetStmtDataBlock(STableDataCxt* block, bool deepClear) {
60,797✔
1258
  STableDataCxt* pBlock = (STableDataCxt*)block;
60,797✔
1259
  int32_t        colNum = taosArrayGetSize(pBlock->pData->aCol);
60,797✔
1260

1261
  for (int32_t i = 0; i < colNum; ++i) {
248,927✔
1262
    if (pBlock->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
188,150!
1263
      SColData* pCol = (SColData*)taosArrayGet(pBlock->pData->aCol, i);
188,150✔
1264
      if (pCol == NULL) {
188,149!
1265
        parserError("qResetStmtDataBlock column:%d is NULL", i);
×
1266
        return terrno;
×
1267
      }
1268
      if (deepClear) {
188,165✔
1269
        tColDataDeepClear(pCol);
63,164✔
1270
      } else {
1271
        tColDataClear(pCol);
125,001✔
1272
      }
1273
    } else {
UNCOV
1274
      pBlock->pData->aRowP = taosArrayInit(20, POINTER_BYTES);
×
1275
    }
1276
  }
1277

1278
  return TSDB_CODE_SUCCESS;
60,777✔
1279
}
1280

1281
int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset) {
20,144✔
1282
  int32_t code = 0;
20,144✔
1283

1284
  *pDst = taosMemoryCalloc(1, sizeof(STableDataCxt));
20,144!
1285
  if (NULL == *pDst) {
20,169!
1286
    return terrno;
×
1287
  }
1288

1289
  STableDataCxt* pNewCxt = (STableDataCxt*)*pDst;
20,169✔
1290
  STableDataCxt* pCxt = (STableDataCxt*)pSrc;
20,169✔
1291
  pNewCxt->pSchema = NULL;
20,169✔
1292
  pNewCxt->pValues = NULL;
20,169✔
1293

1294
  if (pCxt->pMeta) {
20,169!
1295
    void* pNewMeta = taosMemoryMalloc(TABLE_META_SIZE(pCxt->pMeta));
20,171!
1296
    if (NULL == pNewMeta) {
20,165!
1297
      insDestroyTableDataCxt(*pDst);
×
1298
      return terrno;
×
1299
    }
1300
    memcpy(pNewMeta, pCxt->pMeta, TABLE_META_SIZE(pCxt->pMeta));
20,165!
1301
    pNewCxt->pMeta = pNewMeta;
20,165✔
1302
  }
1303

1304
  memcpy(&pNewCxt->boundColsInfo, &pCxt->boundColsInfo, sizeof(pCxt->boundColsInfo));
20,163✔
1305
  pNewCxt->boundColsInfo.pColIndex = NULL;
20,163✔
1306

1307
  if (pCxt->boundColsInfo.pColIndex) {
20,163✔
1308
    void* pNewColIdx = taosMemoryMalloc(pCxt->boundColsInfo.numOfBound * sizeof(*pCxt->boundColsInfo.pColIndex));
20,155!
1309
    if (NULL == pNewColIdx) {
20,169!
1310
      insDestroyTableDataCxt(*pDst);
×
1311
      return terrno;
×
1312
    }
1313
    memcpy(pNewColIdx, pCxt->boundColsInfo.pColIndex,
20,169✔
1314
           pCxt->boundColsInfo.numOfBound * sizeof(*pCxt->boundColsInfo.pColIndex));
20,169✔
1315
    pNewCxt->boundColsInfo.pColIndex = pNewColIdx;
20,169✔
1316
  }
1317

1318
  if (pCxt->pData) {
20,177✔
1319
    SSubmitTbData* pNewTb = (SSubmitTbData*)taosMemoryMalloc(sizeof(SSubmitTbData));
20,164!
1320
    if (NULL == pNewTb) {
20,169!
1321
      insDestroyTableDataCxt(*pDst);
×
1322
      return terrno;
×
1323
    }
1324

1325
    memcpy(pNewTb, pCxt->pData, sizeof(*pCxt->pData));
20,169✔
1326
    pNewTb->pCreateTbReq = NULL;
20,169✔
1327

1328
    pNewTb->aCol = taosArrayDup(pCxt->pData->aCol, NULL);
20,169✔
1329
    if (NULL == pNewTb->aCol) {
20,156!
1330
      insDestroyTableDataCxt(*pDst);
×
1331
      return terrno;
×
1332
    }
1333

1334
    pNewCxt->pData = pNewTb;
20,156✔
1335

1336
    if (reset) {
20,156!
1337
      code = qResetStmtDataBlock(*pDst, true);
20,161✔
1338
    }
1339
  }
1340

1341
  return code;
20,162✔
1342
}
1343

UNCOV
1344
int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId,
×
1345
                              bool rebuildCreateTb) {
UNCOV
1346
  int32_t code = qCloneStmtDataBlock(pDst, pSrc, false);
×
UNCOV
1347
  if (code) {
×
1348
    return code;
×
1349
  }
1350

UNCOV
1351
  STableDataCxt* pBlock = (STableDataCxt*)*pDst;
×
UNCOV
1352
  if (pBlock->pMeta) {
×
UNCOV
1353
    pBlock->pMeta->uid = uid;
×
UNCOV
1354
    pBlock->pMeta->vgId = vgId;
×
UNCOV
1355
    pBlock->pMeta->suid = suid;
×
1356
  }
1357

UNCOV
1358
  pBlock->pData->suid = suid;
×
UNCOV
1359
  pBlock->pData->uid = uid;
×
1360

UNCOV
1361
  if (rebuildCreateTb && NULL == pBlock->pData->pCreateTbReq) {
×
UNCOV
1362
    pBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
×
UNCOV
1363
    if (NULL == pBlock->pData->pCreateTbReq) {
×
1364
      return terrno;
×
1365
    }
1366
  }
1367

UNCOV
1368
  return TSDB_CODE_SUCCESS;
×
1369
}
1370

1371
STableMeta* qGetTableMetaInDataBlock(STableDataCxt* pDataBlock) { return ((STableDataCxt*)pDataBlock)->pMeta; }
61,237✔
1372

1373
void qDestroyStmtDataBlock(STableDataCxt* pBlock) {
61,545✔
1374
  if (pBlock == NULL) {
61,545✔
1375
    return;
20,638✔
1376
  }
1377

1378
  STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
40,907✔
1379
  insDestroyTableDataCxt(pDataBlock);
40,907✔
1380
}
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