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

taosdata / TDengine / #3720

26 Mar 2025 06:20AM UTC coverage: 30.242% (-31.7%) from 61.936%
#3720

push

travis-ci

web-flow
feat(taosBenchmark): supports decimal data type (#30456)

* feat: taosBenchmark supports decimal data type

* build: decimal script not use pytest.sh

* fix: fix typo for decimal script

* test: insertBasic.py debug

71234 of 313946 branches covered (22.69%)

Branch coverage included in aggregate %.

38 of 423 new or added lines in 8 files covered. (8.98%)

120240 existing lines in 447 files now uncovered.

118188 of 312400 relevant lines covered (37.83%)

1450220.33 hits per line

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

46.99
/source/libs/parser/src/parser.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 "parser.h"
17
#include "os.h"
18

19
#include "parInt.h"
20
#include "parToken.h"
21

22
bool qIsInsertValuesSql(const char* pStr, size_t length) {
15,091,552✔
23
  if (NULL == pStr) {
15,091,552!
UNCOV
24
    return false;
×
25
  }
26

27
  const char* pSql = pStr;
15,091,552✔
28

29
  int32_t index = 0;
15,091,552✔
30
  SToken  t = tStrGetToken((char*)pStr, &index, false, NULL);
15,091,552✔
31
  if (TK_INSERT != t.type && TK_IMPORT != t.type) {
15,108,775!
32
    return false;
73,879✔
33
  }
34

35
  do {
36
    pStr += index;
45,196,737✔
37
    index = 0;
45,196,737✔
38
    t = tStrGetToken((char*)pStr, &index, false, NULL);
45,196,737✔
39
    if (TK_USING == t.type || TK_VALUES == t.type || TK_FILE == t.type) {
45,114,995!
40
      return true;
14,953,154✔
41
    } else if (TK_SELECT == t.type) {
30,161,841!
UNCOV
42
      return false;
×
43
    }
44
    if (0 == t.type || 0 == t.n) {
30,161,841!
45
      break;
46
    }
47
  } while (pStr - pSql < length);
30,172,382✔
UNCOV
48
  return false;
×
49
}
50

51
bool qIsCreateTbFromFileSql(const char* pStr, size_t length) {
36,840✔
52
  if (NULL == pStr) {
36,840!
53
    return false;
×
54
  }
55

56
  const char* pSql = pStr;
36,840✔
57

58
  int32_t index = 0;
36,840✔
59
  SToken  t = tStrGetToken((char*)pStr, &index, false, NULL);
36,840✔
60
  if (TK_CREATE != t.type) {
36,840✔
61
    return false;
35,938✔
62
  }
63

64
  do {
65
    pStr += index;
33,276✔
66
    index = 0;
33,276✔
67
    t = tStrGetToken((char*)pStr, &index, false, NULL);
33,276✔
68
    if (TK_FILE == t.type) {
33,276!
69
      return true;
×
70
    }
71
    if (0 == t.type || 0 == t.n) {
33,276✔
72
      break;
73
    }
74
  } while (pStr - pSql < length);
32,385✔
75
  return false;
902✔
76
}
77

78
bool qParseDbName(const char* pStr, size_t length, char** pDbName) {
5✔
79
  (void)length;
80
  int32_t index = 0;
5✔
81
  SToken  t;
82

83
  if (NULL == pStr) {
5!
84
    *pDbName = NULL;
×
85
    return false;
×
86
  }
87

88
  t = tStrGetToken((char*)pStr, &index, false, NULL);
5✔
89
  if (TK_INSERT != t.type && TK_IMPORT != t.type) {
5!
90
    *pDbName = NULL;
1✔
91
    return false;
1✔
92
  }
93

94
  t = tStrGetToken((char*)pStr, &index, false, NULL);
4✔
95
  if (TK_INTO != t.type) {
4!
96
    *pDbName = NULL;
×
97
    return false;
×
98
  }
99

100
  t = tStrGetToken((char*)pStr, &index, false, NULL);
4✔
101
  if (t.n == 0 || t.z == NULL) {
4!
UNCOV
102
    *pDbName = NULL;
×
UNCOV
103
    return false;
×
104
  }
105
  char* dotPos = strnchr(t.z, '.', t.n, true);
4✔
106
  if (dotPos != NULL) {
4!
UNCOV
107
    int dbNameLen = dotPos - t.z;
×
UNCOV
108
    *pDbName = taosMemoryMalloc(dbNameLen + 1);
×
UNCOV
109
    if (*pDbName == NULL) {
×
110
      return false;
×
111
    }
UNCOV
112
    strncpy(*pDbName, t.z, dbNameLen);
×
UNCOV
113
    (*pDbName)[dbNameLen] = '\0';
×
UNCOV
114
    return true;
×
115
  }
116
  return false;
4✔
117
}
118

119
static int32_t analyseSemantic(SParseContext* pCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) {
36,057✔
120
  int32_t code = authenticate(pCxt, pQuery, pMetaCache);
36,057✔
121

122
  if (pCxt->parseOnly) {
36,057✔
123
    return code;
1✔
124
  }
125

126
  if (TSDB_CODE_SUCCESS == code && pQuery->placeholderNum > 0) {
36,056✔
127
    TSWAP(pQuery->pPrepareRoot, pQuery->pRoot);
1✔
128
    return TSDB_CODE_SUCCESS;
1✔
129
  }
130

131
  if (TSDB_CODE_SUCCESS == code) {
36,055✔
132
    code = translate(pCxt, pQuery, pMetaCache);
36,050✔
133
  }
134
  if (TSDB_CODE_SUCCESS == code) {
36,057✔
135
    code = calculateConstant(pCxt, pQuery);
34,898✔
136
  }
137
  return code;
36,055✔
138
}
139

140
static int32_t parseSqlIntoAst(SParseContext* pCxt, SQuery** pQuery) {
1✔
141
  int32_t code = parse(pCxt, pQuery);
1✔
142
  if (TSDB_CODE_SUCCESS == code) {
1!
143
    code = analyseSemantic(pCxt, *pQuery, NULL);
1✔
144
  }
145
  return code;
1✔
146
}
147

148
static int32_t parseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, SParseMetaCache* pMetaCache) {
36,840✔
149
  int32_t code = parse(pCxt, pQuery);
36,840✔
150
  if (TSDB_CODE_SUCCESS == code) {
36,840✔
151
    code = collectMetaKey(pCxt, *pQuery, pMetaCache);
36,058✔
152
  }
153
  return code;
36,840✔
154
}
155

