tscSql.c 25.9 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

H
hjxilinx 已提交
16
#include "hash.h"
H
hjxilinx 已提交
17
#include "os.h"
H
Haojun Liao 已提交
18
#include "qAst.h"
19
#include "tkey.h"
H
hzcheng 已提交
20
#include "tcache.h"
H
hjxilinx 已提交
21
#include "tnote.h"
H
hzcheng 已提交
22
#include "trpc.h"
S
slguan 已提交
23
#include "tscLog.h"
H
hjxilinx 已提交
24
#include "tscSubquery.h"
H
hzcheng 已提交
25 26
#include "tscUtil.h"
#include "tsclient.h"
27
#include "ttokendef.h"
H
hjxilinx 已提交
28
#include "tutil.h"
H
hzcheng 已提交
29

30 31 32 33 34 35 36 37 38 39 40 41
static bool validImpl(const char* str, size_t maxsize) {
  if (str == NULL) {
    return false;
  }
  
  size_t len = strlen(str);
  if (len <= 0 || len > maxsize) {
    return false;
  }
  
  return true;
}
H
hzcheng 已提交
42

43
static bool validUserName(const char* user) {
B
Bomin Zhang 已提交
44
  return validImpl(user, TSDB_USER_LEN - 1);
45
}
S
slguan 已提交
46

47
static bool validPassword(const char* passwd) {
B
Bomin Zhang 已提交
48
  return validImpl(passwd, TSDB_PASSWORD_LEN - 1);
49
}
H
hzcheng 已提交
50

51 52
SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, const char *auth, const char *db,
                         uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, void **taos) {
53
  taos_init();
54

55
  if (!validUserName(user)) {
56
    terrno = TSDB_CODE_TSC_INVALID_USER_LENGTH;
H
hzcheng 已提交
57 58 59
    return NULL;
  }

60 61 62 63 64 65 66 67 68 69
  char secretEncrypt[32] = {0};
  int  secretEncryptLen = 0;
  if (auth == NULL) {
    if (!validPassword(pass)) {
      terrno = TSDB_CODE_TSC_INVALID_PASS_LENGTH;
      return NULL;
    }
    taosEncryptPass((uint8_t *)pass, strlen(pass), secretEncrypt);
  } else {
    int   outlen = 0;
70
    int   len = (int)strlen(auth);
71 72 73 74 75 76 77 78 79 80 81
    char *base64 = (char *)base64_decode(auth, len, &outlen);
    if (base64 == NULL || outlen == 0) {
      tscError("invalid auth info:%s", auth);
      free(base64);
      terrno = TSDB_CODE_TSC_INVALID_PASS_LENGTH;
      return NULL;
    } else {
      memcpy(secretEncrypt, base64, outlen);
      free(base64);
    }
    secretEncryptLen = outlen;
H
hzcheng 已提交
82
  }
83 84

  if (ip) {
85
    if (tscSetMgmtEpSetFromCfg(ip, NULL) < 0) return NULL;
86
    if (port) tscMgmtEpSet.epSet.port[0] = port;
87 88
  } 
 
89
  void *pDnodeConn = NULL;
90
  if (tscInitRpc(user, secretEncrypt, &pDnodeConn) != 0) {
91
    terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL;
S
slguan 已提交
92 93
    return NULL;
  }
94
 
95
  STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj));
S
slguan 已提交
96
  if (NULL == pObj) {
97
    terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
98
    rpcClose(pDnodeConn);
S
slguan 已提交
99 100
    return NULL;
  }
H
hjxilinx 已提交
101

H
hzcheng 已提交
102 103
  pObj->signature = pObj;

B
Bomin Zhang 已提交
104
  tstrncpy(pObj->user, user, sizeof(pObj->user));
105 106
  secretEncryptLen = MIN(secretEncryptLen, sizeof(pObj->pass));
  memcpy(pObj->pass, secretEncrypt, secretEncryptLen);
H
hzcheng 已提交
107 108

  if (db) {
S
TD-1057  
Shengliang Guan 已提交
109
    int32_t len = (int32_t)strlen(db);
H
hzcheng 已提交
110
    /* db name is too long */
B
Bomin Zhang 已提交
111
    if (len >= TSDB_DB_NAME_LEN) {
112
      terrno = TSDB_CODE_TSC_INVALID_DB_LENGTH;
113 114
      rpcClose(pDnodeConn);
      free(pObj);
H
hzcheng 已提交
115 116 117
      return NULL;
    }

B
Bomin Zhang 已提交
118 119
    char tmp[TSDB_DB_NAME_LEN] = {0};
    tstrncpy(tmp, db, sizeof(tmp));
H
hzcheng 已提交
120 121

    strdequote(tmp);
S
slguan 已提交
122
    strtolower(pObj->db, tmp);
H
hzcheng 已提交
123 124 125 126
  }

  pthread_mutex_init(&pObj->mutex, NULL);

127
  SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
S
slguan 已提交
128
  if (NULL == pSql) {
129
    terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
130
    rpcClose(pDnodeConn);
S
slguan 已提交
131 132 133
    free(pObj);
    return NULL;
  }
H
hjxilinx 已提交
134

H
hzcheng 已提交
135 136
  pSql->pTscObj = pObj;
  pSql->signature = pSql;
137
  pSql->maxRetry = TSDB_MAX_REPLICA;
S
slguan 已提交
138
  tsem_init(&pSql->rspSem, 0, 0);
H
hjxilinx 已提交
139
  
140 141
  pObj->pDnodeConn = pDnodeConn;
  
H
hzcheng 已提交
142 143 144 145 146 147 148
  pSql->fp = fp;
  pSql->param = param;
  if (taos != NULL) {
    *taos = pObj;
  }

  pSql->cmd.command = TSDB_SQL_CONNECT;
