forked from jlucid/capi
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathschema.c
53 lines (49 loc) · 1.32 KB
/
schema.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
/* File name: schema.c */
#include "common.h"
int main() {
J i;
I handle;
I portnumber= 5010;
S hostname= "localhost";
S usernamePassword= "kdb:pass";
K response, table, columnNames;
handle= khpu(hostname, portnumber, usernamePassword);
if(!handleOk(handle)) {
m9();
return EXIT_FAILURE;
}
response= k(handle, ".u.sub[`trade;`]", (K) 0);
if(isRemoteErr(response)) {
kclose(handle);
m9();
return EXIT_FAILURE;
}
// .u.sub returns a two element list
// containing the table name and schema
// q)h:hopen 5010
// q)h".u.sub[`trade;`]"
// `trade
// +`time`sym`price`size!(();();();())
if(response->t != 0 || response->n != 2 || kK(response)[0]->t != -KS ||
kK(response)[1]->t != XT) {
fprintf(stderr,
"Subscription response is of unknown shape. Top level type is %d\n",
response->t);
r0(response);
kclose(handle);
m9();
return EXIT_FAILURE;
}
printf("Number of elements returned is %lld\n", response->n);
printf("Table name: %s\n", kK(response)[0]->s);
table= kK(response)[1]->k;
columnNames= kK(table)[0];
printf("Num colNames: %lld\n", columnNames->n);
for(i= 0; i < columnNames->n; i++) {
printf("Column %lld is named %s\n", i, kS(columnNames)[i]);
}
r0(response);
kclose(handle);
m9();
return EXIT_SUCCESS;
}