forked from nezroy/sdd2json
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsta.c
More file actions
250 lines (220 loc) · 9.33 KB
/
Copy pathsta.c
File metadata and controls
250 lines (220 loc) · 9.33 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#include <stdio.h>
#include <string.h>
#include "compat.h"
#include <sql.h>
#include <sqlext.h>
#include "sdd2json.h"
// all tables this creates
unsigned int create_staServices(const char*, FILE*, FILE*);
unsigned int create_staOperations(const char*, FILE*, FILE*);
unsigned int create_staStationTypes(const char*, FILE*, FILE*);
unsigned int create_staStations(const char*, FILE*, FILE*);
unsigned int create_sta(FILE *mf) {
int rc;
char *src;
FILE *f = NULL;
// staData
src = "staData";
if (!(f = open_datafile(src))) return 1;
rc = create_staServices(src, mf, f); if (0 != rc) return rc;
TBLSEP(f, mf); rc = create_staOperations(src, mf, f); if (0 != rc) return rc;
TBLSEP(f, mf); rc = create_staStationTypes(src, mf, f); if (0 != rc) return rc;
TBLSEP(f, mf); rc = create_staStations(src, mf, f); if (0 != rc) return rc;
if (close_datafile(src, f)) return 1;
return 0;
}
unsigned int create_staServices(const char *j, FILE *mf, FILE *f) {
const char *tbl = "staServices";
SQLRETURN rc;
SQLHSTMT stmt;
unsigned int count = 0;
char txtbuf[1001];
// meta
fprintf(mf, "\"%s\":{\n", tbl);
fprintf(mf, "\"j\":\"%s\",\n", j);
fprintf(mf, "\"c\":[\"serviceName\",\"description\"],\n");
fprintf(mf, "\"k\":\"serviceID\",\n");
fprintf(mf, "\"t\":\"sql\",\n");
// data
fprintf(f, "\"%s\":{\n", tbl);
fprintf(f, "\"d\":{\n");
rc = SQLAllocHandle(SQL_HANDLE_STMT, H_DBC, &stmt);
if (!SQL_SUCCEEDED(rc)) return dump_sql_error(rc, SQL_HANDLE_DBC, H_DBC, 1);
rc = SQLExecDirect(stmt, "SELECT * FROM staServices ORDER BY serviceID", SQL_NTS);
if (!SQL_SUCCEEDED(rc)) return dump_sql_error(rc, SQL_HANDLE_STMT, stmt, 1);
rc = SQLFetch(stmt);
while (SQL_SUCCEEDED(rc)) {
fprintf(f, "\"%ld\":[", sql_column_long(stmt, 0));
sql_column_text(txtbuf, stmt, 1, 101);
fprintf(f, "\"%s\",", txtbuf); // serviceName
sql_column_text(txtbuf, stmt, 2, 1001);
fprintf(f, "\"%s\"", txtbuf); // description
rc = SQLFetch(stmt);
if (SQL_SUCCEEDED(rc)) fprintf(f, "],\n");
else fprintf(f, "]\n");
count++;
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
fprintf(f, "}\n}");
fprintf(mf, "\"l\":%u\n}", count);
return 0;
}
unsigned int create_staOperations(const char *j, FILE *mf, FILE *f) {
const char *tbl = "staOperations";
SQLRETURN rc;
SQLHSTMT stmt;
SQLHSTMT substmt;
SQLINTEGER activityID;
SQLINTEGER operationID;
unsigned int count = 0;
char txtbuf[1001];
char sql[BUFLEN] = NULLSTR;
// meta
fprintf(mf, "\"%s\":{\n", tbl);
fprintf(mf, "\"j\":\"%s\",\n", j);
fprintf(mf, "\"c\":[\"activityID\",\"operationName\",\"decsription\",\"fringe\",\"corridor\",\"hub\",\"border\",\"ratio\",\"caldariStationTypeID\",\"minmatarStationTypeID\",\"amarrStationTypeID\",\"gallenteStationTypeID\",\"joveStationTypeID\",\"services\"],\n");
fprintf(mf, "\"k\":\"operationID\",\n");
fprintf(mf, "\"m\":{\"services\":\"[ serviceID, ... ]\"},\n");
fprintf(mf, "\"t\":\"sql\",\n");
// data
fprintf(f, "\"%s\":{\n", tbl);
fprintf(f, "\"d\":{\n");
rc = SQLAllocHandle(SQL_HANDLE_STMT, H_DBC, &stmt);
if (!SQL_SUCCEEDED(rc)) return dump_sql_error(rc, SQL_HANDLE_DBC, H_DBC, 1);
rc = SQLExecDirect(stmt, "SELECT * FROM staOperations ORDER BY operationID", SQL_NTS);
if (!SQL_SUCCEEDED(rc)) return dump_sql_error(rc, SQL_HANDLE_STMT, stmt, 1);
rc = SQLFetch(stmt);
while (SQL_SUCCEEDED(rc)) {
activityID = sql_column_long(stmt, 0);
operationID = sql_column_long(stmt, 1);
fprintf(f, "\"%ld\":[", operationID);
sql_column_text(txtbuf, stmt, 2, 101);
fprintf(f, "\"%s\",", txtbuf); // operationName
sql_column_text(txtbuf, stmt, 3, 1001);
fprintf(f, "\"%s\",", txtbuf); // description
fprintf(f, "%ld,", sql_column_long(stmt, 4)); // fringe
fprintf(f, "%ld,", sql_column_long(stmt, 5)); // corridor
fprintf(f, "%ld,", sql_column_long(stmt, 6)); // hub
fprintf(f, "%ld,", sql_column_long(stmt, 7)); // border
fprintf(f, "%ld,", sql_column_long(stmt, 8)); // ratio
fprintf(f, "%ld,", sql_column_long(stmt, 9)); // caldariStationTypeID
fprintf(f, "%ld,", sql_column_long(stmt, 10)); // minmatarStationTypeID
fprintf(f, "%ld,", sql_column_long(stmt, 11)); // amarrStationTypeID
fprintf(f, "%ld,", sql_column_long(stmt, 12)); // gallenteStationTypeID
fprintf(f, "%ld,", sql_column_long(stmt, 13)); // joveStationTypeID
// services
fprintf(f, "[");
rc = SQLAllocHandle(SQL_HANDLE_STMT, H_DBC2, &substmt);
if (!SQL_SUCCEEDED(rc)) return dump_sql_error(rc, SQL_HANDLE_DBC, H_DBC2, 1);
SNPRINTF(sql, BUFLEN, "SELECT * FROM staOperationServices WHERE operationID = %ld ORDER BY serviceID\0", operationID);
rc = SQLExecDirect(substmt, sql, SQL_NTS);
if (!SQL_SUCCEEDED(rc)) return dump_sql_error(rc, SQL_HANDLE_STMT, substmt, 1);
rc = SQLFetch(substmt);
while (SQL_SUCCEEDED(rc)) {
fprintf(f, "%ld", sql_column_long(substmt, 1));
rc = SQLFetch(substmt);
if (SQL_SUCCEEDED(rc)) fprintf(f, ",");
}
fprintf(f, "]");
SQLFreeHandle(SQL_HANDLE_STMT, substmt);
rc = SQLFetch(stmt);
if (SQL_SUCCEEDED(rc)) fprintf(f, "],\n");
else fprintf(f, "]\n");
count++;
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
fprintf(f, "}\n}");
fprintf(mf, "\"l\":%u\n}", count);
return 0;
}
unsigned int create_staStationTypes(const char *j, FILE *mf, FILE *f) {
const char *tbl = "staStationTypes";
SQLRETURN rc;
SQLHSTMT stmt;
unsigned int count = 0;
// meta
fprintf(mf, "\"%s\":{\n", tbl);
fprintf(mf, "\"j\":\"%s\",\n", j);
fprintf(mf, "\"c\":[\"dockEntryX\",\"dockEntryY\",\"dockEntryZ\",\"dockOrientationX\",\"dockOrientationY\",\"dockOrientationZ\",\"operationID\",\"officeSlots\",\"reprocessingEfficiency\",\"conquerable\"],\n");
fprintf(mf, "\"k\":\"stationTypeID\",\n");
fprintf(mf, "\"t\":\"sql\",\n");
// data
fprintf(f, "\"%s\":{\n", tbl);
fprintf(f, "\"d\":{\n");
rc = SQLAllocHandle(SQL_HANDLE_STMT, H_DBC, &stmt);
if (!SQL_SUCCEEDED(rc)) return dump_sql_error(rc, SQL_HANDLE_DBC, H_DBC, 1);
rc = SQLExecDirect(stmt, "SELECT * FROM staStationTypes ORDER BY stationTypeID", SQL_NTS);
if (!SQL_SUCCEEDED(rc)) return dump_sql_error(rc, SQL_HANDLE_STMT, stmt, 1);
rc = SQLFetch(stmt);
while (SQL_SUCCEEDED(rc)) {
fprintf(f, "\"%ld\":[", sql_column_long(stmt, 0));
fprintf(f, "%g,", sql_column_float(stmt, 1)); // dockEntryX
fprintf(f, "%g,", sql_column_float(stmt, 2)); // dockEntryY
fprintf(f, "%g,", sql_column_float(stmt, 3)); // dockEntryZ
fprintf(f, "%g,", sql_column_float(stmt, 4)); // dockOrientationX
fprintf(f, "%g,", sql_column_float(stmt, 5)); // dockOrientationY
fprintf(f, "%g,", sql_column_float(stmt, 6)); // dockOrientationZ
fprintf(f, "%ld,", sql_column_long(stmt, 7)); // operationID
fprintf(f, "%ld,", sql_column_long(stmt, 8)); // officeSlots
fprintf(f, "%g,", sql_column_float(stmt, 9)); // reprocessingEfficiency
fprintf(f, "%s", sql_column_long(stmt, 10) == 0 ? "false" : "true"); // conquerable
rc = SQLFetch(stmt);
if (SQL_SUCCEEDED(rc)) fprintf(f, "],\n");
else fprintf(f, "]\n");
count++;
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
fprintf(f, "}\n}");
fprintf(mf, "\"l\":%u\n}", count);
return 0;
}
unsigned int create_staStations(const char *j, FILE *mf, FILE *f) {
const char *tbl = "staStations";
SQLRETURN rc;
SQLHSTMT stmt;
unsigned int count = 0;
char txtbuf[101];
// meta
fprintf(mf, "\"%s\":{\n", tbl);
fprintf(mf, "\"j\":\"%s\",\n", j);
fprintf(mf, "\"c\":[\"security\",\"dockingCostPerVolume\",\"maxShipVolumeDockable\",\"officeRentalCost\",\"operationID\",\"stationTypeID\",\"corporationID\",\"solarSystemID\",\"constellationID\",\"regionID\",\"stationName\",\"x\",\"y\",\"z\",\"reprocessingEfficiency\",\"reprocessingStationsTake\",\"reprocessingHangarFlag\"],\n");
fprintf(mf, "\"k\":\"stationID\",\n");
fprintf(mf, "\"t\":\"sql\",\n");
// data
fprintf(f, "\"%s\":{\n", tbl);
fprintf(f, "\"d\":{\n");
rc = SQLAllocHandle(SQL_HANDLE_STMT, H_DBC, &stmt);
if (!SQL_SUCCEEDED(rc)) return dump_sql_error(rc, SQL_HANDLE_DBC, H_DBC, 1);
rc = SQLExecDirect(stmt, "SELECT * FROM staStations ORDER BY stationID", SQL_NTS);
if (!SQL_SUCCEEDED(rc)) return dump_sql_error(rc, SQL_HANDLE_STMT, stmt, 1);
rc = SQLFetch(stmt);
while (SQL_SUCCEEDED(rc)) {
fprintf(f, "\"%ld\":[", sql_column_long(stmt, 0));
fprintf(f, "%ld,", sql_column_long(stmt, 1)); // security
fprintf(f, "%g,", sql_column_float(stmt, 2)); // dockingCostPerVolume
fprintf(f, "%g,", sql_column_float(stmt, 3)); // maxShipVolumeDockable
fprintf(f, "%ld,", sql_column_long(stmt, 4)); // officeRentalCost
fprintf(f, "%ld,", sql_column_long(stmt, 5)); // operationID
fprintf(f, "%ld,", sql_column_long(stmt, 6)); // stationTypeID
fprintf(f, "%ld,", sql_column_long(stmt, 7)); // corporationID
fprintf(f, "%ld,", sql_column_long(stmt, 8)); // solarSystemID
fprintf(f, "%ld,", sql_column_long(stmt, 9)); // constellationID
fprintf(f, "%ld,", sql_column_long(stmt, 10)); // regionID
sql_column_text(txtbuf, stmt, 11, 101);
fprintf(f, "\"%s\",", txtbuf); // stationName
fprintf(f, "%g,", sql_column_float(stmt, 12)); // x
fprintf(f, "%g,", sql_column_float(stmt, 13)); // y
fprintf(f, "%g,", sql_column_float(stmt, 14)); // z
fprintf(f, "%g,", sql_column_float(stmt, 15)); // reprocessingEfficiency
fprintf(f, "%g,", sql_column_float(stmt, 16)); // reprocessingStationsTake
fprintf(f, "%ld", sql_column_long(stmt, 17)); // reprocessingHangarFlag
rc = SQLFetch(stmt);
if (SQL_SUCCEEDED(rc)) fprintf(f, "],\n");
else fprintf(f, "]\n");
count++;
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
fprintf(f, "}\n}");
fprintf(mf, "\"l\":%u\n}", count);
return 0;
}