149
  if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) {
150
    terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
151
    rpcClose(pDnodeConn);
S
slguan 已提交
152 153 154 155
    free(pSql);
    free(pObj);
    return NULL;
  }
H
hzcheng 已提交
156

157
  tsInsertHeadSize = sizeof(SMsgDesc) + sizeof(SSubmitMsg);
H
Haojun Liao 已提交
158
  return pSql;
H
hzcheng 已提交
159 160
}

161
static void syncConnCallback(void *param, TAOS_RES *tres, int code) {
H
Haojun Liao 已提交
162 163
  SSqlObj *pSql = (SSqlObj *) tres;
  assert(pSql != NULL);
H
hjxilinx 已提交
164
  
S
TD-1057  
Shengliang Guan 已提交
165
  tsem_post(&pSql->rspSem);
166 167
}

168 169 170 171
TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, const char *auth, const char *db,
                            uint16_t port) {
  STscObj *pObj = NULL;
  SSqlObj *pSql = taosConnectImpl(ip, user, pass, auth, db, port, syncConnCallback, NULL, (void **)&pObj);
H
Haojun Liao 已提交
172
  if (pSql != NULL) {
173
    pSql->fp = syncConnCallback;
H
Haojun Liao 已提交
174
    pSql->param = pSql;
175

176
    tscProcessSql(pSql);
S
TD-1057  
Shengliang Guan 已提交
177
    tsem_wait(&pSql->rspSem);
178

179
    if (pSql->res.code != TSDB_CODE_SUCCESS) {
H
hjxilinx 已提交
180
      terrno = pSql->res.code;
H
Haojun Liao 已提交
181
      taos_free_result(pSql);
182 183 184 185
      taos_close(pObj);
      return NULL;
    }
    
186
    tscDebug("%p DB connection is opening, dnodeConn:%p", pObj, pObj->pDnodeConn);
H
Haojun Liao 已提交
187 188
    taos_free_result(pSql);
  
S
slguan 已提交
189
    // version compare only requires the first 3 segments of the version string
190
    int code = taosCheckVersion(version, taos_get_server_info(pObj), 3);
S
slguan 已提交
191
    if (code != 0) {
H
hjxilinx 已提交
192
      terrno = code;
193
      taos_close(pObj);
S
slguan 已提交
194
      return NULL;
195 196
    } else {
      return pObj;
S
slguan 已提交
197
    }
H
hzcheng 已提交
198 199
  }

200
  return NULL;
H
hzcheng 已提交
201
}
H
Haojun Liao 已提交
202

203
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
S
Shengliang Guan 已提交
204
  tscDebug("try to create a connection to %s:%u, user:%s db:%s", ip, port != 0 ? port : tsServerPort , user, db);
205 206 207 208 209 210 211 212 213 214 215 216
  if (user == NULL) user = TSDB_DEFAULT_USER;
  if (pass == NULL) pass = TSDB_DEFAULT_PASS;

  return taos_connect_internal(ip, user, pass, NULL, db, port);
}

TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) {
  tscDebug("try to create a connection to %s:%u by auth, user:%s db:%s", ip, port, user, db);
  if (user == NULL) user = TSDB_DEFAULT_USER;
  if (auth == NULL) return NULL;

  return taos_connect_internal(ip, user, NULL, auth, db, port);
dengyihao's avatar
dengyihao 已提交
217 218
}

219 220 221 222 223 224 225 226 227 228 229 230
TAOS *taos_connect_c(const char *ip, uint8_t ipLen, const char *user, uint8_t userLen, const char *pass,
                     uint8_t passLen, const char *db, uint8_t dbLen, uint16_t port) {
  char ipBuf[TSDB_EP_LEN] = {0};
  char userBuf[TSDB_USER_LEN] = {0};
  char passBuf[TSDB_PASSWORD_LEN] = {0};
  char dbBuf[TSDB_DB_NAME_LEN] = {0};
  strncpy(ipBuf, ip, MIN(TSDB_EP_LEN - 1, ipLen));
  strncpy(userBuf, user, MIN(TSDB_USER_LEN - 1, userLen));
  strncpy(passBuf, pass, MIN(TSDB_PASSWORD_LEN - 1, passLen));
  strncpy(dbBuf, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen));
  return taos_connect(ipBuf, userBuf, passBuf, dbBuf, port);
}
H
hzcheng 已提交
231

L
lihui 已提交
232
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int),
H
hzcheng 已提交
233
                     void *param, void **taos) {
234
  SSqlObj* pSql = taosConnectImpl(ip, user, pass, NULL, db, port, fp, param, taos);
H
Haojun Liao 已提交
235
  if (pSql == NULL) {
236 237 238 239
    return NULL;
  }
  
  pSql->res.code = tscProcessSql(pSql);
240
  tscDebug("%p DB async connection is opening", taos);
H
Haojun Liao 已提交
241
  return taos;
H
hzcheng 已提交
242 243 244 245 246
}

void taos_close(TAOS *taos) {
  STscObj *pObj = (STscObj *)taos;

H
hjxilinx 已提交
247 248 249
  if (pObj == NULL || pObj->signature != pObj)  {
    return;
  }
H
hzcheng 已提交
250 251

  if (pObj->pHb != NULL) {
252 253 254 255
    if (pObj->pHb->pRpcCtx != NULL) {  // wait for rsp from dnode
      rpcCancelRequest(pObj->pHb->pRpcCtx);
    }

H
hzcheng 已提交
256
    tscSetFreeHeatBeat(pObj);
257
    tscFreeSqlObj(pObj->pHb);
H
hzcheng 已提交
258
  }
259 260

  tscCloseTscObj(pObj);
H
hzcheng 已提交
261 262
}