156
static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam, void *charsetCxt) {
2✔
157
  if (!pParam || IS_NULL_TYPE(pParam->buffer_type)) {
2!
158
    return TSDB_CODE_APP_ERROR;
×
159
  }
160
  if (IS_VAR_DATA_TYPE(pVal->node.resType.type)) {
2!
161
    taosMemoryFreeClear(pVal->datum.p);
×
162
  }
163

164
  if (pParam->is_null && 1 == *(pParam->is_null)) {
2!
165
    pVal->node.resType.type = TSDB_DATA_TYPE_NULL;
×
166
    pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
×
167
    return TSDB_CODE_SUCCESS;
×
168
  }
169

170
  int32_t inputSize = (NULL != pParam->length ? *(pParam->length) : tDataTypes[pParam->buffer_type].bytes);
2!
171
  pVal->node.resType.type = pParam->buffer_type;
2✔
172
  pVal->node.resType.bytes = inputSize;
2✔
173

174
  switch (pParam->buffer_type) {
2!
UNCOV
175
    case TSDB_DATA_TYPE_VARBINARY:
×
UNCOV
176
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
UNCOV
177
      if (NULL == pVal->datum.p) {
×
178
        return terrno;
×
179
      }
UNCOV
180
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
×
UNCOV
181
      memcpy(varDataVal(pVal->datum.p), pParam->buffer, pVal->node.resType.bytes);
×
UNCOV
182
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
×
UNCOV
183
      break;
×
UNCOV
184
    case TSDB_DATA_TYPE_VARCHAR:
×
185
    case TSDB_DATA_TYPE_GEOMETRY:
UNCOV
186
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
UNCOV
187
      if (NULL == pVal->datum.p) {
×
188
        return terrno;
×
189
      }
UNCOV
190
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
×
UNCOV
191
      strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes);
×
UNCOV
192
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
×
UNCOV
193
      break;
×
194
    case TSDB_DATA_TYPE_NCHAR: {
×
195
      pVal->node.resType.bytes *= TSDB_NCHAR_SIZE;
×
196
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
197
      if (NULL == pVal->datum.p) {
×
198
        return terrno;
×
199
      }
200

201
      int32_t output = 0;
×
202
      if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes,
×
203
                         &output, charsetCxt)) {
204
        return terrno;
×
205
      }
