planStmtTest.cpp 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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/>.
 */

#include "planTestUtil.h"
#include "planner.h"

using namespace std;

class PlanStmtTest : public PlannerTestBase {
X
Xiaoyu Wang 已提交
22
 public:
23 24 25 26 27 28 29 30 31 32
  void buildParam(TAOS_MULTI_BIND* pBindParams, int32_t index, void* pVal, int32_t type, int32_t bytes = 0) {
    TAOS_MULTI_BIND* pBindParam = pBindParams + index;
    pBindParam->buffer_type = type;
    pBindParam->num = 1;
    pBindParam->buffer_length = bytes > 0 ? bytes : tDataTypes[type].bytes;
    pBindParam->buffer = taosMemoryCalloc(1, pBindParam->buffer_length);
    pBindParam->length = (int32_t*)taosMemoryCalloc(1, sizeof(int32_t));
    pBindParam->is_null = (char*)taosMemoryCalloc(1, sizeof(char));
    *(pBindParam->length) = bytes > 0 ? bytes : tDataTypes[type].bytes;
    *(pBindParam->is_null) = 0;
33

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    switch (type) {
      case TSDB_DATA_TYPE_BOOL:
        *((bool*)pBindParam->buffer) = *(bool*)pVal;
        break;
      case TSDB_DATA_TYPE_TINYINT:
        *((int8_t*)pBindParam->buffer) = *(int64_t*)pVal;
        break;
      case TSDB_DATA_TYPE_SMALLINT:
      case TSDB_DATA_TYPE_INT:
      case TSDB_DATA_TYPE_BIGINT:
      case TSDB_DATA_TYPE_FLOAT:
      case TSDB_DATA_TYPE_DOUBLE:
      case TSDB_DATA_TYPE_VARCHAR:
      case TSDB_DATA_TYPE_TIMESTAMP:
      case TSDB_DATA_TYPE_NCHAR:
      case TSDB_DATA_TYPE_UTINYINT:
      case TSDB_DATA_TYPE_USMALLINT:
      case TSDB_DATA_TYPE_UINT:
      case TSDB_DATA_TYPE_UBIGINT:
      case TSDB_DATA_TYPE_JSON:
      case TSDB_DATA_TYPE_VARBINARY:
      case TSDB_DATA_TYPE_DECIMAL:
      case TSDB_DATA_TYPE_BLOB:
      case TSDB_DATA_TYPE_MEDIUMBLOB:
      default:
        break;
    }
61 62 63 64 65 66
  }
};

TEST_F(PlanStmtTest, stmt) {
  useDb("root", "test");

67
  prepare("SELECT * FROM t1 WHERE c1 = ?");
68
}