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

taosdata / TDengine / #3599

08 Feb 2025 11:23AM UTC coverage: 1.77% (-61.6%) from 63.396%
#3599

push

travis-ci

web-flow
Merge pull request #29712 from taosdata/fix/TD-33652-3.0

fix: reduce write rows from 30w to 3w

3776 of 278949 branches covered (1.35%)

Branch coverage included in aggregate %.

6012 of 274147 relevant lines covered (2.19%)

1642.73 hits per line

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

0.0
/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) {
×
23
  if (NULL == pStr) {
×
24
    return false;
×
25
  }
26

27
  const char* pSql = pStr;
×
28

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

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

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

56
  const char* pSql = pStr;
×
57

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

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

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

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

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

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

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

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

122
  if (pCxt->parseOnly) {
×
123
    return code;
×
124
  }
125

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

131
  if (TSDB_CODE_SUCCESS == code) {
×
132
    code = translate(pCxt, pQuery, pMetaCache);
×
133
  }
134
  if (TSDB_CODE_SUCCESS == code) {
×
135
    code = calculateConstant(pCxt, pQuery);
×
136
  }
137
  return code;
×
138
}
139

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

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

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

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

174
  switch (pParam->buffer_type) {
×
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:
×
185
    case TSDB_DATA_TYPE_GEOMETRY:
186
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
×
187
      if (NULL == pVal->datum.p) {
×
188
        return terrno;
×
189
      }
190
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
×
191
      strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes);
×
192
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
×
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: {
×
211
      int32_t code = nodesSetValueNodeValue(pVal, pParam->buffer);
×
212
      if (code) {
×
213
        return code;
×
214
      }
215
      break;
×
216
    }
217
  }
218
  pVal->translate = true;
×
219
  return TSDB_CODE_SUCCESS;
×
220
}
221

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

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

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

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

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

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

310
int32_t qContinueParseSql(SParseContext* pCxt, struct SCatalogReq* pCatalogReq, const struct SMetaData* pMetaData,
×
311
                          SQuery* pQuery) {
312
  return parseInsertSql(pCxt, &pQuery, pCatalogReq, pMetaData);
×
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) {
×
338
  STablesReq* pRes = (STablesReq*)p;
×
339
  taosArrayDestroy(pRes->pTables);
×
340
}
×
341

342
void destoryCatalogReq(SCatalogReq* pCatalogReq) {
×
343
  if (NULL == pCatalogReq) {
×
344
    return;
×
345
  }
346
  taosArrayDestroy(pCatalogReq->pDbVgroup);
×
347
  taosArrayDestroy(pCatalogReq->pDbCfg);
×
348
  taosArrayDestroy(pCatalogReq->pDbInfo);
×
349
  if (pCatalogReq->cloned) {
×
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);
×
360
    taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
×
361
#ifdef TD_ENTERPRISE
362
    taosArrayDestroyEx(pCatalogReq->pView, destoryTablesReq);
×
363
#endif
364
    taosArrayDestroyEx(pCatalogReq->pTableTSMAs, destoryTablesReq);
×
365
    taosArrayDestroyEx(pCatalogReq->pTSMAs, destoryTablesReq);
×
366
    taosArrayDestroyEx(pCatalogReq->pTableName, destoryTablesReq);
×
367
  }
368
  taosArrayDestroy(pCatalogReq->pUdf);
×
369
  taosArrayDestroy(pCatalogReq->pIndex);
×
370
  taosArrayDestroy(pCatalogReq->pUser);
×
371
  taosArrayDestroy(pCatalogReq->pTableIndex);
×
372
  taosArrayDestroy(pCatalogReq->pTableCfg);
×
373
  taosArrayDestroy(pCatalogReq->pTableTag);
×
374
}
375

376
void tfreeSParseQueryRes(void* p) {
×
377
  if (NULL == p) {
×
378
    return;
×
379
  }
380

381
  SParseQueryRes* pRes = p;
×
382
  destoryCatalogReq(pRes->pCatalogReq);
×
383
  taosMemoryFree(pRes->pCatalogReq);
×
384
  catalogFreeMetaData(&pRes->meta);
×
385
}
386

387
void qDestroyParseContext(SParseContext* pCxt) {
×
388
  if (NULL == pCxt) {
×
389
    return;
×
390
  }
391

392
  taosArrayDestroyEx(pCxt->pSubMetaList, tfreeSParseQueryRes);
×
393
  taosArrayDestroy(pCxt->pTableMetaPos);
×
394
  taosArrayDestroy(pCxt->pTableVgroupPos);
×
395
  taosMemoryFree(pCxt);
×
396
}
397

398
void qDestroyQuery(SQuery* pQueryNode) { nodesDestroyNode((SNode*)pQueryNode); }
×
399

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

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

416
int32_t qInitKeywordsTable() { return taosInitKeywordsTable(); }
×
417

418
void qCleanupKeywordsTable() { taosCleanupKeywordsTable(); }
×
419

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

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

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

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

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

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

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

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

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

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

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

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