tvariant.h 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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/>.
 */

#ifndef TDENGINE_TVARIANT_H
#define TDENGINE_TVARIANT_H

weixin_48148422's avatar
weixin_48148422 已提交
19
#include "tarray.h"
20
#include "ttoken.h"
H
hzcheng 已提交
21

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

// variant, each number/string/field_id has a corresponding struct during parsing sql
typedef struct tVariant {
28
  int32_t nType;      // change uint to int, because in tVariantCreate() pVar->nType = -1;   // -1 means error type
29 30
  int32_t  nLen;  // only used for string, for number, it is useless
  union {
31 32
    int64_t  i64;
    uint64_t u64;
33 34 35
    double   dKey;
    char *   pz;
    wchar_t *wpz;
weixin_48148422's avatar
weixin_48148422 已提交
36
    SArray  *arr; // only for 'in' query to hold value list, not value for a field
37 38 39
  };
} tVariant;

40
bool tVariantIsValid(tVariant *pVar);
41

42 43 44
void tVariantCreate(tVariant *pVar, SStrToken *token);

void tVariantCreateExt(tVariant *pVar, SStrToken *token, int32_t optrType, bool needRmquoteEscape);
45

46
void tVariantCreateFromBinary(tVariant *pVar, const char *pz, size_t len, uint32_t type);
47 48 49 50 51

void tVariantDestroy(tVariant *pV);

void tVariantAssign(tVariant *pDst, const tVariant *pSrc);

52 53
int32_t tVariantCompare(const tVariant* p1, const tVariant* p2);

54 55
int32_t tVariantToString(tVariant *pVar, char *dst);

56
int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix);
57

W
wpan 已提交
58 59
int32_t tVariantDumpEx(tVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix, bool *converted, char *extInfo);

60 61 62 63 64 65 66
int32_t tVariantTypeSetType(tVariant *pVariant, char type);

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_TVARIANT_H