forked from jlucid/capi
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrowswithtime.c
48 lines (41 loc) · 1.04 KB
/
rowswithtime.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
/* File name: rowswithtime.c */
#include <time.h>
#include "common.h"
J castTime(struct tm *x) {
return (J)((60 * x->tm_hour + x->tm_min) * 60 + x->tm_sec) * 1000000000;
}
int main() {
J i, n= 3;
I handle;
I portnumber= 5010;
S hostname= "localhost";
K result;
S usernamePassword= "kdb:pass";
S symbols[]= { "ABC", "DEF", "GHI" };
time_t currentTime;
struct tm *ct;
handle= khpu(hostname, portnumber, usernamePassword);
if(!handleOk(handle)) {
m9();
return EXIT_FAILURE;
}
K multipleRow= knk(4, ktn(KN, n), ktn(KS, n), ktn(KF, n), ktn(KJ, n));
time(¤tTime);
ct= localtime(¤tTime);
for(i= 0; i < n; i++) {
kJ(kK(multipleRow)[0])[i]= castTime(ct);
kS(kK(multipleRow)[1])[i]= ss(symbols[i % n]);
kF(kK(multipleRow)[2])[i]= 10.0 * i;
kJ(kK(multipleRow)[3])[i]= i;
}
result= k(handle, ".u.upd", ks((S) "trade"), multipleRow, (K) 0);
if(isRemoteErr(result)) {
kclose(handle);
m9();
return EXIT_FAILURE;
}
r0(result);
kclose(handle);
m9();
return EXIT_SUCCESS;
}