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

taosdata / TDengine / #3533

20 Nov 2024 07:11AM UTC coverage: 58.848% (-1.9%) from 60.78%
#3533

push

travis-ci

web-flow
Merge pull request #28823 from taosdata/fix/3.0/TD-32587

fix:[TD-32587]fix stmt segmentation fault

115578 of 252434 branches covered (45.79%)

Branch coverage included in aggregate %.

1 of 4 new or added lines in 1 file covered. (25.0%)

8038 existing lines in 233 files now uncovered.

194926 of 275199 relevant lines covered (70.83%)

1494459.59 hits per line

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

58.17
/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) {
2,727,405✔
23
  if (NULL == pStr) {
2,727,405!
24
    return false;
×
25
  }
26

27
  const char* pSql = pStr;
2,727,405✔
28

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

35
  do {
36
    pStr += index;
9,343,788✔
37
    index = 0;
9,343,788✔
38
    t = tStrGetToken((char*)pStr, &index, false, NULL);
9,343,788✔
39
    if (TK_USING == t.type || TK_VALUES == t.type || TK_FILE == t.type) {
9,343,789✔
40
      return true;
1,795,737✔
41
    } else if (TK_SELECT == t.type) {
7,548,052✔
42
      return false;
218✔
43
    }
44
    if (0 == t.type || 0 == t.n) {
7,547,834!
45
      break;
46
    }
47
  } while (pStr - pSql < length);
7,547,831✔
48
  return false;
4✔
49
}
50

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

56
  const char* pSql = pStr;
468,686✔
57

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

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

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

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

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

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

100
  t = tStrGetToken((char*)pStr, &index, false, NULL);
27✔
101
  if (t.n == 0 || t.z == NULL) {
27!
102
    *pDbName = NULL;
×
103
    return false;
×
104
  }
105
  char* dotPos = strnchr(t.z, '.', t.n, true);
27✔
106
  if (dotPos != NULL) {
27!
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;
27✔
117
}
118

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

122
  if (pCxt->parseOnly) {
449,969✔
123
    return code;
449✔
124
  }
125

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

131
  if (TSDB_CODE_SUCCESS == code) {
449,506✔
132
    code = translate(pCxt, pQuery, pMetaCache);
449,339✔
133
  }
134
  if (TSDB_CODE_SUCCESS == code) {
449,504✔
135
    code = calculateConstant(pCxt, pQuery);
382,857✔
136
  }
137
  return code;
449,500✔
138
}
139

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

148
static int32_t parseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, SParseMetaCache* pMetaCache) {
468,686✔
149
  int32_t code = parse(pCxt, pQuery);
468,686✔
150
  if (TSDB_CODE_SUCCESS == code) {
468,685✔
151
    code = collectMetaKey(pCxt, *pQuery, pMetaCache);
449,670✔
152
  }
153
  return code;
468,689✔
154
}
155

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

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

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

174
  switch (pParam->buffer_type) {
15!
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) {
×
UNCOV
178
        return terrno;
×
179
      }
UNCOV
180
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
×
181
      memcpy(varDataVal(pVal->datum.p), pParam->buffer, pVal->node.resType.bytes);
×
UNCOV
182
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
×
UNCOV
183
      break;
×
184
    case TSDB_DATA_TYPE_VARCHAR:
5✔
185
    case TSDB_DATA_TYPE_GEOMETRY:
186
      pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
5✔
187
      if (NULL == pVal->datum.p) {
5!
UNCOV
188
        return terrno;
×
189
      }
190
      varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
5✔
191
      strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes);
5✔
192
      pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
5✔
193
      break;
5✔
UNCOV
194
    case TSDB_DATA_TYPE_NCHAR: {
×
UNCOV
195
      pVal->node.resType.bytes *= TSDB_NCHAR_SIZE;
×
UNCOV
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;
×
UNCOV
202
      if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes,
×
203
                         &output)) {
204
        return terrno;
×
205
      }
UNCOV
206
      varDataSetLen(pVal->datum.p, output);
×
207
      pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE;
×
UNCOV
208
      break;
×
209
    }
210
    default: {
10✔
211
      int32_t code = nodesSetValueNodeValue(pVal, pParam->buffer);
10✔
212
      if (code) {
10!
UNCOV
213
        return code;
×
214
      }
215
      break;
10✔
216
    }
217
  }
218
  pVal->translate = true;
15✔
219
  return TSDB_CODE_SUCCESS;
15✔
220
}
221

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

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

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

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

262
static int32_t parseQuerySyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
468,688✔
263
  SParseMetaCache metaCache = {0};
468,688✔
264
  int32_t         code = parseSqlSyntax(pCxt, pQuery, &metaCache);
468,688✔
265
  if (TSDB_CODE_SUCCESS == code) {
468,689✔
266
    code = buildCatalogReq(&metaCache, pCatalogReq);
449,672✔
267
  }
268
  destoryParseMetaCache(&metaCache, true);
468,690✔
269
  return code;
468,686✔
270
}
271