H
Hui Li 已提交
263
void waitForQueryRsp(void *param, TAOS_RES *tres, int code) {
H
Hui Li 已提交
264
  assert(tres != NULL);
H
[td-99]  
hjxilinx 已提交
265
  
H
Haojun Liao 已提交
266
  SSqlObj *pSql = (SSqlObj *) tres;
S
TD-1057  
Shengliang Guan 已提交
267
  tsem_post(&pSql->rspSem);
268 269
}

270 271
static void waitForRetrieveRsp(void *param, TAOS_RES *tres, int numOfRows) {
  SSqlObj* pSql = (SSqlObj*) tres;
S
TD-1057  
Shengliang Guan 已提交
272
  tsem_post(&pSql->rspSem);
273 274
}

275
TAOS_RES* taos_query_c(TAOS *taos, const char *sqlstr, uint32_t sqlLen) {
S
slguan 已提交
276 277
  STscObj *pObj = (STscObj *)taos;
  if (pObj == NULL || pObj->signature != pObj) {
278
    terrno = TSDB_CODE_TSC_DISCONNECTED;
H
Haojun Liao 已提交
279
    return NULL;
S
slguan 已提交
280
  }
281
  
S
TD-1057  
Shengliang Guan 已提交
282
  if (sqlLen > (uint32_t)tsMaxSQLStringLen) {
H
Haojun Liao 已提交
283
    tscError("sql string exceeds max length:%d", tsMaxSQLStringLen);
284
    terrno = TSDB_CODE_TSC_INVALID_SQL;
H
Haojun Liao 已提交
285 286
    return NULL;
  }
287

H
Haojun Liao 已提交
288
  taosNotePrintTsc(sqlstr);
S
slguan 已提交
289

H
Haojun Liao 已提交
290 291 292
  SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
  if (pSql == NULL) {
    tscError("failed to malloc sqlObj");
293
    terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
H
Haojun Liao 已提交
294 295 296
    return NULL;
  }
  
S
TD-1057  
Shengliang Guan 已提交
297
  tsem_init(&pSql->rspSem, 0, 0);
H
[TD-98]  
hjxilinx 已提交
298
  doAsyncQuery(pObj, pSql, waitForQueryRsp, taos, sqlstr, sqlLen);
S
slguan 已提交
299

H
Haojun Liao 已提交
300
  tsem_wait(&pSql->rspSem);
301
  return pSql; 
H
hzcheng 已提交
302
}
303

304
TAOS_RES* taos_query(TAOS *taos, const char *sqlstr) {
S
Shengliang Guan 已提交
305
  return taos_query_c(taos, sqlstr, (uint32_t)strlen(sqlstr));
dengyihao's avatar
dengyihao 已提交
306
}
307

H
hzcheng 已提交
308 309 310 311 312 313 314 315 316 317 318 319 320
int taos_result_precision(TAOS_RES *res) {
  SSqlObj *pSql = (SSqlObj *)res;
  if (pSql == NULL || pSql->signature != pSql) return 0;

  return pSql->res.precision;
}

int taos_num_rows(TAOS_RES *res) { return 0; }

int taos_num_fields(TAOS_RES *res) {
  SSqlObj *pSql = (SSqlObj *)res;
  if (pSql == NULL || pSql->signature != pSql) return 0;

H
hjxilinx 已提交
321
  int32_t num = 0;
322
  SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
323
  if (pQueryInfo == NULL) {
H
hjxilinx 已提交
324
    return num;
325
  }
326

H
hjxilinx 已提交
327 328 329 330 331 332 333 334 335
  size_t numOfCols = tscNumOfFields(pQueryInfo);
  for(int32_t i = 0; i < numOfCols; ++i) {
    SFieldSupInfo* pInfo = taosArrayGet(pQueryInfo->fieldsInfo.pSupportInfo, i);
    if (pInfo->visible) {
      num++;
    }
  }
  
  return num;
H
hzcheng 已提交
336 337
}

H
Haojun Liao 已提交
338 339 340
int taos_field_count(TAOS_RES *tres) {
  SSqlObj* pSql = (SSqlObj*) tres;
  if (pSql == NULL || pSql->signature != pSql) return 0;
H
hzcheng 已提交
341

H
Haojun Liao 已提交
342
  return taos_num_fields(pSql);
H
hzcheng 已提交
343 344
}

H
Haojun Liao 已提交
345 346 347
int taos_affected_rows(TAOS_RES *tres) {
  SSqlObj* pSql = (SSqlObj*) tres;
  if (pSql == NULL || pSql->signature != pSql) return 0;
H
hzcheng 已提交
348

S
TD-1057  
Shengliang Guan 已提交
349
  return (int)(pSql->res.numOfRows);
H
hzcheng 已提交
350 351 352 353 354
}

TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
  SSqlObj *pSql = (SSqlObj *)res;
  if (pSql == NULL || pSql->signature != pSql) return 0;
355 356

  SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
H
hjxilinx 已提交
357
  if (pQueryInfo == NULL) {
sangshuduo's avatar
sangshuduo 已提交
358
    return NULL;
H
hjxilinx 已提交
359 360 361 362 363 364 365 366
  }
  
  size_t numOfCols = tscNumOfFields(pQueryInfo);
  if (numOfCols == 0) {
    return NULL;
  }
  
  return pQueryInfo->fieldsInfo.pFields->pData;
H
hzcheng 已提交
367 368 369 370 371 372 373 374 375 376
}

