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

taosdata / TDengine / #3929

25 Apr 2025 11:21AM UTC coverage: 62.507% (+0.1%) from 62.362%
#3929

push

travis-ci

web-flow
docs: jdbc tmq supports database subscription. [TS-6222] (#30819)

* docs: jdbc tmq supports database subscription. [TS-6222]

* Update docs/zh/07-develop/07-tmq.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update 07-tmq.md

---------

Co-authored-by: haoranchen <haoran920c@163.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

155520 of 317319 branches covered (49.01%)

Branch coverage included in aggregate %.

240651 of 316482 relevant lines covered (76.04%)

6469891.78 hits per line

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

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

27
  const char* pSql = pStr;
6,090,379✔
28

29
  int32_t index = 0;
6,090,379✔
30
  SToken  t = tStrGetToken((char*)pStr, &index, false, NULL);
6,090,379✔
31
  if (TK_INSERT != t.type && TK_IMPORT != t.type) {
6,090,535✔
32
    return false;
2,466,404✔
33
  }
34

35
  do {
36
    pStr += index;
30,958,368✔
37
    index = 0;
30,958,368✔
38
    t = tStrGetToken((char*)pStr, &index, false, NULL);
30,958,368✔
39
    if (TK_USING == t.type || TK_VALUES == t.type || TK_FILE == t.type) {
30,958,332✔
40
      return true;
3,623,795✔
41
    } else if (TK_SELECT == t.type) {
27,334,537✔
42
      return false;
261✔
43
    }
44
    if (0 == t.type || 0 == t.n) {
27,334,276✔
45
      break;
46
    }
47
  } while (pStr - pSql < length);
27,334,240✔
48
  return false;
39✔
49
}
50

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

56
  const char* pSql = pStr;
1,236,876✔
57

58
  int32_t index = 0;
1,236,876✔
59
  SToken  t = tStrGetToken((char*)pStr, &index, false, NULL);
1,236,876✔
60
  if (TK_CREATE != t.type) {
1,236,935✔
61
    return false;
1,112,263✔
62
  }
63

64
  do {
65
    pStr += index;
3,588,834✔
66
    index = 0;
3,588,834✔
67
    t = tStrGetToken((char*)pStr, &index, false, NULL);
3,588,834✔
68
    if (TK_FILE == t.type) {
3,588,829✔
69
      return true;
4✔
70
    }
71
    if (0 == t.type || 0 == t.n) {
3,588,825✔
72
      break;
73
    }
74
  } while (pStr - pSql < length);
3,464,262✔
75
  return false;
124,663✔
76
}
77

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

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

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

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

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

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

122
  if (pCxt->parseOnly) {
1,205,083✔
123
    return code;
638✔
124
  }
125

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

131
  if (TSDB_CODE_SUCCESS == code) {
1,204,418✔
132
    code = translate(pCxt, pQuery, pMetaCache);
1,204,038✔
133
  }
134
  if (TSDB_CODE_SUCCESS == code) {
1,204,408✔
135
    code = calculateConstant(pCxt, pQuery);
1,105,060✔
136
  }
137
  return code;
1,204,375✔
138
}
139

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

148
static int32_t parseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, SParseMetaCache* pMetaCache) {
1,236,831✔
149
  int32_t code = parse(pCxt, pQuery);
1,236,831✔
150
  if (TSDB_CODE_SUCCESS == code) {
1,236,823✔
151
    code = collectMetaKey(pCxt, *pQuery, pMetaCache);
1,203,881✔
152
  }
153
  return code;
1,236,888✔
154
}
155

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

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

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

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

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

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

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

262
static int32_t parseQuerySyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
1,236,847✔
263
  SParseMetaCache metaCache = {0};
1,236,847✔
264
  int32_t         code = parseSqlSyntax(pCxt, pQuery, &metaCache);
1,236,847✔
265
  if (TSDB_CODE_SUCCESS == code) {
1,236,862✔
266
    code = buildCatalogReq(&metaCache, pCatalogReq);
1,203,923✔
267
  }
268
  destoryParseMetaCache(&metaCache, true);
1,236,875✔
269
  return code;
1,236,894✔
270
}
271

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

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

