openTSDBTest.c 34.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include "taoserror.h"
#include "cJSON.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <taos.h>
#include <unistd.h>

void verify_telnet_insert(TAOS* taos) {
  TAOS_RES *result;

  result = taos_query(taos, "drop database if exists db;");
  taos_free_result(result);
  usleep(100000);
  result = taos_query(taos, "create database db precision 'ms';");
  taos_free_result(result);
  usleep(100000);

  (void)taos_select_db(taos, "db");
  int32_t code = 0;

  /* metric */
  char* lines0[] = {
      "stb0_0 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
      "stb0_1 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
      "stb0_2 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
  };
G
Ganlin Zhao 已提交
29
  result = taos_schemaless_insert(taos, lines0, 3, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
30
  code = taos_errno(result);
31 32 33
  if (code) {
    printf("lines0 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
34
  taos_free_result(result);
35 36 37 38 39 40

  /* timestamp */
  char* lines1[] = {
      "stb1 1626006833s 1i8 host=\"host0\"",
      "stb1 1626006833639000000ns 2i8 host=\"host0\"",
      "stb1 1626006833640000us 3i8 host=\"host0\"",
41 42 43 44
      "stb1 1626006833641 4i8 host=\"host0\"",
      "stb1 1626006832 5i8 host=\"host0\"",
      "stb1 1626006833651ms 6i8 host=\"host0\"",
      "stb1 0 7i8 host=\"host0\"",
45
  };
G
Ganlin Zhao 已提交
46
  result = taos_schemaless_insert(taos, lines1, 7, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
47
  code = taos_errno(result);
48 49 50
  if (code) {
    printf("lines1 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
51
  taos_free_result(result);
52 53 54 55 56 57 58

  /* metric value */
  //tinyint
  char* lines2_0[] = {
      "stb2_0 1626006833651ms -127i8 host=\"host0\"",
      "stb2_0 1626006833652ms 127i8 host=\"host0\""
  };
G
Ganlin Zhao 已提交
59
  result = taos_schemaless_insert(taos, lines2_0, 2, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
60
  code = taos_errno(result);
61 62 63
  if (code) {
    printf("lines2_0 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
64
  taos_free_result(result);
65 66 67 68 69 70

  //smallint
  char* lines2_1[] = {
      "stb2_1 1626006833651ms -32767i16 host=\"host0\"",
      "stb2_1 1626006833652ms 32767i16 host=\"host0\""
  };
G
Ganlin Zhao 已提交
71
  result = taos_schemaless_insert(taos, lines2_1, 2, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
72
  code = taos_errno(result);
73 74 75
  if (code) {
    printf("lines2_1 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
76
  taos_free_result(result);
77 78 79 80 81 82

  //int
  char* lines2_2[] = {
      "stb2_2 1626006833651ms -2147483647i32 host=\"host0\"",
      "stb2_2 1626006833652ms 2147483647i32 host=\"host0\""
  };
G
Ganlin Zhao 已提交
83
  result = taos_schemaless_insert(taos, lines2_2, 2, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
84
  code = taos_errno(result);
85 86 87
  if (code) {
    printf("lines2_2 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
88
  taos_free_result(result);
89 90 91 92

  //bigint
  char* lines2_3[] = {
      "stb2_3 1626006833651ms -9223372036854775807i64 host=\"host0\"",
93
      "stb2_3 1626006833652ms 9223372036854775807i64 host=\"host0\""
94
  };
G
Ganlin Zhao 已提交
95
  result = taos_schemaless_insert(taos, lines2_3, 2, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
96
  code = taos_errno(result);
97 98 99
  if (code) {
    printf("lines2_3 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
100
  taos_free_result(result);
101 102 103 104 105 106 107 108 109 110 111 112 113 114

  //float
  char* lines2_4[] = {
      "stb2_4 1626006833610ms 3f32 host=\"host0\"",
      "stb2_4 1626006833620ms -3f32 host=\"host0\"",
      "stb2_4 1626006833630ms 3.4f32 host=\"host0\"",
      "stb2_4 1626006833640ms -3.4f32 host=\"host0\"",
      "stb2_4 1626006833650ms 3.4E10f32 host=\"host0\"",
      "stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"",
      "stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"",
      "stb2_4 1626006833680ms -3.4e-2f32 host=\"host0\"",
      "stb2_4 1626006833700ms 3.4E38f32 host=\"host0\"",
      "stb2_4 1626006833710ms -3.4E38f32 host=\"host0\""
  };
G
Ganlin Zhao 已提交
115
  result = taos_schemaless_insert(taos, lines2_4, 10, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
116
  code = taos_errno(result);
117 118 119
  if (code) {
    printf("lines2_4 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
120
  taos_free_result(result);
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

  //double
  char* lines2_5[] = {
      "stb2_5 1626006833610ms 3f64 host=\"host0\"",
      "stb2_5 1626006833620ms -3f64 host=\"host0\"",
      "stb2_5 1626006833630ms 3.4f64 host=\"host0\"",
      "stb2_5 1626006833640ms -3.4f64 host=\"host0\"",
      "stb2_5 1626006833650ms 3.4E10f64 host=\"host0\"",
      "stb2_5 1626006833660ms -3.4e10f64 host=\"host0\"",
      "stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"",
      "stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"",
      "stb2_5 1626006833690ms 1.7E308f64 host=\"host0\"",
      "stb2_5 1626006833700ms -1.7E308f64 host=\"host0\"",
      "stb2_5 1626006833710ms 3.15 host=\"host0\""
  };
G
Ganlin Zhao 已提交
136
  result = taos_schemaless_insert(taos, lines2_5, 11, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
137
  code = taos_errno(result);
138 139 140
  if (code) {
    printf("lines2_5 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
141
  taos_free_result(result);
142 143 144 145 146 147 148 149 150 151 152 153 154 155

  //bool
  char* lines2_6[] = {
      "stb2_6 1626006833610ms t host=\"host0\"",
      "stb2_6 1626006833620ms T host=\"host0\"",
      "stb2_6 1626006833630ms true host=\"host0\"",
      "stb2_6 1626006833640ms True host=\"host0\"",
      "stb2_6 1626006833650ms TRUE host=\"host0\"",
      "stb2_6 1626006833660ms f host=\"host0\"",
      "stb2_6 1626006833670ms F host=\"host0\"",
      "stb2_6 1626006833680ms false host=\"host0\"",
      "stb2_6 1626006833690ms False host=\"host0\"",
      "stb2_6 1626006833700ms FALSE host=\"host0\""
  };
G
Ganlin Zhao 已提交
156
  result = taos_schemaless_insert(taos, lines2_6, 10, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
157
  code = taos_errno(result);
158 159 160
  if (code) {
    printf("lines2_6 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
161
  taos_free_result(result);
162 163 164 165 166 167 168

  //binary
  char* lines2_7[] = {
      "stb2_7 1626006833610ms \"binary_val.!@#$%^&*\" host=\"host0\"",
      "stb2_7 1626006833620ms \"binary_val.:;,./?|+-=\" host=\"host0\"",
      "stb2_7 1626006833630ms \"binary_val.()[]{}<>\" host=\"host0\""
  };
G
Ganlin Zhao 已提交
169
  result = taos_schemaless_insert(taos, lines2_7, 3, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
170
  code = taos_errno(result);
171 172 173
  if (code) {
    printf("lines2_7 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
174
  taos_free_result(result);
175 176 177 178 179 180

  //nchar
  char* lines2_8[] = {
      "stb2_8 1626006833610ms L\"nchar_val数值一\" host=\"host0\"",
      "stb2_8 1626006833620ms L\"nchar_val数值二\" host=\"host0\""
  };
G
Ganlin Zhao 已提交
181
  result = taos_schemaless_insert(taos, lines2_8, 2, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
182
  code = taos_errno(result);
183 184 185
  if (code) {
    printf("lines2_8 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
186
  taos_free_result(result);
187 188 189 190 191 192 193

  /* tags */
  //tag value types
  char* lines3_0[] = {
      "stb3_0 1626006833610ms 1 t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=3.4E38f32 t6=1.7E308f64 t7=true t8=\"binary_val_1\" t9=L\"标签值1\"",
      "stb3_0 1626006833610ms 2 t1=-127i8 t2=-32767i16 t3=-2147483647i32 t4=-9223372036854775807i64 t5=-3.4E38f32 t6=-1.7E308f64 t7=false t8=\"binary_val_2\" t9=L\"标签值2\""
  };
G
Ganlin Zhao 已提交
194
  result = taos_schemaless_insert(taos, lines3_0, 2, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
195
  code = taos_errno(result);
196 197 198
  if (code) {
    printf("lines3_0 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
199
  taos_free_result(result);
200 201 202

  //tag ID as child table name
  char* lines3_1[] = {
203 204 205
      "stb3_1 1626006833610ms 1 id=child_table1 host=host1",
      "stb3_1 1626006833610ms 2 host=host2 iD=child_table2",
      "stb3_1 1626006833610ms 3 ID=child_table3 host=host3"
206
  };
G
Ganlin Zhao 已提交
207
  result = taos_schemaless_insert(taos, lines3_1, 3, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
208
  code = taos_errno(result);
209 210 211
  if (code) {
    printf("lines3_1 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
212
  taos_free_result(result);
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229

  return;
}

void verify_json_insert(TAOS* taos) {
  TAOS_RES *result;

  result = taos_query(taos, "drop database if exists db;");
  taos_free_result(result);
  usleep(100000);
  result = taos_query(taos, "create database db precision 'ms';");
  taos_free_result(result);
  usleep(100000);

  (void)taos_select_db(taos, "db");
  int32_t code = 0;

230
  char *message[] = {
231 232
  "{                                      \
      \"metric\":\"cpu_load_0\",          \
233
      \"timestamp\": 1626006833610,       \
234 235 236 237 238 239 240
      \"value\": 55.5,                    \
      \"tags\":                           \
          {                               \
              \"host\": \"ubuntu\",       \
              \"interface1\": \"eth0\",   \
              \"Id\": \"tb0\"             \
          }                               \
241
  }"};
242

G
Ganlin Zhao 已提交
243
  result = taos_schemaless_insert(taos, message, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
244
  code = taos_errno(result);
245 246 247
  if (code) {
    printf("payload_0 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
248
  taos_free_result(result);
249

250
  char *message1[] = {
251 252 253
  "[                                       \
    {                                      \
       \"metric\":\"cpu_load_1\",          \
254
       \"timestamp\": 1626006833610,       \
255 256 257 258 259 260 261 262 263 264
       \"value\": 55.5,                    \
       \"tags\":                           \
           {                               \
               \"host\": \"ubuntu\",       \
               \"interface\": \"eth1\",    \
               \"Id\": \"tb1\"             \
           }                               \
    },                                     \
    {                                      \
       \"metric\":\"cpu_load_2\",          \
265
       \"timestamp\": 1626006833610,       \
266 267 268 269 270 271 272 273
       \"value\": 55.5,                    \
       \"tags\":                           \
           {                               \
               \"host\": \"ubuntu\",       \
               \"interface\": \"eth2\",    \
               \"Id\": \"tb2\"             \
           }                               \
    }                                      \
274
   ]"};
275

G
Ganlin Zhao 已提交
276
  result = taos_schemaless_insert(taos, message1, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
277
  code = taos_errno(result);
278 279 280
  if (code) {
    printf("payload_1 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
281
  taos_free_result(result);
282

283
  char *message2[] = {
284 285 286 287 288
  "[                                       \
    {                                      \
       \"metric\":\"cpu_load_3\",          \
       \"timestamp\":                      \
           {                               \
289 290
             \"value\": 1626006833610,     \
             \"type\": \"ms\"              \
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
           },                              \
       \"value\":                          \
           {                               \
             \"value\": 55,                \
             \"type\": \"int\"             \
           },                              \
       \"tags\":                           \
           {                               \
               \"host\":                   \
                  {                        \
                    \"value\": \"ubuntu\", \
                    \"type\": \"binary\"   \
                  },                       \
               \"interface\":              \
                  {                        \
                    \"value\": \"eth3\",   \
                    \"type\": \"nchar\"    \
                  },                       \
               \"ID\": \"tb3\",            \
               \"port\":                   \
                  {                        \
                    \"value\": 4040,       \
                    \"type\": \"int\"      \
                  }                        \
           }                               \
    },                                     \
    {                                      \
       \"metric\":\"cpu_load_4\",          \
319
       \"timestamp\": 1626006833610,       \
320 321 322 323 324 325 326 327
       \"value\": 66.6,                    \
       \"tags\":                           \
           {                               \
               \"host\": \"ubuntu\",       \
               \"interface\": \"eth4\",    \
               \"Id\": \"tb4\"             \
           }                               \
    }                                      \
328
   ]"};
G
Ganlin Zhao 已提交
329
  result = taos_schemaless_insert(taos, message2, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
330
  code = taos_errno(result);
331 332 333
  if (code) {
    printf("payload_2 code: %d, %s.\n", code, tstrerror(code));
  }
G
Ganlin Zhao 已提交
334
  taos_free_result(result);
335 336 337


  cJSON *payload, *tags;
338
  char *payload_str[1];
339 340 341 342 343

  /* Default format */
  //number
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb0_0");
344
  cJSON_AddNumberToObject(payload, "timestamp", 1626006833610);
345 346 347 348 349 350 351
  cJSON_AddNumberToObject(payload, "value", 10);
  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
352
  *payload_str = cJSON_Print(payload);
353 354
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
355
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
356
  code = taos_errno(result);
357 358 359
  if (code) {
    printf("payload0_0 code: %d, %s.\n", code, tstrerror(code));
  }
360
  free(*payload_str);
361
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
362
  taos_free_result(result);
363 364 365 366

  //true
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb0_1");
367
  cJSON_AddNumberToObject(payload, "timestamp", 1626006833610);
368 369 370 371 372 373 374
  cJSON_AddTrueToObject(payload, "value");
  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
375
  *payload_str = cJSON_Print(payload);
376 377
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
378
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
379
  code = taos_errno(result);
380 381 382
  if (code) {
    printf("payload0_1 code: %d, %s.\n", code, tstrerror(code));
  }
383
  free(*payload_str);
384
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
385
  taos_free_result(result);
386 387 388 389

  //false
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb0_2");
390
  cJSON_AddNumberToObject(payload, "timestamp", 1626006833610);
391 392 393 394 395 396 397
  cJSON_AddFalseToObject(payload, "value");
  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
398
  *payload_str = cJSON_Print(payload);
399 400
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
401
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
402
  code = taos_errno(result);
403 404 405
  if (code) {
    printf("payload0_2 code: %d, %s.\n", code, tstrerror(code));
  }
406
  free(*payload_str);
407
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
408
  taos_free_result(result);
409 410 411 412

  //string
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb0_3");
413
  cJSON_AddNumberToObject(payload, "timestamp", 1626006833610);
414 415 416 417 418 419 420
  cJSON_AddStringToObject(payload, "value", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
421
  *payload_str = cJSON_Print(payload);
422 423
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
424
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
425
  code = taos_errno(result);
426 427 428
  if (code) {
    printf("payload0_3 code: %d, %s.\n", code, tstrerror(code));
  }
429
  free(*payload_str);
430
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
431
  taos_free_result(result);
432 433 434 435 436 437 438 439 440 441 442 443

  //timestamp 0 -> current time
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb0_4");
  cJSON_AddNumberToObject(payload, "timestamp", 0);
  cJSON_AddNumberToObject(payload, "value", 123);
  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
444
  *payload_str = cJSON_Print(payload);
445 446
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
447
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
448
  code = taos_errno(result);
449 450 451
  if (code) {
    printf("payload0_4 code: %d, %s.\n", code, tstrerror(code));
  }
452
  free(*payload_str);
453
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
454
  taos_free_result(result);
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474

  /* Nested format */
  //timestamp
  cJSON *timestamp;
  //seconds
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb1_0");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833);
  cJSON_AddStringToObject(timestamp, "type", "s");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  cJSON_AddNumberToObject(payload, "value", 10);
  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
475
  *payload_str = cJSON_Print(payload);
476 477
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
478
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
479
  code = taos_errno(result);
480 481 482
  if (code) {
    printf("payload1_0 code: %d, %s.\n", code, tstrerror(code));
  }
483
  free(*payload_str);
484
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
485
  taos_free_result(result);
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502

  //milleseconds
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb1_1");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833610);
  cJSON_AddStringToObject(timestamp, "type", "ms");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  cJSON_AddNumberToObject(payload, "value", 10);
  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
503
  *payload_str = cJSON_Print(payload);
504 505
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
506
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
507
  code = taos_errno(result);
508 509 510
  if (code) {
    printf("payload1_1 code: %d, %s.\n", code, tstrerror(code));
  }
511
  free(*payload_str);
512
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
513
  taos_free_result(result);
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530

  //microseconds
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb1_2");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833610123);
  cJSON_AddStringToObject(timestamp, "type", "us");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  cJSON_AddNumberToObject(payload, "value", 10);
  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
531
  *payload_str = cJSON_Print(payload);
532 533
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
534
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
535
  code = taos_errno(result);
536 537 538
  if (code) {
    printf("payload1_2 code: %d, %s.\n", code, tstrerror(code));
  }
539
  free(*payload_str);
540
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
541
  taos_free_result(result);
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558

  //now
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb1_4");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 0);
  cJSON_AddStringToObject(timestamp, "type", "ns");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  cJSON_AddNumberToObject(payload, "value", 10);
  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
559
  *payload_str = cJSON_Print(payload);
560 561
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
562
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
563
  code = taos_errno(result);
564 565 566
  if (code) {
    printf("payload1_4 code: %d, %s.\n", code, tstrerror(code));
  }
567
  free(*payload_str);
568
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
569
  taos_free_result(result);
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592

  //metric value
  cJSON *metric_val;
  //bool
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb2_0");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833);
  cJSON_AddStringToObject(timestamp, "type", "s");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  metric_val = cJSON_CreateObject();
  cJSON_AddTrueToObject(metric_val, "value");
  cJSON_AddStringToObject(metric_val, "type", "bool");
  cJSON_AddItemToObject(payload, "value", metric_val);

  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
593
  *payload_str = cJSON_Print(payload);
594 595
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
596
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
597
  code = taos_errno(result);
598 599 600
  if (code) {
    printf("payload2_0 code: %d, %s.\n", code, tstrerror(code));
  }
601
  free(*payload_str);
602
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
603
  taos_free_result(result);
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624

  //tinyint
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb2_1");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833);
  cJSON_AddStringToObject(timestamp, "type", "s");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  metric_val = cJSON_CreateObject();
  cJSON_AddNumberToObject(metric_val, "value", 127);
  cJSON_AddStringToObject(metric_val, "type", "tinyint");
  cJSON_AddItemToObject(payload, "value", metric_val);

  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
625
  *payload_str = cJSON_Print(payload);
626 627
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
628
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
629
  code = taos_errno(result);
630 631 632
  if (code) {
    printf("payload2_1 code: %d, %s.\n", code, tstrerror(code));
  }
633
  free(*payload_str);
634
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
635
  taos_free_result(result);
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656

  //smallint
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb2_2");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833);
  cJSON_AddStringToObject(timestamp, "type", "s");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  metric_val = cJSON_CreateObject();
  cJSON_AddNumberToObject(metric_val, "value", 32767);
  cJSON_AddStringToObject(metric_val, "type", "smallint");
  cJSON_AddItemToObject(payload, "value", metric_val);

  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
657
  *payload_str = cJSON_Print(payload);
658 659
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
660
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
661
  code = taos_errno(result);
662 663 664
  if (code) {
    printf("payload2_2 code: %d, %s.\n", code, tstrerror(code));
  }
665
  free(*payload_str);
666
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
667
  taos_free_result(result);
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688

  //int
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb2_3");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833);
  cJSON_AddStringToObject(timestamp, "type", "s");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  metric_val = cJSON_CreateObject();
  cJSON_AddNumberToObject(metric_val, "value", 2147483647);
  cJSON_AddStringToObject(metric_val, "type", "int");
  cJSON_AddItemToObject(payload, "value", metric_val);

  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
689
  *payload_str = cJSON_Print(payload);
690 691
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
692
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
693
  code = taos_errno(result);
694 695 696
  if (code) {
    printf("payload2_3 code: %d, %s.\n", code, tstrerror(code));
  }
697
  free(*payload_str);
698
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
699
  taos_free_result(result);
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720

  //bigint
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb2_4");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833);
  cJSON_AddStringToObject(timestamp, "type", "s");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  metric_val = cJSON_CreateObject();
  cJSON_AddNumberToObject(metric_val, "value", (double)9223372036854775807);
  cJSON_AddStringToObject(metric_val, "type", "bigint");
  cJSON_AddItemToObject(payload, "value", metric_val);

  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
721
  *payload_str = cJSON_Print(payload);
722 723
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
724
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
725
  code = taos_errno(result);
726 727 728
  if (code) {
    printf("payload2_4 code: %d, %s.\n", code, tstrerror(code));
  }
729
  free(*payload_str);
730
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
731
  taos_free_result(result);
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752

  //float
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb2_5");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833);
  cJSON_AddStringToObject(timestamp, "type", "s");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  metric_val = cJSON_CreateObject();
  cJSON_AddNumberToObject(metric_val, "value", 11.12345);
  cJSON_AddStringToObject(metric_val, "type", "float");
  cJSON_AddItemToObject(payload, "value", metric_val);

  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
753
  *payload_str = cJSON_Print(payload);
754 755
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
756
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
757
  code = taos_errno(result);
758 759 760
  if (code) {
    printf("payload2_5 code: %d, %s.\n", code, tstrerror(code));
  }
761
  free(*payload_str);
762
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
763
  taos_free_result(result);
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784

  //double
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb2_6");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833);
  cJSON_AddStringToObject(timestamp, "type", "s");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  metric_val = cJSON_CreateObject();
  cJSON_AddNumberToObject(metric_val, "value", 22.123456789);
  cJSON_AddStringToObject(metric_val, "type", "double");
  cJSON_AddItemToObject(payload, "value", metric_val);

  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
785
  *payload_str = cJSON_Print(payload);
786 787
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
788
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
789
  code = taos_errno(result);
790 791 792
  if (code) {
    printf("payload2_6 code: %d, %s.\n", code, tstrerror(code));
  }
793
  free(*payload_str);
794
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
795
  taos_free_result(result);
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816

  //binary
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb2_7");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833);
  cJSON_AddStringToObject(timestamp, "type", "s");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  metric_val = cJSON_CreateObject();
  cJSON_AddStringToObject(metric_val, "value", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddStringToObject(metric_val, "type", "binary");
  cJSON_AddItemToObject(payload, "value", metric_val);

  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
817
  *payload_str = cJSON_Print(payload);
818 819
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
820
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
821
  code = taos_errno(result);
822 823 824
  if (code) {
    printf("payload2_7 code: %d, %s.\n", code, tstrerror(code));
  }
825
  free(*payload_str);
826
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
827
  taos_free_result(result);
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848

  //nchar
  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb2_8");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833);
  cJSON_AddStringToObject(timestamp, "type", "s");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  metric_val = cJSON_CreateObject();
  cJSON_AddStringToObject(metric_val, "value", "你好");
  cJSON_AddStringToObject(metric_val, "type", "nchar");
  cJSON_AddItemToObject(payload, "value", metric_val);

  tags = cJSON_CreateObject();
  cJSON_AddTrueToObject(tags, "t1");
  cJSON_AddFalseToObject(tags, "t2");
  cJSON_AddNumberToObject(tags, "t3", 10);
  cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>");
  cJSON_AddItemToObject(payload, "tags", tags);
849
  *payload_str = cJSON_Print(payload);
850 851
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
852
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
853
  code = taos_errno(result);
854 855 856
  if (code) {
    printf("payload2_8 code: %d, %s.\n", code, tstrerror(code));
  }
857
  free(*payload_str);
858
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
859
  taos_free_result(result);
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930

  //tag value
  cJSON *tag;

  payload = cJSON_CreateObject();
  cJSON_AddStringToObject(payload, "metric", "stb3_0");

  timestamp = cJSON_CreateObject();
  cJSON_AddNumberToObject(timestamp, "value", 1626006833);
  cJSON_AddStringToObject(timestamp, "type", "s");
  cJSON_AddItemToObject(payload, "timestamp", timestamp);

  metric_val = cJSON_CreateObject();
  cJSON_AddStringToObject(metric_val, "value", "hello");
  cJSON_AddStringToObject(metric_val, "type", "nchar");
  cJSON_AddItemToObject(payload, "value", metric_val);

  tags = cJSON_CreateObject();

  tag = cJSON_CreateObject();
  cJSON_AddTrueToObject(tag, "value");
  cJSON_AddStringToObject(tag, "type", "bool");
  cJSON_AddItemToObject(tags, "t1", tag);

  tag = cJSON_CreateObject();
  cJSON_AddFalseToObject(tag, "value");
  cJSON_AddStringToObject(tag, "type", "bool");
  cJSON_AddItemToObject(tags, "t2", tag);

  tag = cJSON_CreateObject();
  cJSON_AddNumberToObject(tag, "value", 127);
  cJSON_AddStringToObject(tag, "type", "tinyint");
  cJSON_AddItemToObject(tags, "t3", tag);

  tag = cJSON_CreateObject();
  cJSON_AddNumberToObject(tag, "value", 32767);
  cJSON_AddStringToObject(tag, "type", "smallint");
  cJSON_AddItemToObject(tags, "t4", tag);

  tag = cJSON_CreateObject();
  cJSON_AddNumberToObject(tag, "value", 2147483647);
  cJSON_AddStringToObject(tag, "type", "int");
  cJSON_AddItemToObject(tags, "t5", tag);

  tag = cJSON_CreateObject();
  cJSON_AddNumberToObject(tag, "value", (double)9223372036854775807);
  cJSON_AddStringToObject(tag, "type", "bigint");
  cJSON_AddItemToObject(tags, "t6", tag);

  tag = cJSON_CreateObject();
  cJSON_AddNumberToObject(tag, "value", 11.12345);
  cJSON_AddStringToObject(tag, "type", "float");
  cJSON_AddItemToObject(tags, "t7", tag);

  tag = cJSON_CreateObject();
  cJSON_AddNumberToObject(tag, "value", 22.1234567890);
  cJSON_AddStringToObject(tag, "type", "double");
  cJSON_AddItemToObject(tags, "t8", tag);

  tag = cJSON_CreateObject();
  cJSON_AddStringToObject(tag, "value", "binary_val");
  cJSON_AddStringToObject(tag, "type", "binary");
  cJSON_AddItemToObject(tags, "t9", tag);

  tag = cJSON_CreateObject();
  cJSON_AddStringToObject(tag, "value", "你好");
  cJSON_AddStringToObject(tag, "type", "nchar");
  cJSON_AddItemToObject(tags, "t10", tag);

  cJSON_AddItemToObject(payload, "tags", tags);

931
  *payload_str = cJSON_Print(payload);
932 933
  //printf("%s\n", payload_str);

G
Ganlin Zhao 已提交
934
  result = taos_schemaless_insert(taos, payload_str, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
G
Ganlin Zhao 已提交
935
  code = taos_errno(result);
936 937 938
  if (code) {
    printf("payload3_0 code: %d, %s.\n", code, tstrerror(code));
  }
939
  free(*payload_str);
940
  cJSON_Delete(payload);
G
Ganlin Zhao 已提交
941
  taos_free_result(result);
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
}

int main(int argc, char *argv[]) {
  const char* host = "127.0.0.1";
  const char* user = "root";
  const char* passwd = "taosdata";

  taos_options(TSDB_OPTION_TIMEZONE, "GMT-8");
  TAOS* taos = taos_connect(host, user, passwd, "", 0);
  if (taos == NULL) {
    printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos));
    exit(1);
  }

  char* info = taos_get_server_info(taos);
  printf("server info: %s\n", info);
  info = taos_get_client_info(taos);
  printf("client info: %s\n", info);

  printf("************  verify telnet-insert  *************\n");
  verify_telnet_insert(taos);

  printf("************  verify json-insert  *************\n");
  verify_json_insert(taos);

  printf("done\n");
  taos_close(taos);
  taos_cleanup();
}