int taos_retrieve(TAOS_RES *res) {
  if (res == NULL) return 0;
  SSqlObj *pSql = (SSqlObj *)res;
  SSqlCmd *pCmd = &pSql->cmd;
  SSqlRes *pRes = &pSql->res;
  if (pSql == NULL || pSql->signature != pSql) return 0;
  if (pRes->qhandle == 0) return 0;

S
slguan 已提交
377 378
  tscResetForNextRetrieve(pRes);

H
hzcheng 已提交
379 380 381 382 383
  if (pCmd->command < TSDB_SQL_LOCAL) {
    pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
  }
  tscProcessSql(pSql);

S
TD-1057  
Shengliang Guan 已提交
384
  return (int)pRes->numOfRows;
H
hzcheng 已提交
385 386 387 388 389 390 391
}

int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) {
  SSqlObj *pSql = (SSqlObj *)res;
  SSqlCmd *pCmd = &pSql->cmd;
  SSqlRes *pRes = &pSql->res;

H
Haojun Liao 已提交
392
  if (pRes->qhandle == 0 || pSql->signature != pSql) {
H
hzcheng 已提交
393 394 395 396 397
    *rows = NULL;
    return 0;
  }

  // Retrieve new block
S
slguan 已提交
398
  tscResetForNextRetrieve(pRes);
H
hzcheng 已提交
399 400 401 402 403 404 405 406 407 408
  if (pCmd->command < TSDB_SQL_LOCAL) {
    pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
  }

  tscProcessSql(pSql);
  if (pRes->numOfRows == 0) {
    *rows = NULL;
    return 0;
  }

S
slguan 已提交
409
  // secondary merge has handle this situation
H
hjxilinx 已提交
410
  if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE) {
H
Haojun Liao 已提交
411
    pRes->numOfClauseTotal += pRes->numOfRows;
S
slguan 已提交
412 413
  }

414
  SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
sangshuduo's avatar
sangshuduo 已提交
415 416 417
  if (pQueryInfo == NULL)
    return 0;

H
hjxilinx 已提交
418
  assert(0);
H
hjxilinx 已提交
419
  for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
420
    tscGetResultColumnChr(pRes, &pQueryInfo->fieldsInfo, i);
H
hzcheng 已提交
421 422 423 424
  }

  *rows = pRes->tsrow;

S
TD-1057  
Shengliang Guan 已提交
425
  return (int)((pQueryInfo->order.order == TSDB_ORDER_DESC) ? pRes->numOfRows : -pRes->numOfRows);
H
hzcheng 已提交
426 427 428 429 430
}

TAOS_ROW taos_fetch_row(TAOS_RES *res) {
  SSqlObj *pSql = (SSqlObj *)res;
  if (pSql == NULL || pSql->signature != pSql) {
431
    terrno = TSDB_CODE_TSC_DISCONNECTED;
H
hzcheng 已提交
432 433
    return NULL;
  }
434 435 436 437
  
  SSqlCmd *pCmd = &pSql->cmd;
  SSqlRes *pRes = &pSql->res;
  
H
hjxilinx 已提交
438 439 440
  if (pRes->qhandle == 0 ||
      pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
      pCmd->command == TSDB_SQL_INSERT) {
441
    return NULL;
442
  }
443 444 445 446

  // set the sql object owner
  tscSetSqlOwner(pSql);

447
  // current data set are exhausted, fetch more data from node
H
Haojun Liao 已提交
448
  if (pRes->row >= pRes->numOfRows && (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) &&
H
hjxilinx 已提交
449
      (pCmd->command == TSDB_SQL_RETRIEVE ||
H
hjxilinx 已提交
450
       pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE ||
451
       pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE ||
H
hjxilinx 已提交
452 453 454
       pCmd->command == TSDB_SQL_FETCH ||
       pCmd->command == TSDB_SQL_SHOW ||
       pCmd->command == TSDB_SQL_SELECT ||
H
Haojun Liao 已提交
455 456 457 458 459 460
       pCmd->command == TSDB_SQL_DESCRIBE_TABLE ||
       pCmd->command == TSDB_SQL_SERV_STATUS ||
       pCmd->command == TSDB_SQL_CURRENT_DB ||
       pCmd->command == TSDB_SQL_SERV_VERSION ||
       pCmd->command == TSDB_SQL_CLI_VERSION ||
       pCmd->command == TSDB_SQL_CURRENT_USER )) {
H
[td-99]  
hjxilinx 已提交
461
    taos_fetch_rows_a(res, waitForRetrieveRsp, pSql->pTscObj);
S
TD-1057  
Shengliang Guan 已提交
462
    tsem_wait(&pSql->rspSem);
H
hjxilinx 已提交
463
  }
H
Haojun Liao 已提交
464

465 466 467 468
  void* data = doSetResultRowData(pSql, true);

  tscClearSqlOwner(pSql);
  return data;
H
hzcheng 已提交
469 470 471
}

int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
H
hjxilinx 已提交
472
#if 0
H
hzcheng 已提交
473
  SSqlObj *pSql = (SSqlObj *)res;
H
hjxilinx 已提交
474
  SSqlCmd *pCmd = &pSql->cmd;
475
  SSqlRes *pRes = &pSql->res;
476

H
hzcheng 已提交
477 478 479
  int nRows = 0;

  if (pSql == NULL || pSql->signature != pSql) {
480
    terrno = TSDB_CODE_TSC_DISCONNECTED;
H
hzcheng 已提交
481 482 483 484
    *rows = NULL;
    return 0;
  }

S
slguan 已提交
485
  // projection query on metric, pipeline retrieve data from vnode list,
S
slguan 已提交
486
  // instead of two-stage mergednodeProcessMsgFromShell free qhandle
H
hzcheng 已提交
487
  nRows = taos_fetch_block_impl(res, rows);
488

H
hjxilinx 已提交
489 490
  // current subclause is completed, try the next subclause
  while (rows == NULL && pCmd->clauseIndex < pCmd->numOfClause - 1) {
491 492
    SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);