206
      varDataSetLen(pVal->datum.p, output);
×
207
      pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE;
×
208
      break;
×
209
    }
210
    default: {
2✔
211
      int32_t code = nodesSetValueNodeValue(pVal, pParam->buffer);
2✔
212
      if (code) {
2!
213
        return code;
×
214
      }
215
      break;
2✔
216
    }
217
  }
218
  pVal->translate = true;
2✔
219
  return TSDB_CODE_SUCCESS;
2✔
220
}
221

222
static EDealRes rewriteQueryExprAliasImpl(SNode* pNode, void* pContext) {
9✔
223
  if (nodesIsExprNode(pNode) && QUERY_NODE_COLUMN != nodeType(pNode)) {
9✔
224
    snprintf(((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN, "#%d", *(int32_t*)pContext);
5✔
225
    ++(*(int32_t*)pContext);
5✔
226
  }
227
  return DEAL_RES_CONTINUE;
9✔
228
}
229

230
static void rewriteQueryExprAlias(SNode* pRoot, int32_t* pNo) {
1✔
231
  switch (nodeType(pRoot)) {
1!
232
    case QUERY_NODE_SELECT_STMT:
1✔
233
      nodesWalkSelectStmt((SSelectStmt*)pRoot, SQL_CLAUSE_FROM, rewriteQueryExprAliasImpl, pNo);
1✔
234
      break;
1✔
235
    case QUERY_NODE_SET_OPERATOR: {
×
236
      SSetOperator* pSetOper = (SSetOperator*)pRoot;
×
237
      rewriteQueryExprAlias(pSetOper->pLeft, pNo);
×
238
      rewriteQueryExprAlias(pSetOper->pRight, pNo);
×
239
      break;
×
240
    }
241
    default:
×
242
      break;
×
243
  }
244
}
1✔
245

246
static void rewriteExprAlias(SNode* pRoot) {
1✔
247
  int32_t no = 1;
1✔
248
  rewriteQueryExprAlias(pRoot, &no);
1✔
249
}
1✔
250

251
int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery) {
23✔
252
  int32_t code = TSDB_CODE_SUCCESS;
23✔
253
  if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) {
23✔
254
    code = parseInsertSql(pCxt, pQuery, NULL, NULL);
22✔
255
  } else {
256
    code = parseSqlIntoAst(pCxt, pQuery);
1✔
257
  }
258
  terrno = code;
23✔
259
  return code;
23✔
260
}
261

262
static int32_t parseQuerySyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
36,840✔
263
  SParseMetaCache metaCache = {0};
36,840✔
264
  int32_t         code = parseSqlSyntax(pCxt, pQuery, &metaCache);
36,840✔
265
  if (TSDB_CODE_SUCCESS == code) {
36,840✔
266
    code = buildCatalogReq(&metaCache, pCatalogReq);
36,058✔
267
  }
268
  destoryParseMetaCache(&metaCache, true);
36,839✔
269
  return code;
36,838✔
270
}
271

272
static int32_t parseCreateTbFromFileSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
×
273
  if (NULL == *pQuery) return parseQuerySyntax(pCxt, pQuery, pCatalogReq);
×
274

275
  return continueCreateTbFromFile(pCxt, pQuery);
×
276
}
277

278
int32_t qParseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
7,560,907✔
279
  int32_t code = nodesAcquireAllocator(pCxt->allocatorId);
7,560,907✔
280
  if (TSDB_CODE_SUCCESS == code) {
7,559,534!
281
    if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) {
7,559,687✔
282
      code = parseInsertSql(pCxt, pQuery, pCatalogReq, NULL);
7,525,574✔
283
    } else if (qIsCreateTbFromFileSql(pCxt->pSql, pCxt->sqlLen)) {
39,095!
284
      code = parseCreateTbFromFileSyntax(pCxt, pQuery, pCatalogReq);
×
285
    } else {
286
      code = parseQuerySyntax(pCxt, pQuery, pCatalogReq);
36,840✔
287
    }
288
  }
289
  (void)nodesReleaseAllocator(pCxt->allocatorId);
7,436,434✔
290
  terrno = code;
7,449,910✔
291
  return code;
7,461,759✔
292
}
293

