-
Notifications
You must be signed in to change notification settings - Fork 0
/
clib.c
97 lines (72 loc) · 1.98 KB
/
clib.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
94
95
96
97
#include <FBCAccess/FBCAccess.h>
#include <stdio.h>
#include <stdlib.h>
#include "clib.h"
FBCDatabaseConnection *GoFBOpen(const char *url) {
FBCMetaData *md = fbcdcConnectToURL(url,"","_system","","sid");
if (fbcmdErrorsFound(md)) {
fprintf(stderr, "%s: open failed\n", url);
fbcmdRelease(md);
return NULL;
}
FBCDatabaseConnection *connection = fbcdcRetain(fbcmdDatabaseConnection(md));
fbcmdRelease(md);
fbcdcSetFormatResult(connection, 0);
return connection;
}
void GoFBClose(FBCDatabaseConnection *connection) {
if (connection == NULL) return;
fbcdcClose(connection);
fbcdcRelease(connection);
}
int GoFBPing(FBCDatabaseConnection *connection) {
if (connection == NULL) return 0;
const char *url = fbcdcURL(connection);
if (url == NULL) url = "???";
fprintf(stderr, "%s: ping\n", url);
return fbcdcConnected(connection);
}
FBCColumn *GoFBColumnAtIndex(FBCRow *row, unsigned int i) {
return row[i];
}
uint8_t GoFBColumnValueBool(FBCColumn *col) {
return col->boolean;
}
int8_t GoFBColumnValueTinyInt(FBCColumn *col) {
return col->tinyInteger;
}
int16_t GoFBColumnValueSmallInt(FBCColumn *col) {
return col->shortInteger;
}
int32_t GoFBColumnValueInt(FBCColumn *col) {
return col->integer;
}
int64_t GoFBColumnValueLongInt(FBCColumn *col) {
return col->longInteger;
}
double GoFBColumnValueDouble(FBCColumn *col) {
return col->real;
}
double GoFBColumnValueDecimal(FBCColumn *col) {
return col->decimal;
}
char *GoFBColumnValueChar(FBCColumn *col) {
return col->character;
}
unsigned char *GoFBColumnValueBit(FBCColumn *col) {
return col->bit.bytes;
}
int GoFBColumnSizeBit(FBCColumn *col) {
return col->bit.size;
}
void GoFBColumnValueTimestamp(FBCColumn *col, struct GoFBTimestampValue *res) {
if (res == NULL) return;
double secs = col->rawTimestamp.seconds;
res->secs = (int64_t)secs;
double fraction = secs - res->secs;
res->nsecs = (int64_t)(fraction * 1000000000.0);
res->secs += 978307200;
if (res->nsecs < 0) {
res->nsecs = 1000000000 + res->nsecs;
}
}