tvariant.h 1.6 KB
Newer Older
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/>.
 */

S
Shengliang Guan 已提交
16 17 18 19
#ifndef _TD_COMMON_VARIANT_H_
#define _TD_COMMON_VARIANT_H_

#include "tarray.h"
H
hzcheng 已提交
20

21 22 23 24 25
#ifdef __cplusplus
extern "C" {
#endif

// variant, each number/string/field_id has a corresponding struct during parsing sql
H
Haojun Liao 已提交
26
typedef struct SVariant {
S
Shengliang Guan 已提交
27 28
  uint32_t nType;
  int32_t  nLen;  // only used for string, for number, it is useless
29
  union {
30 31
    int64_t  i;
    uint64_t u;
H
Haojun Liao 已提交
32 33
    double   d;
    char    *pz;
wafwerar's avatar
wafwerar 已提交
34
    TdUcs4  *ucs4;
S
Shengliang Guan 已提交
35
    SArray  *arr;  // only for 'in' query to hold value list, not value for a field
36
  };
H
Haojun Liao 已提交
37
} SVariant;
38

X
Xiaoyu Wang 已提交
39 40
int32_t toInteger(const char *z, int32_t n, int32_t base, int64_t *value);
int32_t toUInteger(const char *z, int32_t n, int32_t base, uint64_t *value);
41

H
Haojun Liao 已提交
42
void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type);
43

H
Haojun Liao 已提交
44
void taosVariantDestroy(SVariant *pV);
45

H
Haojun Liao 已提交
46
void taosVariantAssign(SVariant *pDst, const SVariant *pSrc);
47

S
Shengliang Guan 已提交
48
int32_t taosVariantCompare(const SVariant *p1, const SVariant *p2);
49

X
Xiaoyu Wang 已提交
50
char   *taosVariantGet(SVariant *pVar, int32_t type);
51 52 53 54 55

#ifdef __cplusplus
}
#endif

X
Xiaoyu Wang 已提交
56
#endif /*_TD_COMMON_VARIANT_H_*/