294
int32_t qAnalyseSqlSemantic(SParseContext* pCxt, const struct SCatalogReq* pCatalogReq,
36,057✔
295
                            struct SMetaData* pMetaData, SQuery* pQuery) {
296
  SParseMetaCache metaCache = {0};
36,057✔
297
  int32_t         code = nodesAcquireAllocator(pCxt->allocatorId);
36,057✔
298
  if (TSDB_CODE_SUCCESS == code && pCatalogReq) {
36,056!
299
    code = putMetaDataToCache(pCatalogReq, pMetaData, &metaCache);
36,056✔
300
  }
301
  if (TSDB_CODE_SUCCESS == code) {
36,056!
302
    code = analyseSemantic(pCxt, pQuery, &metaCache);
36,056✔
303
  }
304
  (void)nodesReleaseAllocator(pCxt->allocatorId);
36,056✔
305
  destoryParseMetaCache(&metaCache, false);
36,057✔
306
  terrno = code;
36,056✔
307
  return code;
36,057✔
308
}
309

310
int32_t qContinueParseSql(SParseContext* pCxt, struct SCatalogReq* pCatalogReq, const struct SMetaData* pMetaData,
12,591✔
311
                          SQuery* pQuery) {
312
  return parseInsertSql(pCxt, &pQuery, pCatalogReq, pMetaData);
12,591✔
313
}
314

UNCOV
315
int32_t qContinueParsePostQuery(SParseContext* pCxt, SQuery* pQuery, SSDataBlock* pBlock) {
×
UNCOV
316
  int32_t code = TSDB_CODE_SUCCESS;
×
UNCOV
317
  switch (nodeType(pQuery->pRoot)) {
×
UNCOV
318
    case QUERY_NODE_CREATE_STREAM_STMT: {
×
UNCOV
319
      code = translatePostCreateStream(pCxt, pQuery, pBlock);
×
UNCOV
320
      break;
×
321
    }
322
    case QUERY_NODE_CREATE_INDEX_STMT: {
×
323
      code = translatePostCreateSmaIndex(pCxt, pQuery, pBlock);
×
324
      break;
×
325
    }
UNCOV
326
    case QUERY_NODE_CREATE_TSMA_STMT: {
×
UNCOV
327
      code = translatePostCreateTSMA(pCxt, pQuery, pBlock);
×
UNCOV
328
      break;
×
329
    }
330
    default:
×
331
      break;
×
332
  }
333

UNCOV
334
  return code;
×
335
}
336

337
static void destoryTablesReq(void* p) {
140,842✔
338
  STablesReq* pRes = (STablesReq*)p;
140,842✔
339
  taosArrayDestroy(pRes->pTables);
140,842✔
340
}
140,842✔
341

342
void destoryCatalogReq(SCatalogReq* pCatalogReq) {
7,553,362✔
343
  if (NULL == pCatalogReq) {
7,553,362✔
344
    return;
1✔
345
  }
346
  taosArrayDestroy(pCatalogReq->pDbVgroup);
7,553,361✔
347
  taosArrayDestroy(pCatalogReq->pDbCfg);
7,553,602✔
348
  taosArrayDestroy(pCatalogReq->pDbInfo);
7,555,365✔
349
  if (pCatalogReq->cloned) {
7,557,804!
UNCOV
350
    taosArrayDestroy(pCatalogReq->pTableMeta);
×
UNCOV
351
    taosArrayDestroy(pCatalogReq->pTableHash);
×
352
#ifdef TD_ENTERPRISE
UNCOV
353
    taosArrayDestroy(pCatalogReq->pView);
×
354
#endif
UNCOV
355
    taosArrayDestroy(pCatalogReq->pTableTSMAs);
×
UNCOV
356
    taosArrayDestroy(pCatalogReq->pTSMAs);
×
UNCOV
357
    taosArrayDestroy(pCatalogReq->pTableName);
×
358
  } else {
359
    taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq);
7,557,804✔
360
    taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
7,547,707✔
361
#ifdef TD_ENTERPRISE
362
    taosArrayDestroyEx(pCatalogReq->pView, destoryTablesReq);
7,551,723✔
363
#endif
364
    taosArrayDestroyEx(pCatalogReq->pTableTSMAs, destoryTablesReq);
7,556,965✔
365
    taosArrayDestroyEx(pCatalogReq->pTSMAs, destoryTablesReq);
7,559,638✔
366
    taosArrayDestroyEx(pCatalogReq->pTableName, destoryTablesReq);
7,555,307✔
367
  }
368
  taosArrayDestroy(pCatalogReq->pUdf);
7,554,149✔
369
  taosArrayDestroy(pCatalogReq->pIndex);
