59
void *cache = spatialite_alloc_connection();
62
void *cache = spatialite_alloc_connection ();
61
64
if (argc > 1 || argv[0] == NULL)
62
65
argc = 1; /* silencing stupid compiler warnings */
64
ret = sqlite3_open_v2 (":memory:", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
65
if (ret != SQLITE_OK) {
66
fprintf(stderr, "cannot open in-memory db: %s\n", sqlite3_errmsg (handle));
67
sqlite3_close(handle);
71
spatialite_init_ex (handle, cache, 0);
73
ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata(\"NONE\")", NULL, NULL, &err_msg);
74
if (ret != SQLITE_OK) {
75
fprintf (stderr, "InitSpatialMetadata(\"NONE\") error: %s\n", err_msg);
76
sqlite3_free(err_msg);
77
sqlite3_close(handle);
81
ret = sqlite3_exec (handle, "SELECT InsertEpsgSrid(4326)", NULL, NULL, &err_msg);
82
if (ret != SQLITE_OK) {
83
fprintf (stderr, "Insert SRID 4326 error: %s\n", err_msg);
84
sqlite3_free(err_msg);
85
sqlite3_close(handle);
89
ret = sqlite3_exec (handle, "SELECT InsertEpsgSrid(2998)", NULL, NULL, &err_msg);
90
if (ret != SQLITE_OK) {
91
fprintf (stderr, "Insert SRID 2998 error: %s\n", err_msg);
92
sqlite3_free(err_msg);
93
sqlite3_close(handle);
97
ret = sqlite3_close (handle);
98
if (ret != SQLITE_OK) {
99
fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
103
spatialite_cleanup_ex (cache);
105
cache = spatialite_alloc_connection();
106
ret = sqlite3_open_v2 (":memory:", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
107
if (ret != SQLITE_OK) {
108
fprintf(stderr, "cannot open in-memory db: %s\n", sqlite3_errmsg (handle));
109
sqlite3_close(handle);
113
spatialite_init_ex (handle, cache, 0);
115
ret = sqlite3_get_table (handle, "SELECT InitSpatialMetadata(3.4)", &results, &rows, &columns, &err_msg);
116
if (ret != SQLITE_OK) {
117
fprintf (stderr, "Error: %s\n", err_msg);
118
sqlite3_free (err_msg);
121
if ((rows != 1) || (columns != 1)) {
122
fprintf (stderr, "Unexpected result InitSpatialMetadata() bad result: %i/%i.\n", rows, columns);
125
if (strcmp(results[1], "0") != 0) {
126
fprintf (stderr, "Unexpected result: InitSpatialMetadata() with non-text passed: %s.\n", results[1]);
129
sqlite3_free_table (results);
131
ret = sqlite3_close (handle);
132
if (ret != SQLITE_OK) {
133
fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
137
spatialite_cleanup_ex (cache);
139
cache = spatialite_alloc_connection();
140
ret = sqlite3_open_v2 (":memory:", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
141
if (ret != SQLITE_OK) {
142
fprintf(stderr, "cannot open in-memory db: %s\n", sqlite3_errmsg (handle));
143
sqlite3_close(handle);
147
spatialite_init_ex (handle, cache, 0);
149
ret = sqlite3_get_table (handle, "SELECT InitSpatialMetadata(\"EMPTY\")", &results, &rows, &columns, &err_msg);
150
if (ret != SQLITE_OK) {
151
fprintf (stderr, "Error: %s\n", err_msg);
152
sqlite3_free (err_msg);
155
if ((rows != 1) || (columns != 1)) {
156
fprintf (stderr, "Unexpected result InitSpatialMetadata(\"EMPTY\") bad result: %i/%i.\n", rows, columns);
159
if (strcmp(results[1], "1") != 0) {
160
fprintf (stderr, "Unexpected error: InitSpatialMetadata(\"EMPTY\"): %s.\n", results[1]);
163
sqlite3_free_table (results);
165
ret = sqlite3_get_table (handle, "SELECT InsertEpsgSrid(4326)", &results, &rows, &columns, &err_msg);
166
if (ret != SQLITE_OK) {
167
fprintf (stderr, "Error: %s\n", err_msg);
168
sqlite3_free (err_msg);
171
if ((rows != 1) || (columns != 1)) {
172
fprintf (stderr, "Unexpected result InsertEpsgSrid(4326) bad result: %i/%i.\n", rows, columns);
175
if (strcmp(results[1], "1") != 0) {
176
fprintf (stderr, "Unexpected error: InsertEpsgSrid(4326): %s.\n", results[1]);
179
sqlite3_free_table (results);
181
ret = sqlite3_get_table (handle, "SELECT InsertEpsgSrid(\"Non-integer\")", &results, &rows, &columns, &err_msg);
182
if (ret != SQLITE_OK) {
183
fprintf (stderr, "Error: %s\n", err_msg);
184
sqlite3_free (err_msg);
187
if ((rows != 1) || (columns != 1)) {
188
fprintf (stderr, "Unexpected result InsertEpsgSrid(\"Non-integer\") bad result: %i/%i.\n", rows, columns);
191
if (strcmp(results[1], "0") != 0) {
192
fprintf (stderr, "Unexpected result: InsertEpsgSrid() with non-integer passed: %s.\n", results[1]);
195
sqlite3_free_table (results);
197
ret = sqlite3_close (handle);
198
if (ret != SQLITE_OK) {
199
fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
203
spatialite_cleanup_ex (cache);
205
cache = spatialite_alloc_connection();
206
ret = sqlite3_open_v2 (":memory:", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
207
if (ret != SQLITE_OK) {
208
fprintf(stderr, "cannot open in-memory db: %s\n", sqlite3_errmsg (handle));
209
sqlite3_close(handle);
213
spatialite_init_ex (handle, cache, 0);
215
ret = sqlite3_get_table (handle, "SELECT InitSpatialMetadata(\"WGS84\")", &results, &rows, &columns, &err_msg);
216
if (ret != SQLITE_OK) {
217
fprintf (stderr, "Error: %s\n", err_msg);
218
sqlite3_free (err_msg);
221
if ((rows != 1) || (columns != 1)) {
222
fprintf (stderr, "Unexpected result InitSpatialMetadata(\"WGS84\") bad result: %i/%i.\n", rows, columns);
225
if (strcmp(results[1], "1") != 0) {
226
fprintf (stderr, "Unexpected error: InitSpatialMetadata(\"WGS84\"): %s.\n", results[1]);
229
sqlite3_free_table (results);
231
ret = sqlite3_get_table (handle, "SELECT InsertEpsgSrid(3003)", &results, &rows, &columns, &err_msg);
232
if (ret != SQLITE_OK) {
233
fprintf (stderr, "Error: %s\n", err_msg);
234
sqlite3_free (err_msg);
237
if ((rows != 1) || (columns != 1)) {
238
fprintf (stderr, "Unexpected result InsertEpsgSrid(3003) bad result: %i/%i.\n", rows, columns);
241
if (strcmp(results[1], "1") != 0) {
242
fprintf (stderr, "Unexpected error: InsertEpsgSrid(3003): %s.\n", results[1]);
245
sqlite3_free_table (results);
247
ret = sqlite3_get_table (handle, "SELECT InsertEpsgSrid(4326)", &results, &rows, &columns, &err_msg);
248
if (ret != SQLITE_OK) {
249
fprintf (stderr, "Error: %s\n", err_msg);
250
sqlite3_free (err_msg);
253
if ((rows != 1) || (columns != 1)) {
254
fprintf (stderr, "Unexpected result InsertEpsgSrid(4326) (dupe) bad result: %i/%i.\n", rows, columns);
257
if (strcmp(results[1], "0") != 0) {
258
fprintf (stderr, "Unexpected result: InsertEpsgSrid(4326) duplicate passed: %s.\n", results[1]);
261
sqlite3_free_table (results);
263
ret = sqlite3_close (handle);
264
if (ret != SQLITE_OK) {
265
fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
269
spatialite_cleanup_ex (cache);
271
cache = spatialite_alloc_connection();
272
ret = sqlite3_open_v2 (":memory:", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
273
if (ret != SQLITE_OK) {
274
fprintf(stderr, "cannot open in-memory db: %s\n", sqlite3_errmsg (handle));
275
sqlite3_close(handle);
279
spatialite_init_ex (handle, cache, 0);
281
ret = sqlite3_get_table (handle, "SELECT InitSpatialMetadata(\"WGS84_only\")", &results, &rows, &columns, &err_msg);
282
if (ret != SQLITE_OK) {
283
fprintf (stderr, "Error: %s\n", err_msg);
284
sqlite3_free (err_msg);
287
if ((rows != 1) || (columns != 1)) {
288
fprintf (stderr, "Unexpected result InitSpatialMetadata(\"WGS84_ONLY\") bad result: %i/%i.\n", rows, columns);
291
if (strcmp(results[1], "1") != 0) {
292
fprintf (stderr, "Unexpected error: InitSpatialMetadata(\"WGS84_ONLY\"): %s.\n", results[1]);
295
sqlite3_free_table (results);
297
ret = sqlite3_close (handle);
298
if (ret != SQLITE_OK) {
299
fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
303
spatialite_cleanup_ex (cache);
68
sqlite3_open_v2 (":memory:", &handle,
69
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
72
fprintf (stderr, "cannot open in-memory db: %s\n",
73
sqlite3_errmsg (handle));
74
sqlite3_close (handle);
78
spatialite_init_ex (handle, cache, 0);
81
sqlite3_exec (handle, "SELECT InitSpatialMetadata(\"NONE\")", NULL,
85
fprintf (stderr, "InitSpatialMetadata(\"NONE\") error: %s\n",
87
sqlite3_free (err_msg);
88
sqlite3_close (handle);
93
sqlite3_exec (handle, "SELECT InsertEpsgSrid(4326)", NULL, NULL,
97
fprintf (stderr, "Insert SRID 4326 error: %s\n", err_msg);
98
sqlite3_free (err_msg);
99
sqlite3_close (handle);
104
/* only if full EPSG support is enabled */
106
sqlite3_exec (handle, "SELECT InsertEpsgSrid(2998)", NULL, NULL,
108
if (ret != SQLITE_OK)
110
fprintf (stderr, "Insert SRID 2998 error: %s\n", err_msg);
111
sqlite3_free (err_msg);
112
sqlite3_close (handle);
117
ret = sqlite3_close (handle);
118
if (ret != SQLITE_OK)
120
fprintf (stderr, "sqlite3_close() error: %s\n",
121
sqlite3_errmsg (handle));
125
spatialite_cleanup_ex (cache);
127
cache = spatialite_alloc_connection ();
129
sqlite3_open_v2 (":memory:", &handle,
130
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
131
if (ret != SQLITE_OK)
133
fprintf (stderr, "cannot open in-memory db: %s\n",
134
sqlite3_errmsg (handle));
135
sqlite3_close (handle);
139
spatialite_init_ex (handle, cache, 0);
142
sqlite3_get_table (handle, "SELECT InitSpatialMetadata(3.4)", &results,
143
&rows, &columns, &err_msg);
144
if (ret != SQLITE_OK)
146
fprintf (stderr, "Error: %s\n", err_msg);
147
sqlite3_free (err_msg);
150
if ((rows != 1) || (columns != 1))
153
"Unexpected result InitSpatialMetadata() bad result: %i/%i.\n",
157
if (strcmp (results[1], "0") != 0)
160
"Unexpected result: InitSpatialMetadata() with non-text passed: %s.\n",
164
sqlite3_free_table (results);
166
ret = sqlite3_close (handle);
167
if (ret != SQLITE_OK)
169
fprintf (stderr, "sqlite3_close() error: %s\n",
170
sqlite3_errmsg (handle));
174
spatialite_cleanup_ex (cache);
176
cache = spatialite_alloc_connection ();
178
sqlite3_open_v2 (":memory:", &handle,
179
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
180
if (ret != SQLITE_OK)
182
fprintf (stderr, "cannot open in-memory db: %s\n",
183
sqlite3_errmsg (handle));
184
sqlite3_close (handle);
188
spatialite_init_ex (handle, cache, 0);
191
sqlite3_get_table (handle, "SELECT InitSpatialMetadata(\"EMPTY\")",
192
&results, &rows, &columns, &err_msg);
193
if (ret != SQLITE_OK)
195
fprintf (stderr, "Error: %s\n", err_msg);
196
sqlite3_free (err_msg);
199
if ((rows != 1) || (columns != 1))
202
"Unexpected result InitSpatialMetadata(\"EMPTY\") bad result: %i/%i.\n",
206
if (strcmp (results[1], "1") != 0)
209
"Unexpected error: InitSpatialMetadata(\"EMPTY\"): %s.\n",
213
sqlite3_free_table (results);
216
sqlite3_get_table (handle, "SELECT InsertEpsgSrid(4326)", &results,
217
&rows, &columns, &err_msg);
218
if (ret != SQLITE_OK)
220
fprintf (stderr, "Error: %s\n", err_msg);
221
sqlite3_free (err_msg);
224
if ((rows != 1) || (columns != 1))
227
"Unexpected result InsertEpsgSrid(4326) bad result: %i/%i.\n",
231
if (strcmp (results[1], "1") != 0)
233
fprintf (stderr, "Unexpected error: InsertEpsgSrid(4326): %s.\n",
237
sqlite3_free_table (results);
240
sqlite3_get_table (handle, "SELECT InsertEpsgSrid(\"Non-integer\")",
241
&results, &rows, &columns, &err_msg);
242
if (ret != SQLITE_OK)
244
fprintf (stderr, "Error: %s\n", err_msg);
245
sqlite3_free (err_msg);
248
if ((rows != 1) || (columns != 1))
251
"Unexpected result InsertEpsgSrid(\"Non-integer\") bad result: %i/%i.\n",
255
if (strcmp (results[1], "0") != 0)
258
"Unexpected result: InsertEpsgSrid() with non-integer passed: %s.\n",
262
sqlite3_free_table (results);
264
ret = sqlite3_close (handle);
265
if (ret != SQLITE_OK)
267
fprintf (stderr, "sqlite3_close() error: %s\n",
268
sqlite3_errmsg (handle));
272
spatialite_cleanup_ex (cache);
274
cache = spatialite_alloc_connection ();
276
sqlite3_open_v2 (":memory:", &handle,
277
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
278
if (ret != SQLITE_OK)
280
fprintf (stderr, "cannot open in-memory db: %s\n",
281
sqlite3_errmsg (handle));
282
sqlite3_close (handle);
286
spatialite_init_ex (handle, cache, 0);
289
sqlite3_get_table (handle, "SELECT InitSpatialMetadata(\"WGS84\")",
290
&results, &rows, &columns, &err_msg);
291
if (ret != SQLITE_OK)
293
fprintf (stderr, "Error: %s\n", err_msg);
294
sqlite3_free (err_msg);
297
if ((rows != 1) || (columns != 1))
300
"Unexpected result InitSpatialMetadata(\"WGS84\") bad result: %i/%i.\n",
304
if (strcmp (results[1], "1") != 0)
307
"Unexpected error: InitSpatialMetadata(\"WGS84\"): %s.\n",
311
sqlite3_free_table (results);
314
/* only if full EPSG support is enabled */
316
sqlite3_get_table (handle, "SELECT InsertEpsgSrid(3003)", &results,
317
&rows, &columns, &err_msg);
318
if (ret != SQLITE_OK)
320
fprintf (stderr, "Error: %s\n", err_msg);
321
sqlite3_free (err_msg);
324
if ((rows != 1) || (columns != 1))
327
"Unexpected result InsertEpsgSrid(3003) bad result: %i/%i.\n",
331
if (strcmp (results[1], "1") != 0)
333
fprintf (stderr, "Unexpected error: InsertEpsgSrid(3003): %s.\n",
337
sqlite3_free_table (results);
341
sqlite3_get_table (handle, "SELECT InsertEpsgSrid(4326)", &results,
342
&rows, &columns, &err_msg);
343
if (ret != SQLITE_OK)
345
fprintf (stderr, "Error: %s\n", err_msg);
346
sqlite3_free (err_msg);
349
if ((rows != 1) || (columns != 1))
352
"Unexpected result InsertEpsgSrid(4326) (dupe) bad result: %i/%i.\n",
356
if (strcmp (results[1], "0") != 0)
359
"Unexpected result: InsertEpsgSrid(4326) duplicate passed: %s.\n",
363
sqlite3_free_table (results);
365
ret = sqlite3_close (handle);
366
if (ret != SQLITE_OK)
368
fprintf (stderr, "sqlite3_close() error: %s\n",
369
sqlite3_errmsg (handle));
373
spatialite_cleanup_ex (cache);
375
cache = spatialite_alloc_connection ();
377
sqlite3_open_v2 (":memory:", &handle,
378
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
379
if (ret != SQLITE_OK)
381
fprintf (stderr, "cannot open in-memory db: %s\n",
382
sqlite3_errmsg (handle));
383
sqlite3_close (handle);
387
spatialite_init_ex (handle, cache, 0);
390
sqlite3_get_table (handle, "SELECT InitSpatialMetadata(\"WGS84_only\")",
391
&results, &rows, &columns, &err_msg);
392
if (ret != SQLITE_OK)
394
fprintf (stderr, "Error: %s\n", err_msg);
395
sqlite3_free (err_msg);
398
if ((rows != 1) || (columns != 1))
401
"Unexpected result InitSpatialMetadata(\"WGS84_ONLY\") bad result: %i/%i.\n",
405
if (strcmp (results[1], "1") != 0)
408
"Unexpected error: InitSpatialMetadata(\"WGS84_ONLY\"): %s.\n",
412
sqlite3_free_table (results);
414
ret = sqlite3_close (handle);
415
if (ret != SQLITE_OK)
417
fprintf (stderr, "sqlite3_close() error: %s\n",
418
sqlite3_errmsg (handle));
422
spatialite_cleanup_ex (cache);