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

taosdata / TDengine / #3796

31 Mar 2025 10:39AM UTC coverage: 30.372% (-7.1%) from 37.443%
#3796

push

travis-ci

happyguoxy
test:add test cases

69287 of 309062 branches covered (22.42%)

Branch coverage included in aggregate %.

118044 of 307720 relevant lines covered (38.36%)

278592.15 hits per line

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

60.37
/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) {
24,653✔
23
  if (NULL == pStr) {
24,653✔
24
    return false;
1✔
25
  }
26

27
  const char* pSql = pStr;
24,652✔
28

29
  int32_t index = 0;
24,652✔
30
  SToken  t = tStrGetToken((char*)pStr, &index, false, NULL);
24,652✔
31
  if (TK_INSERT != t.type && TK_IMPORT != t.type) {
24,652!
32
    return false;
18,610✔
33
  }
34

35
  do {
36
    pStr += index;
19,002✔
37
    index = 0;
19,002✔
38
    t = tStrGetToken((char*)pStr, &index, false, NULL);
19,002✔
39
    if (TK_USING == t.type || TK_VALUES == t.type || TK_FILE == t.type) {
19,002✔
40
      return true;
6,020✔
41
    } else if (TK_SELECT == t.type) {
12,982✔
42
      return false;
7✔
43
    }
44
    if (0 == t.type || 0 == t.n) {
12,975✔
45
      break;
46
    }
47
  } while (pStr - pSql < length);
12,960!
48
  return false;
15✔
49
}
50

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

56
  const char* pSql = pStr;
8,647✔
57

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

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

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

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

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

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

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

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

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

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

131
  if (TSDB_CODE_SUCCESS == code) {
9,323✔
132
    code = translate(pCxt, pQuery, pMetaCache);
9,154✔
133
  }
134
  if (TSDB_CODE_SUCCESS == code) {
9,323✔
135
    code = calculateConstant(pCxt, pQuery);
8,898✔
136
  }
137
  return code;
9,323✔
138
}
139

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

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

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

164
  if (pParam->is_null && 1 == *(pParam->is_null)) {
10!
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);
10!
171
  pVal->node.resType.type = pParam->buffer_type;
10✔
172
  pVal->node.resType.bytes = inputSize;
10✔
173

174
  switch (pParam->buffer_type) {
10!
175
    case TSDB_DATA_TYPE_VARBINARY:
×
176
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
177
      if (NULL == pVal->datum.p) {
×
178
        return terrno;
×
179
      }
180
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
×
181
      memcpy(varDataVal(pVal->datum.p), pParam->buffer, pVal->node.resType.bytes);
×
182
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
×
183
      break;
×
184
    case TSDB_DATA_TYPE_VARCHAR:
1✔
185
    case TSDB_DATA_TYPE_GEOMETRY:
186
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
1!
187
      if (NULL == pVal->datum.p) {
1!
188
        return terrno;
×
189
      }
190
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
1✔
191
      strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes);
1✔
192
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
1✔
193
      break;
1✔
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: {
9✔
211
      int32_t code = nodesSetValueNodeValue(pVal, pParam->buffer);
9✔
212
      if (code) {
9!
213
        return code;
×
214
      }
215
      break;
9✔
216
    }
217
  }
218
  pVal->translate = true;
10✔
219
  return TSDB_CODE_SUCCESS;
10✔
220
}
221

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

230
static void rewriteQueryExprAlias(SNode* pRoot, int32_t* pNo) {
10✔
231
  switch (nodeType(pRoot)) {
10!
232
    case QUERY_NODE_SELECT_STMT:
10✔
233
      nodesWalkSelectStmt((SSelectStmt*)pRoot, SQL_CLAUSE_FROM, rewriteQueryExprAliasImpl, pNo);
10✔
234
      break;
10✔
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
}
10✔
245

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

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

262
static int32_t parseQuerySyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
8,647✔
263
  SParseMetaCache metaCache = {0};
8,647✔
264
  int32_t         code = parseSqlSyntax(pCxt, pQuery, &metaCache);
8,647✔
265
  if (TSDB_CODE_SUCCESS == code) {
8,647✔
266
    code = buildCatalogReq(&metaCache, pCatalogReq);
8,633✔
267
  }
268
  destoryParseMetaCache(&metaCache, true);
8,647✔
269
  return code;
8,647✔
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) {
11,502✔
279
  int32_t code = nodesAcquireAllocator(pCxt->allocatorId);
11,502✔
280
  if (TSDB_CODE_SUCCESS == code) {
11,502!
281
    if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) {
11,502✔
282
      code = parseInsertSql(pCxt, pQuery, pCatalogReq, NULL);
2,855✔
283
    } else if (qIsCreateTbFromFileSql(pCxt->pSql, pCxt->sqlLen)) {
8,647!
284
      code = parseCreateTbFromFileSyntax(pCxt, pQuery, pCatalogReq);
×
285
    } else {
286
      code = parseQuerySyntax(pCxt, pQuery, pCatalogReq);
8,647✔
287
    }
288
  }