UNCOV
272
static int32_t parseCreateTbFromFileSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
×
UNCOV
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) {
1,366,570✔
279
  int32_t code = nodesAcquireAllocator(pCxt->allocatorId);
1,366,570✔
280
  if (TSDB_CODE_SUCCESS == code) {
1,366,575!
281
    if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) {
1,366,577✔
282
      code = parseInsertSql(pCxt, pQuery, pCatalogReq, NULL);
897,886✔
283
    } else if (qIsCreateTbFromFileSql(pCxt->pSql, pCxt->sqlLen)) {
468,690!
UNCOV
284
      code = parseCreateTbFromFileSyntax(pCxt, pQuery, pCatalogReq);
×
285
    } else {
286
      code = parseQuerySyntax(pCxt, pQuery, pCatalogReq);
468,689✔
287
    }
288
  }
289
  (void)nodesReleaseAllocator(pCxt->allocatorId);
1,366,567✔
290
  terrno = code;
1,366,569✔
291
  return code;
1,366,568✔
292
}
293

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

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

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

334
  return code;
264✔
335
}
336

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

342
void destoryCatalogReq(SCatalogReq* pCatalogReq) {
1,367,292✔
343
  if (NULL == pCatalogReq) {
1,367,292✔
344
    return;
449✔
345
  }
346
  taosArrayDestroy(pCatalogReq->pDbVgroup);
1,366,843✔
347
  taosArrayDestroy(pCatalogReq->pDbCfg);
1,366,844✔
348
  taosArrayDestroy(pCatalogReq->pDbInfo);
1,366,840✔
349
  if (pCatalogReq->cloned) {
1,366,839✔
350
    taosArrayDestroy(pCatalogReq->pTableMeta);
286✔
351
    taosArrayDestroy(pCatalogReq->pTableHash);
286✔
352
#ifdef TD_ENTERPRISE
353
    taosArrayDestroy(pCatalogReq->pView);
286✔
354
#endif
355
    taosArrayDestroy(pCatalogReq->pTableTSMAs);
286✔
356
    taosArrayDestroy(pCatalogReq->pTSMAs);
286✔
357
    taosArrayDestroy(pCatalogReq->pTableName);
286✔
358
  } else {
359
    taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq);
1,366,553✔
360
    taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
1,366,557✔
361
#ifdef TD_ENTERPRISE
362
    taosArrayDestroyEx(pCatalogReq->pView, destoryTablesReq);
1,366,557✔
363
#endif
364
    taosArrayDestroyEx(pCatalogReq->pTableTSMAs, destoryTablesReq);
1,366,558✔
365
    taosArrayDestroyEx(pCatalogReq->pTSMAs, destoryTablesReq);
1,366,557✔
366
    taosArrayDestroyEx(pCatalogReq->pTableName, destoryTablesReq);
1,366,555✔
367
  }
368
  taosArrayDestroy(pCatalogReq->pUdf);
1,366,841✔
369
  taosArrayDestroy(pCatalogReq->pIndex);
1,366,841✔
370
  taosArrayDestroy(pCatalogReq->pUser);
1,366,841✔
371
  taosArrayDestroy(pCatalogReq->pTableIndex);
1,366,841✔
372
  taosArrayDestroy(pCatalogReq->pTableCfg);
1,366,841✔
373
  taosArrayDestroy(pCatalogReq->pTableTag);
1,366,841✔
374
}
375

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

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

387
void qDestroyParseContext(SParseContext* pCxt) {
1,366,841✔
388
  if (NULL == pCxt) {
1,366,841!
UNCOV
389
    return;
×
390
  }
391

392
  taosArrayDestroyEx(pCxt->pSubMetaList, tfreeSParseQueryRes);
1,366,841✔
393
  taosArrayDestroy(pCxt->pTableMetaPos);
1,366,841✔
394
  taosArrayDestroy(pCxt->pTableVgroupPos);
1,366,841✔
395
  taosMemoryFree(pCxt);
1,366,839✔
396
}
397

398
void qDestroyQuery(SQuery* pQueryNode) { nodesDestroyNode((SNode*)pQueryNode); }
1,464,378✔
399

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

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

416
int32_t qInitKeywordsTable() { return taosInitKeywordsTable(); }
1,602✔
417

418
void qCleanupKeywordsTable() { taosCleanupKeywordsTable(); }
1,602✔
419

420
int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx) {
14✔
421
  int32_t code = TSDB_CODE_SUCCESS;
14✔
422

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

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

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

454
  if (pParam->is_null && 1 == *(pParam->is_null)) {
×
UNCOV
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

UNCOV
464
  switch (pParam->buffer_type) {
×
UNCOV
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);
×
UNCOV
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: {
×
UNCOV
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)) {
494
        return terrno;
×
495
      }
UNCOV
496
      varDataSetLen(pVal->datum.p, output);
×
497
      pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE;
×
498
      break;
×
499
    }
500
    default: {
×
UNCOV
501
      int32_t code = nodesSetValueNodeValue(pVal, pParam->buffer);
×
502
      if (code) {
×
503
        return code;
×
504
      }
UNCOV
505
      break;
×
506
    }
507
  }
508
  pVal->translate = true;
×
509
  return TSDB_CODE_SUCCESS;
×
510
}
511

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

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

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

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