493
    pSql->cmd.command = pQueryInfo->command;
H
hjxilinx 已提交
494
    pCmd->clauseIndex++;
495

H
Haojun Liao 已提交
496 497
    pRes->numOfTotal += pRes->numOfClauseTotal;
    pRes->numOfClauseTotal = 0;
498
    pRes->rspType = 0;
499

500
    pSql->numOfSubs = 0;
S
Shengliang Guan 已提交
501
    taosTFree(pSql->pSubs);
502

H
hjxilinx 已提交
503
    assert(pSql->fp == NULL);
504

505
    tscDebug("%p try data in the next subclause:%d, total subclause:%d", pSql, pCmd->clauseIndex, pCmd->numOfClause);
H
hjxilinx 已提交
506
    tscProcessSql(pSql);
507

H
hjxilinx 已提交
508
    nRows = taos_fetch_block_impl(res, rows);
H
hzcheng 已提交
509
  }
510

H
hzcheng 已提交
511
  return nRows;
H
hjxilinx 已提交
512 513 514 515
#endif

  (*rows) = taos_fetch_row(res);
  return ((*rows) != NULL)? 1:0;
H
hzcheng 已提交
516 517
}

S
slguan 已提交
518
int taos_select_db(TAOS *taos, const char *db) {
519
  char sql[256] = {0};
H
hzcheng 已提交
520 521 522

  STscObj *pObj = (STscObj *)taos;
  if (pObj == NULL || pObj->signature != pObj) {
523 524
    terrno = TSDB_CODE_TSC_DISCONNECTED;
    return TSDB_CODE_TSC_DISCONNECTED;
H
hzcheng 已提交
525 526
  }

527
  snprintf(sql, tListLen(sql), "use %s", db);
H
Haojun Liao 已提交
528 529 530 531 532
  SSqlObj* pSql = taos_query(taos, sql);
  int32_t code = pSql->res.code;
  taos_free_result(pSql);
  
  return code;
H
hzcheng 已提交
533 534
}

H
Haojun Liao 已提交
535
// send free message to vnode to free qhandle and corresponding resources in vnode
536
static bool tscKillQueryInVnode(SSqlObj* pSql) {
H
Haojun Liao 已提交
537 538 539 540 541 542 543 544
  SSqlCmd* pCmd = &pSql->cmd;
  SSqlRes* pRes = &pSql->res;

  SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
  STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);

  if (pRes->code == TSDB_CODE_SUCCESS && pRes->completed == false && !tscIsTwoStageSTableQuery(pQueryInfo, 0) &&
      (pCmd->command == TSDB_SQL_SELECT ||
H
Haojun Liao 已提交
545 546 547 548
       pCmd->command == TSDB_SQL_SHOW ||
       pCmd->command == TSDB_SQL_RETRIEVE ||
       pCmd->command == TSDB_SQL_FETCH) &&
      (pSql->pStream == NULL && pTableMetaInfo->pTableMeta != NULL)) {
H
Haojun Liao 已提交
549 550

    pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
H
Haojun Liao 已提交
551
    tscDebug("%p send msg to dnode to free qhandle ASAP, command:%s, ", pSql, sqlCmd[pCmd->command]);
H
Haojun Liao 已提交
552
    tscProcessSql(pSql);
H
Haojun Liao 已提交
553
    return true;
H
Haojun Liao 已提交
554
  }
H
Haojun Liao 已提交
555 556

  return false;
H
Haojun Liao 已提交
557 558
}

H
Haojun Liao 已提交
559
void taos_free_result(TAOS_RES *res) {
H
hzcheng 已提交
560
  SSqlObj *pSql = (SSqlObj *)res;
H
Haojun Liao 已提交
561

H
Haojun Liao 已提交
562
  if (pSql == NULL || pSql->signature != pSql) {
563
    tscDebug("%p sqlObj has been freed", pSql);
H
Haojun Liao 已提交
564 565
    return;
  }
H
Haojun Liao 已提交
566
  
H
Haojun Liao 已提交
567
  // The semaphore can not be changed while freeing async sub query objects.
H
Haojun Liao 已提交
568
  SSqlRes *pRes = &pSql->res;
H
Haojun Liao 已提交
569 570
  if (pRes == NULL || pRes->qhandle == 0) {
    tscFreeSqlObj(pSql);
571
    tscDebug("%p SqlObj is freed by app, qhandle is null", pSql);
H
hzcheng 已提交
572 573 574
    return;
  }

H
Haojun Liao 已提交
575
  // set freeFlag to 1 in retrieve message if there are un-retrieved results data in node
576
  SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
577
  if (pQueryInfo == NULL) {
H
Haojun Liao 已提交
578
    tscFreeSqlObj(pSql);
579
    tscDebug("%p SqlObj is freed by app", pSql);
580 581 582
    return;
  }

583
  pQueryInfo->type = TSDB_QUERY_TYPE_FREE_RESOURCE;
584
  if (!tscKillQueryInVnode(pSql)) {
H
Haojun Liao 已提交
585
    tscFreeSqlObj(pSql);
586
    tscDebug("%p sqlObj is freed by app", pSql);
H
hzcheng 已提交
587 588 589
  }
}

H
Haojun Liao 已提交
590 591 592
int taos_errno(TAOS_RES *tres) {
  SSqlObj *pSql = (SSqlObj *) tres;
  if (pSql == NULL || pSql->signature != pSql) {
H
[td-99]  
hjxilinx 已提交
593 594
    return terrno;
  }
H
hzcheng 已提交
595

H
Haojun Liao 已提交
596
  return pSql->res.code;
H
hzcheng 已提交
597 598
}