289
  (void)nodesReleaseAllocator(pCxt->allocatorId);
11,502✔
290
  terrno = code;
11,502✔
291
  return code;
11,502✔
292
}
293

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

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

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

334
  return code;
×
335
}
336

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

342
void destoryCatalogReq(SCatalogReq* pCatalogReq) {
11,088✔
343
  if (NULL == pCatalogReq) {
11,088✔
344
    return;
13✔
345
  }
346
  taosArrayDestroy(pCatalogReq->pDbVgroup);
11,075✔
347
  taosArrayDestroy(pCatalogReq->pDbCfg);
11,075✔
348
  taosArrayDestroy(pCatalogReq->pDbInfo);
11,075✔
349
  if (pCatalogReq->cloned) {
11,075!
350
    taosArrayDestroy(pCatalogReq->pTableMeta);
×
351
    taosArrayDestroy(pCatalogReq->pTableHash);
×
352
#ifdef TD_ENTERPRISE
353
    taosArrayDestroy(pCatalogReq->pView);
×
354
#endif
355
    taosArrayDestroy(pCatalogReq->pTableTSMAs);
×
356
    taosArrayDestroy(pCatalogReq->pTSMAs);
×
357
    taosArrayDestroy(pCatalogReq->pTableName);
×
358
  } else {
359
    taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq);
11,075✔
360
    taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
11,075✔
361
#ifdef TD_ENTERPRISE
362
    taosArrayDestroyEx(pCatalogReq->pView, destoryTablesReq);
11,075✔
363
#endif
364
    taosArrayDestroyEx(pCatalogReq->pTableTSMAs, destoryTablesReq);
11,075✔
365
    taosArrayDestroyEx(pCatalogReq->pTSMAs, destoryTablesReq);
11,075✔
366
    taosArrayDestroyEx(pCatalogReq->pTableName, destoryTablesReq);
11,075✔
367
  }
368
  taosArrayDestroy(pCatalogReq->pUdf);
11,075✔
369
  taosArrayDestroy(pCatalogReq->pIndex);
11,075✔
370
  taosArrayDestroy(pCatalogReq->pUser);
11,075✔
371
  taosArrayDestroy(pCatalogReq->pTableIndex);
11,075✔
372
  taosArrayDestroy(pCatalogReq->pTableCfg);
11,075✔
373
  taosArrayDestroy(pCatalogReq->pTableTag);
11,075✔
374
  taosArrayDestroy(pCatalogReq->pVSubTable);
11,075✔
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) {
11,087✔
389
  if (NULL == pCxt) {
11,087!
390
    return;
×
391
  }
392

393
  taosArrayDestroyEx(pCxt->pSubMetaList, tfreeSParseQueryRes);
11,087✔
394
  taosArrayDestroy(pCxt->pTableMetaPos);
11,087✔
395
  taosArrayDestroy(pCxt->pTableVgroupPos);
11,087✔
396
  taosMemoryFree(pCxt);
11,087!
397
}
398

399
void qDestroyQuery(SQuery* pQueryNode) { nodesDestroyNode((SNode*)pQueryNode); }
14,456✔
400

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

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

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

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

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

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

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

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

455
  if (pParam->is_null && 1 == *(pParam->is_null)) {
5!
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

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

465
  switch (pParam->buffer_type) {
5!
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
    }
501
    default: {
5✔
502
      int32_t code = nodesSetValueNodeValue(pVal, pParam->buffer);
5✔
503
      if (code) {
5!
504
        return code;
×
505
      }
506
      break;
5✔
507
    }
508
  }
509
  pVal->translate = true;
5✔
510
  return TSDB_CODE_SUCCESS;
5✔
511
}
512

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

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

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

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