7,552,700✔
370
  taosArrayDestroy(pCatalogReq->pUser);
7,552,811✔
371
  taosArrayDestroy(pCatalogReq->pTableIndex);
7,552,309✔
372
  taosArrayDestroy(pCatalogReq->pTableCfg);
7,551,316✔
373
  taosArrayDestroy(pCatalogReq->pTableTag);
7,551,636✔
374
  taosArrayDestroy(pCatalogReq->pVSubTable);
7,551,923✔
375
}
376

377
void tfreeSParseQueryRes(void* p) {
1✔
378
  if (NULL == p) {
1!
379
    return;
×
380
  }
381

382
  SParseQueryRes* pRes = p;
1✔
383
  destoryCatalogReq(pRes->pCatalogReq);
1✔
384
  taosMemoryFree(pRes->pCatalogReq);
1!
385
  catalogFreeMetaData(&pRes->meta);
1✔
386
}
387

388
void qDestroyParseContext(SParseContext* pCxt) {
7,564,460✔
389
  if (NULL == pCxt) {
7,564,460!
390
    return;
×
391
  }
392

393
  taosArrayDestroyEx(pCxt->pSubMetaList, tfreeSParseQueryRes);
7,564,460✔
394
  taosArrayDestroy(pCxt->pTableMetaPos);
7,565,932✔
395
  taosArrayDestroy(pCxt->pTableVgroupPos);
7,563,884✔
396
  taosMemoryFree(pCxt);
7,562,861!
397
}
398

399
void qDestroyQuery(SQuery* pQueryNode) { nodesDestroyNode((SNode*)pQueryNode); }
7,576,562✔
400

401
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) {
9✔
402
  return extractResultSchema(pRoot, numOfCols, pSchema, NULL);
9✔
403
}
404

UNCOV
405
int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid) {
×
UNCOV
406
  if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
×
UNCOV
407
    SNode* pTable = ((SSelectStmt*)pStmt)->pFromTable;
×
UNCOV
408
    if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
×
UNCOV
409
      ((SRealTableNode*)pTable)->pMeta->uid = uid;
×
UNCOV
410
      ((SRealTableNode*)pTable)->pMeta->suid = uid;
×
UNCOV
411
      return TSDB_CODE_SUCCESS;
×
412
    }
413
  }
414
  return TSDB_CODE_FAILED;
×
415
}
416

417
int32_t qInitKeywordsTable() { return taosInitKeywordsTable(); }
104✔
418

419
void qCleanupKeywordsTable() { taosCleanupKeywordsTable(); }
104✔
420

421
int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx, void *charsetCxt) {
1✔
422
  int32_t code = TSDB_CODE_SUCCESS;
1✔
423

424
  if (colIdx < 0) {
1!
425
    int32_t size = taosArrayGetSize(pQuery->pPlaceholderValues);
1✔
426
    for (int32_t i = 0; i < size; ++i) {
3✔
427
      code = setValueByBindParam((SValueNode*)taosArrayGetP(pQuery->pPlaceholderValues, i), pParams + i, charsetCxt);
2✔
428
      if (TSDB_CODE_SUCCESS != code) {
2!
429
        return code;
×
430
      }
431
    }
432
  } else {
UNCOV
433
    code = setValueByBindParam((SValueNode*)taosArrayGetP(pQuery->pPlaceholderValues, colIdx), pParams, charsetCxt);
×
434
  }
435

436
  if (TSDB_CODE_SUCCESS == code && (colIdx < 0 || colIdx + 1 == pQuery->placeholderNum)) {
1!
437
    nodesDestroyNode(pQuery->pRoot);
1✔
438
    pQuery->pRoot = NULL;
1✔
439
    code = nodesCloneNode(pQuery->pPrepareRoot, &pQuery->pRoot);
1✔
440
  }
441
  if (TSDB_CODE_SUCCESS == code) {
1!
442
    rewriteExprAlias(pQuery->pRoot);
1✔
443
  }
444
  return code;
1✔
445
}
446