278
int32_t qParseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) {
3,007,306✔
279
  int32_t code = nodesAcquireAllocator(pCxt->allocatorId);
3,007,306✔
280
  if (TSDB_CODE_SUCCESS == code) {
3,007,414!
281
    if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) {
3,007,427✔
282
      code = parseInsertSql(pCxt, pQuery, pCatalogReq, NULL);
1,770,610✔
283
    } else if (qIsCreateTbFromFileSql(pCxt->pSql, pCxt->sqlLen)) {
1,236,933✔
284
      code = parseCreateTbFromFileSyntax(pCxt, pQuery, pCatalogReq);
4✔
285
    } else {
286
      code = parseQuerySyntax(pCxt, pQuery, pCatalogReq);
1,236,922✔
287
    }
288
  }
289
  (void)nodesReleaseAllocator(pCxt->allocatorId);
3,007,170✔
290
  terrno = code;
3,007,205✔
291
  return code;
3,007,308✔
292
}
293

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

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

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

334
  return code;
436✔
335
}
336

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

342
void destoryCatalogReq(SCatalogReq* pCatalogReq) {
3,008,128✔
343
  if (NULL == pCatalogReq) {
3,008,128✔
344
    return;
650✔
345
  }
346
  taosArrayDestroy(pCatalogReq->pDbVgroup);
3,007,478✔
347
  taosArrayDestroy(pCatalogReq->pDbCfg);
3,007,466✔
348
  taosArrayDestroy(pCatalogReq->pDbInfo);
3,007,523✔
349
  if (pCatalogReq->cloned) {
3,007,513✔
350
    taosArrayDestroy(pCatalogReq->pTableMeta);
459✔
351
    taosArrayDestroy(pCatalogReq->pTableHash);
459✔
352
#ifdef TD_ENTERPRISE
353
    taosArrayDestroy(pCatalogReq->pView);
459✔
354
#endif
355
    taosArrayDestroy(pCatalogReq->pTableTSMAs);
459✔
356
    taosArrayDestroy(pCatalogReq->pTSMAs);
459✔
357
    taosArrayDestroy(pCatalogReq->pTableName);
459✔
358
  } else {
359
    taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq);
3,007,054✔
360
    taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
3,007,013✔
361
#ifdef TD_ENTERPRISE
362
    taosArrayDestroyEx(pCatalogReq->pView, destoryTablesReq);
3,007,055✔
363
#endif
364
    taosArrayDestroyEx(pCatalogReq->pTableTSMAs, destoryTablesReq);
3,007,068✔
365
    taosArrayDestroyEx(pCatalogReq->pTSMAs, destoryTablesReq);
3,007,077✔
366
    taosArrayDestroyEx(pCatalogReq->pTableName, destoryTablesReq);
3,007,084✔
367
  }
368
  taosArrayDestroy(pCatalogReq->pUdf);
3,007,543✔
369
  taosArrayDestroy(pCatalogReq->pIndex);
3,007,537✔
370
  taosArrayDestroy(pCatalogReq->pUser);
3,007,533✔
371
  taosArrayDestroy(pCatalogReq->pTableIndex);
3,007,517✔
372
  taosArrayDestroy(pCatalogReq->pTableCfg);
3,007,517✔
373
  taosArrayDestroy(pCatalogReq->pTableTag);
3,007,520✔
374
  taosArrayDestroy(pCatalogReq->pVSubTable);
3,007,517✔
375
  taosArrayDestroy(pCatalogReq->pVStbRefDbs);
3,007,516✔
376
}
377

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

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

389
void qDestroyParseContext(SParseContext* pCxt) {
3,007,506✔
390
  if (NULL == pCxt) {
3,007,506!
391
    return;
×
392
  }
393

394
  taosArrayDestroyEx(pCxt->pSubMetaList, tfreeSParseQueryRes);
3,007,506✔
395
  taosArrayDestroy(pCxt->pTableMetaPos);
3,007,539✔
396
  taosArrayDestroy(pCxt->pTableVgroupPos);
3,007,541✔
397
  taosMemoryFree(pCxt);
3,007,542!
398
}
399

400
void qDestroyQuery(SQuery* pQueryNode) { nodesDestroyNode((SNode*)pQueryNode); }
3,255,078✔
401

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

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

418
int32_t qInitKeywordsTable() { return taosInitKeywordsTable(); }
17,380✔
419

420
void qCleanupKeywordsTable() { taosCleanupKeywordsTable(); }
17,153✔
421

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

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

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

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

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

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

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

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

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

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

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

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