-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_bridge_import.c
94 lines (83 loc) · 1.86 KB
/
test_bridge_import.c
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
29
30
31
32
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*-------------------------------------------------------------------------
*
* test_bridge_import.c
* Test program for bridge.c for importing
*
* Portions Copyright (c) 2016, Mitsunori Komatsu
*
* IDENTIFICATION
* test_bridge_import.c
*
*-------------------------------------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "bridge.h"
/* For testing */
int main(int argc, char* argv[])
{
int ret;
char* apikey = NULL;
char* database = NULL;
char* table = NULL;
int colsize = 0;
char* coltypes = NULL;
char* colnames = NULL;
char* endpoint = NULL;
char** column_types = NULL;
char** column_names = NULL;
void* td_import_state = NULL;
int i;
char* token;
if (argc < 7)
{
printf("usage: %s apikey database table colsize coltypes colnames [endpoint]\n", argv[0]);
return 1;
}
apikey = argv[1];
database = argv[2];
table = argv[3];
colsize = atoi(argv[4]);
coltypes = argv[5];
colnames = argv[6];
if (argc >= 8)
{
endpoint = argv[7];
}
column_types = (char **) malloc(sizeof(char *) * colsize);
i = 0;
token = strtok(coltypes, ",");
while (token != NULL)
{
column_types[i] = malloc(64);
strcpy(column_types[i], token);
i++;
token = strtok(NULL, ",");
}
column_names = (char **) malloc(sizeof(char *) * colsize);
i = 0;
token = strtok(colnames, ",");
while (token != NULL)
{
column_names[i] = malloc(64);
strcpy(column_names[i], token);
i++;
token = strtok(NULL, ",");
}
td_import_state = importBegin(
apikey,
endpoint,
database,
table,
colsize,
column_types,
column_names);
if (td_import_state == NULL)
{
printf("Failed to begin import\n");
return 1;
}
return 0;
}