H
hjxilinx 已提交
599 600 601 602
/*
 * In case of invalid sql error, additional information is attached to explain
 * why the sql is invalid
 */
H
hjxilinx 已提交
603
static bool hasAdditionalErrorInfo(int32_t code, SSqlCmd *pCmd) {
604
  if (code != TSDB_CODE_TSC_INVALID_SQL) {
H
hjxilinx 已提交
605 606 607 608
    return false;
  }

  size_t len = strlen(pCmd->payload);
H
hjxilinx 已提交
609 610

  char *z = NULL;
H
hjxilinx 已提交
611
  if (len > 0) {
H
hjxilinx 已提交
612
    z = strstr(pCmd->payload, "invalid SQL");
H
hjxilinx 已提交
613
  }
H
hjxilinx 已提交
614

H
hjxilinx 已提交
615 616 617
  return z != NULL;
}

H
[td-99]  
hjxilinx 已提交
618
// todo should not be used in async model
H
Haojun Liao 已提交
619 620
char *taos_errstr(TAOS_RES *tres) {
  SSqlObj *pSql = (SSqlObj *) tres;
H
hzcheng 已提交
621

H
Haojun Liao 已提交
622 623 624
  if (pSql == NULL || pSql->signature != pSql) {
    return (char*) tstrerror(terrno);
  }
H
hzcheng 已提交
625

H
[td-32]  
hjxilinx 已提交
626
  if (hasAdditionalErrorInfo(pSql->res.code, &pSql->cmd)) {
H
hjxilinx 已提交
627
    return pSql->cmd.payload;
H
hzcheng 已提交
628
  } else {
H
[td-32]  
hjxilinx 已提交
629
    return (char*)tstrerror(pSql->res.code);
H
hzcheng 已提交
630 631 632 633 634
  }
}

void taos_config(int debug, char *log_path) {
  uDebugFlag = debug;
B
Bomin Zhang 已提交
635
  tstrncpy(tsLogDir, log_path, TSDB_FILENAME_LEN);
H
hzcheng 已提交
636 637 638 639 640 641 642 643 644 645
}

char *taos_get_server_info(TAOS *taos) {
  STscObj *pObj = (STscObj *)taos;

  if (pObj == NULL) return NULL;

  return pObj->sversion;
}

646 647 648 649 650 651 652 653 654
int* taos_fetch_lengths(TAOS_RES *res) {
  SSqlObj* pSql = (SSqlObj* ) res;
  if (pSql == NULL || pSql->signature != pSql) {
    return NULL;
  }
  
  return pSql->res.length;
}

H
hzcheng 已提交
655 656 657
char *taos_get_client_info() { return version; }

void taos_stop_query(TAOS_RES *res) {
H
Haojun Liao 已提交
658 659
  SSqlObj *pSql = (SSqlObj *)res;
  if (pSql == NULL || pSql->signature != pSql) {
660 661
    return;
  }
H
hzcheng 已提交
662

663
  tscDebug("%p start to cancel query", res);
664 665
  SSqlCmd *pCmd = &pSql->cmd;

H
Haojun Liao 已提交
666 667
  // TODO there are multi-thread problem.
  // It may have been released by the other thread already.
H
Haojun Liao 已提交
668
  // The ref count may fix this problem.
669
  SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
H
hzcheng 已提交
670

671 672
  // set the error code for master pSqlObj firstly
  pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
H
hzcheng 已提交
673

H
hjxilinx 已提交
674
  if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
675
    assert(pSql->pRpcCtx == NULL);
H
hjxilinx 已提交
676
    tscKillSTableQuery(pSql);
677 678 679 680
  } else {
    if (pSql->cmd.command < TSDB_SQL_LOCAL) {
      rpcCancelRequest(pSql->pRpcCtx);
    }
H
hzcheng 已提交
681 682
  }

683
  tscDebug("%p query is cancelled", res);
H
hzcheng 已提交
684 685 686 687 688
}

int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) {
  int len = 0;
  for (int i = 0; i < num_fields; ++i) {
689 690 691 692
    if (i > 0) {
      str[len++] = ' ';
    }

H
hzcheng 已提交
693
    if (row[i] == NULL) {
694
      len += sprintf(str + len, "%s", TSDB_DATA_NULL_STR);
H
hzcheng 已提交
695 696 697 698 699
      continue;
    }

    switch (fields[i].type) {
      case TSDB_DATA_TYPE_TINYINT:
700
        len += sprintf(str + len, "%d", *((char *)row[i]));
H
hzcheng 已提交
701 702 703
        break;

      case TSDB_DATA_TYPE_SMALLINT:
704
        len += sprintf(str + len, "%d", *((short *)row[i]));
H
hzcheng 已提交
705 706 707
        break;

      case TSDB_DATA_TYPE_INT:
708
        len += sprintf(str + len, "%d", *((int *)row[i]));
H
hzcheng 已提交
709 710 711
        break;

      case TSDB_DATA_TYPE_BIGINT:
712
        len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
H
hzcheng 已提交
713 714
        break;

L
lihui 已提交
715 716
      case TSDB_DATA_TYPE_FLOAT: {
        float fv = 0;
L
lihui 已提交
717
        fv = GET_FLOAT_VAL(row[i]);
718
        len += sprintf(str + len, "%f", fv);
719
      } break;
H
hzcheng 已提交
720

721
      case TSDB_DATA_TYPE_DOUBLE: {
L
lihui 已提交
722
        double dv = 0;
L
lihui 已提交
723
        dv = GET_DOUBLE_VAL(row[i]);
724
        len += sprintf(str + len, "%lf", dv);
725
      } break;
H
hzcheng 已提交
726 727

      case TSDB_DATA_TYPE_BINARY:
S
slguan 已提交
728
      case TSDB_DATA_TYPE_NCHAR: {
H
hjxilinx 已提交
729
        size_t xlen = 0;
730
        for (xlen = 0; xlen < fields[i].bytes - VARSTR_HEADER_SIZE; xlen++) {
H
hjxilinx 已提交
731 732 733 734 735 736
          char c = ((char *)row[i])[xlen];
          if (c == 0) break;
          str[len++] = c;
        }
        str[len] = 0;
      } break;
H
hzcheng 已提交
737 738

      case TSDB_DATA_TYPE_TIMESTAMP:
739
        len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
H
hzcheng 已提交
740 741 742
        break;

      case TSDB_DATA_TYPE_BOOL:
743
        len += sprintf(str + len, "%d", *((int8_t *)row[i]));
H
hzcheng 已提交
744 745 746 747 748 749 750 751
      default:
        break;
    }
  }

  return len;
}