UNCOV
447
static int32_t setValueByBindParam2(SValueNode* pVal, TAOS_STMT2_BIND* pParam, void* charsetCxt) {
×
UNCOV
448
  if (!pParam || IS_NULL_TYPE(pParam->buffer_type)) {
×
449
    return TSDB_CODE_APP_ERROR;
×
450
  }
UNCOV
451
  if (IS_VAR_DATA_TYPE(pVal->node.resType.type)) {
×
452
    taosMemoryFreeClear(pVal->datum.p);
×
453
  }
454

UNCOV
455
  if (pParam->is_null && 1 == *(pParam->is_null)) {
×
456
    pVal->node.resType.type = TSDB_DATA_TYPE_NULL;
×
457
    pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
×
458
    return TSDB_CODE_SUCCESS;
×
459
  }
460

UNCOV
461
  int32_t inputSize = (NULL != pParam->length ? *(pParam->length) : tDataTypes[pParam->buffer_type].bytes);
×
UNCOV
462
  pVal->node.resType.type = pParam->buffer_type;
×
UNCOV
463
  pVal->node.resType.bytes = inputSize;
×
464

UNCOV
465
  switch (pParam->buffer_type) {
×
466
    case TSDB_DATA_TYPE_VARBINARY:
×
467
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
468
      if (NULL == pVal->datum.p) {
×
469
        return terrno;
×
470
      }
471
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
×
472
      memcpy(varDataVal(pVal->datum.p), pParam->buffer, pVal->node.resType.bytes);
×
473
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
×
474
      break;
×
475
    case TSDB_DATA_TYPE_VARCHAR:
×
476
    case TSDB_DATA_TYPE_GEOMETRY:
477
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
478
      if (NULL == pVal->datum.p) {
×
479
        return terrno;
×
480
      }
481
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
×
482
      strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes);
×
483
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
×
484
      break;
×
485
    case TSDB_DATA_TYPE_NCHAR: {
×
486
      pVal->node.resType.bytes *= TSDB_NCHAR_SIZE;
×
487
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
488
      if (NULL == pVal->datum.p) {
×
489
        return terrno;
×
490
      }
491

492
      int32_t output = 0;
×
493
      if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes,
×
494
                         &output, charsetCxt)) {
495
        return terrno;
×
496
      }
497
      varDataSetLen(pVal->datum.p, output);
×
498
      pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE;
×
499
      break;
×
500
    }
UNCOV
501
    default: {
×
UNCOV
502
      int32_t code = nodesSetValueNodeValue(pVal, pParam->buffer);
×
UNCOV
503
      if (code) {
×
504
        return code;
×
505
      }
UNCOV
506
      break;
×
507
    }
508
  }
UNCOV
509
  pVal->translate = true;
×
UNCOV
510
  return TSDB_CODE_SUCCESS;
×
511
}
512

UNCOV
513
int32_t qStmtBindParams2(SQuery* pQuery, TAOS_STMT2_BIND* pParams, int32_t colIdx, void* charsetCxt) {
×
UNCOV
514
  int32_t code = TSDB_CODE_SUCCESS;
×
515

UNCOV
516
  if (colIdx < 0) {
×
UNCOV
517
    int32_t size = taosArrayGetSize(pQuery->pPlaceholderValues);
×
UNCOV
518
    for (int32_t i = 0; i < size; ++i) {
×
UNCOV
519
      code = setValueByBindParam2((SValueNode*)taosArrayGetP(pQuery->pPlaceholderValues, i), pParams + i, charsetCxt);
×
UNCOV
520
      if (TSDB_CODE_SUCCESS != code) {
×
521
        return code;
×
522
      }
523
    }
524
  } else {
525
    code = setValueByBindParam2((SValueNode*)taosArrayGetP(pQuery->pPlaceholderValues, colIdx), pParams, charsetCxt);
×
526
  }
527

UNCOV
528
  if (TSDB_CODE_SUCCESS == code && (colIdx < 0 || colIdx + 1 == pQuery->placeholderNum)) {
×
UNCOV
529
    nodesDestroyNode(pQuery->pRoot);
×
UNCOV
530
    pQuery->pRoot = NULL;
×
UNCOV
531
    code = nodesCloneNode(pQuery->pPrepareRoot, &pQuery->pRoot);
×
532
  }
UNCOV
533
  if (TSDB_CODE_SUCCESS == code) {
×
UNCOV
534
    rewriteExprAlias(pQuery->pRoot);
×
535
  }
UNCOV
536
  return code;
×
537
}
538

539
int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery) {
1✔
540
  int32_t code = translate(pCxt, pQuery, NULL);
1✔
541
  if (TSDB_CODE_SUCCESS == code) {
1!
542
    code = calculateConstant(pCxt, pQuery);
1✔
543
  }
544
  return code;
1✔
545
}
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