752 753 754 755
static void asyncCallback(void *param, TAOS_RES *tres, int code) {
  assert(param != NULL);
  SSqlObj *pSql = ((SSqlObj *)param);
  pSql->res.code = code;
S
TD-1057  
Shengliang Guan 已提交
756
  tsem_post(&pSql->rspSem);
757 758
}

S
slguan 已提交
759
int taos_validate_sql(TAOS *taos, const char *sql) {
H
hzcheng 已提交
760 761
  STscObj *pObj = (STscObj *)taos;
  if (pObj == NULL || pObj->signature != pObj) {
762 763
    terrno = TSDB_CODE_TSC_DISCONNECTED;
    return TSDB_CODE_TSC_DISCONNECTED;
H
hzcheng 已提交
764 765
  }

H
Haojun Liao 已提交
766
  SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
767 768
  pSql->pTscObj = taos;
  pSql->signature = pSql;
H
hzcheng 已提交
769
  SSqlRes *pRes = &pSql->res;
770 771
  SSqlCmd *pCmd = &pSql->cmd;
  
H
hzcheng 已提交
772
  pRes->numOfTotal = 0;
H
Haojun Liao 已提交
773
  pRes->numOfClauseTotal = 0;
774

775
  tscDebug("%p Valid SQL: %s pObj:%p", pSql, sql, pObj);
H
hzcheng 已提交
776

S
TD-1057  
Shengliang Guan 已提交
777
  int32_t sqlLen = (int32_t)strlen(sql);
H
hjxilinx 已提交
778
  if (sqlLen > tsMaxSQLStringLen) {
H
hzcheng 已提交
779
    tscError("%p sql too long", pSql);
780
    pRes->code = TSDB_CODE_TSC_INVALID_SQL;
S
Shengliang Guan 已提交
781
    taosTFree(pSql);
H
hzcheng 已提交
782 783 784 785 786
    return pRes->code;
  }

  pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1);
  if (pSql->sqlstr == NULL) {
787
    pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
H
hzcheng 已提交
788
    tscError("%p failed to malloc sql string buffer", pSql);
789
    tscDebug("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
S
Shengliang Guan 已提交
790
    taosTFree(pSql);
H
hzcheng 已提交
791 792 793
    return pRes->code;
  }

S
slguan 已提交
794
  strtolower(pSql->sqlstr, sql);
H
hzcheng 已提交
795

796 797 798 799
  pCmd->curSql = NULL;
  if (NULL != pCmd->pTableList) {
    taosHashCleanup(pCmd->pTableList);
    pCmd->pTableList = NULL;
L
lihui 已提交
800 801
  }

802 803 804 805 806
  pSql->fp = asyncCallback;
  pSql->fetchFp = asyncCallback;
  pSql->param = pSql;
  int code = tsParseSql(pSql, true);
  if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
S
TD-1057  
Shengliang Guan 已提交
807
    tsem_wait(&pSql->rspSem);
808 809 810 811 812
    code = pSql->res.code;
  }
  if (code != TSDB_CODE_SUCCESS) {
    tscDebug("%p Valid SQL result:%d, %s pObj:%p", pSql, code, taos_errstr(taos), pObj);
  }
H
hzcheng 已提交
813 814 815 816
  taos_free_result(pSql);

  return code;
}
S
slguan 已提交
817

H
hjxilinx 已提交
818
static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t tblListLen) {
S
slguan 已提交
819
  // must before clean the sqlcmd object
B
Bomin Zhang 已提交
820
  tscResetSqlCmdObj(&pSql->cmd, false);
S
slguan 已提交
821 822 823 824 825 826

  SSqlCmd *pCmd = &pSql->cmd;

  pCmd->command = TSDB_SQL_MULTI_META;
  pCmd->count = 0;

827
  int   code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
H
hjxilinx 已提交
828
  char *str = (char *)tblNameList;
S
slguan 已提交
829

830 831 832 833 834
  SQueryInfo *pQueryInfo = tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex);
  if (pQueryInfo == NULL) {
    pSql->res.code = terrno;
    return terrno;
  }
835

H
hjxilinx 已提交
836
  STableMetaInfo *pTableMetaInfo = tscAddEmptyMetaInfo(pQueryInfo);
S
slguan 已提交
837

H
hjxilinx 已提交
838
  if ((code = tscAllocPayload(pCmd, tblListLen + 16)) != TSDB_CODE_SUCCESS) {
S
slguan 已提交
839 840 841 842
    return code;
  }

  char *nextStr;
H
Haojun Liao 已提交
843
  char  tblName[TSDB_TABLE_FNAME_LEN];
S
slguan 已提交
844 845 846 847 848 849 850 851 852
  int   payloadLen = 0;
  char *pMsg = pCmd->payload;
  while (1) {
    nextStr = strchr(str, ',');
    if (nextStr == NULL) {
      break;
    }

    memcpy(tblName, str, nextStr - str);
S
TD-1057  
Shengliang Guan 已提交
853
    int32_t len = (int32_t)(nextStr - str);
S
slguan 已提交
854 855 856
    tblName[len] = '\0';

    str = nextStr + 1;
S
TD-1057  
Shengliang Guan 已提交
857
    len = (int32_t)strtrim(tblName);
H
hjxilinx 已提交
858

H
Haojun Liao 已提交
859
    SStrToken sToken = {.n = len, .type = TK_ID, .z = tblName};
S
slguan 已提交
860 861 862 863
    tSQLGetToken(tblName, &sToken.type);

    // Check if the table name available or not
    if (tscValidateName(&sToken) != TSDB_CODE_SUCCESS) {
864
      code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
S
slguan 已提交
865 866 867 868
      sprintf(pCmd->payload, "table name is invalid");
      return code;
    }

H
Haojun Liao 已提交
869
    if ((code = tscSetTableFullName(pTableMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
S
slguan 已提交
870 871 872 873
      return code;
    }

    if (++pCmd->count > TSDB_MULTI_METERMETA_MAX_NUM) {
874
      code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
S
slguan 已提交
875 876 877 878
      sprintf(pCmd->payload, "tables over the max number");
      return code;
    }

H
hjxilinx 已提交
879
    if (payloadLen + strlen(pTableMetaInfo->name) + 128 >= pCmd->allocSize) {
S
slguan 已提交
880 881
      char *pNewMem = realloc(pCmd->payload, pCmd->allocSize + tblListLen);
      if (pNewMem == NULL) {
882
        code = TSDB_CODE_TSC_OUT_OF_MEMORY;
S
slguan 已提交
883 884 885 886 887 888 889 890 891
        sprintf(pCmd->payload, "failed to allocate memory");
        return code;
      }

      pCmd->payload = pNewMem;
      pCmd->allocSize = pCmd->allocSize + tblListLen;
      pMsg = pCmd->payload;
    }

H
hjxilinx 已提交
892
    payloadLen += sprintf(pMsg + payloadLen, "%s,", pTableMetaInfo->name);
S
slguan 已提交
893 894 895 896 897 898 899 900 901
  }

  *(pMsg + payloadLen) = '\0';
  pCmd->payloadLen = payloadLen + 1;

  return TSDB_CODE_SUCCESS;
}

int taos_load_table_info(TAOS *taos, const char *tableNameList) {
H
hjxilinx 已提交
902
  const int32_t MAX_TABLE_NAME_LENGTH = 12 * 1024 * 1024;  // 12MB list
S
slguan 已提交
903 904 905

  STscObj *pObj = (STscObj *)taos;
  if (pObj == NULL || pObj->signature != pObj) {
906 907
    terrno = TSDB_CODE_TSC_DISCONNECTED;
    return TSDB_CODE_TSC_DISCONNECTED;
S
slguan 已提交
908 909
  }

H
Haojun Liao 已提交
910
  SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
911 912
  pSql->pTscObj = taos;
  pSql->signature = pSql;
S
slguan 已提交
913 914 915
  SSqlRes *pRes = &pSql->res;

  pRes->numOfTotal = 0;  // the number of getting table meta from server
H
Haojun Liao 已提交
916
  pRes->numOfClauseTotal = 0;
917

S
slguan 已提交
918 919 920
  pRes->code = 0;

  assert(pSql->fp == NULL);
921
  tscDebug("%p tableNameList: %s pObj:%p", pSql, tableNameList, pObj);
S
slguan 已提交
922

S
TD-1057  
Shengliang Guan 已提交
923
  int32_t tblListLen = (int32_t)strlen(tableNameList);
S
slguan 已提交
924 925
  if (tblListLen > MAX_TABLE_NAME_LENGTH) {
    tscError("%p tableNameList too long, length:%d, maximum allowed:%d", pSql, tblListLen, MAX_TABLE_NAME_LENGTH);
926
    pRes->code = TSDB_CODE_TSC_INVALID_SQL;
S
Shengliang Guan 已提交
927
    taosTFree(pSql);
S
slguan 已提交
928 929 930
    return pRes->code;
  }

H
hjxilinx 已提交
931
  char *str = calloc(1, tblListLen + 1);
S
slguan 已提交
932
  if (str == NULL) {
933
    pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
S
slguan 已提交
934
    tscError("%p failed to malloc sql string buffer", pSql);
S
Shengliang Guan 已提交
935
    taosTFree(pSql);
S
slguan 已提交
936 937 938 939
    return pRes->code;
  }

  strtolower(str, tableNameList);
H
hjxilinx 已提交
940
  pRes->code = (uint8_t)tscParseTblNameList(pSql, str, tblListLen);
S
slguan 已提交
941 942 943 944 945 946 947 948 949 950

  /*
   * set the qhandle to 0 before return in order to erase the qhandle value assigned in the previous successful query.
   * If qhandle is NOT set 0, the function of taos_free_result() will send message to server by calling tscProcessSql()
   * to free connection, which may cause segment fault, when the parse phrase is not even successfully executed.
   */
  pRes->qhandle = 0;
  free(str);

  if (pRes->code != TSDB_CODE_SUCCESS) {
B
Bomin Zhang 已提交
951
    tscFreeSqlObj(pSql);
S
slguan 已提交
952 953 954 955 956
    return pRes->code;
  }

  tscDoQuery(pSql);

957
  tscDebug("%p load multi metermeta result:%d %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
S
slguan 已提交
958
  if (pRes->code != TSDB_CODE_SUCCESS) {
H
hjxilinx 已提交
959
    tscPartiallyFreeSqlObj(pSql);
S
slguan 已提交
960 961 962 963
  }

  return pRes->code;
}