spatialite-sys 0.2.0

Low-level bindings to the SpatiaLite SQLite geospatial extension
Documentation
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743

/*

 check_libxml2.c -- SpatiaLite Test Case

 Author: Sandro Furieri <a.furieri@lqt.it>

 ------------------------------------------------------------------------------
 
 Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
 The contents of this file are subject to the Mozilla Public License Version
 1.1 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at
 http://www.mozilla.org/MPL/
 
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.

The Original Code is the SpatiaLite library

The Initial Developer of the Original Code is Alessandro Furieri
 
Portions created by the Initial Developer are Copyright (C) 2013
the Initial Developer. All Rights Reserved.

Contributor(s):
Brad Hards <bradh@frogmouth.net>

Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
 
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "config.h"

#include "sqlite3.h"
#include "spatialite.h"

#ifdef ENABLE_LIBXML2		/* only if LIBXML2 is supported */

#define ISO_METADATA	1
#define SLD_SE_STYLE	2
#define SVG		3

static int
check_bad_xml (void *cache)
{
/* parsing a not-well-formed XML Sample */
    FILE *fl;
    int sz = 0;
    int rd;
    unsigned char *xml = NULL;
    unsigned char *p_result = NULL;
    int len;
    char *err1;
    char *err2;
    char *version = gaia_libxml2_version ();

    if (version == NULL)
      {
	  fprintf (stderr, "unable to get the library version\n");
	  return 0;
      }
    free (version);

/* loading the XMLDocument */
    fl = fopen ("books-bad.xml", "rb");
    if (!fl)
      {
	  fprintf (stderr, "cannot open \"books-bad.xml\"\n");
	  return 0;
      }
    if (fseek (fl, 0, SEEK_END) == 0)
	sz = ftell (fl);
    xml = malloc (sz);
    rewind (fl);
    rd = fread (xml, 1, sz, fl);
    if (rd != sz)
      {
	  fprintf (stderr, "read error \"books-bad.xml\"\n");
	  return 0;
      }
    fclose (fl);

/* parsing the XMLDocument */
    gaiaXmlToBlob (cache, xml, rd, 1, NULL, &p_result, &len, &err1, &err2);
    if (p_result != NULL)
      {
	  fprintf (stderr, "this is not a well-formed XML !!!\n");
	  return 0;
      }

    free (xml);
    return 1;
}

static int
check_bad_schema (void *cache)
{
/* validating by invalid Schema */
    FILE *fl;
    int sz = 0;
    int rd;
    unsigned char *xml = NULL;
    unsigned char *p_result = NULL;
    int len;
    char *err1;
    char *err2;

/* loading the XMLDocument */
    fl = fopen ("books.xml", "rb");
    if (!fl)
      {
	  fprintf (stderr, "cannot open \"books.xml\"\n");
	  return 0;
      }
    if (fseek (fl, 0, SEEK_END) == 0)
	sz = ftell (fl);
    xml = malloc (sz);
    rewind (fl);
    rd = fread (xml, 1, sz, fl);
    if (rd != sz)
      {
	  fprintf (stderr, "read error \"books.xml\"\n");
	  return 0;
      }
    fclose (fl);

/* validating the XMLDocument */
    gaiaXmlToBlob (cache, xml, rd, 1, "books-bad.xsd", &p_result, &len, &err1,
		   &err2);
    if (p_result != NULL)
      {
	  fprintf (stderr, "this is not a valid XML !!!\n");
	  return 0;
      }

    free (xml);
    return 1;
}

static int
check_validate (void *cache, const char *path)
{
/* validating an XML Sample */
    FILE *fl;
    int sz = 0;
    int rd;
    unsigned char *xml = NULL;
    char *schema_uri = NULL;
    char *schema_uri2 = NULL;
    unsigned char *p_result = NULL;
    int len;

/* loading the XMLDocument */
    fl = fopen (path, "rb");
    if (!fl)
      {
	  fprintf (stderr, "cannot open \"%s\"\n", path);
	  return 0;
      }
    if (fseek (fl, 0, SEEK_END) == 0)
	sz = ftell (fl);
    xml = malloc (sz);
    rewind (fl);
    rd = fread (xml, 1, sz, fl);
    if (rd != sz)
      {
	  fprintf (stderr, "read error \"%s\"\n", path);
	  return 0;
      }
    fclose (fl);

/* extracting the Internal SchemaURI */
    schema_uri = gaiaXmlGetInternalSchemaURI (cache, xml, rd);
    if (schema_uri == NULL)
      {
	  fprintf (stderr, "unable to identify the Schema for \"%s\"\n", path);
	  return 0;
      }
/* validating the XMLDocument */
    gaiaXmlToBlob (cache, xml, rd, 1, schema_uri, &p_result, &len, NULL, NULL);
    if (p_result == NULL)
      {
	  fprintf (stderr, "unable to validate \"%s\"\n", path);
	  return 0;
      }
    if (!gaiaIsSchemaValidatedXmlBlob (p_result, len))
      {
	  fprintf (stderr, "validation failed: \"%s\"\n", path);
	  return 0;
      }
    schema_uri2 = gaiaXmlBlobGetSchemaURI (p_result, len);
    if (schema_uri2 == NULL)
      {
	  fprintf (stderr,
		   "unable to retrieve the ValidationSchemaURI for \"%s\"\n",
		   path);
	  return 0;
      }
    if (strcmp (schema_uri, schema_uri2) != 0)
      {
	  fprintf (stderr,
		   "%s: mismatching SchemaURI \"%s\" (expected \"%s\")\n", path,
		   schema_uri2, schema_uri);
	  return 0;
      }

    free (schema_uri);
    free (schema_uri2);
    free (p_result);
    free (xml);

    return 1;
}

static int
check_extended (void *cache, const char *path, int mode)
{
/* validating an XML Sample */
    FILE *fl;
    int sz = 0;
    int rd;
    unsigned char *xml = NULL;
    int iso;
    int style;
    int svg;
    unsigned char *p_result = NULL;
    int len;
    char *file_id = NULL;
    char *parent_id = NULL;
    char *title = NULL;
    char *abstract = NULL;
    unsigned char *geom_blob;
    int geom_size;
    gaiaGeomCollPtr geom;

/* loading the XMLDocument */
    fl = fopen (path, "rb");
    if (!fl)
      {
	  fprintf (stderr, "cannot open \"%s\"\n", path);
	  return 0;
      }
    if (fseek (fl, 0, SEEK_END) == 0)
	sz = ftell (fl);
    xml = malloc (sz);
    rewind (fl);
    rd = fread (xml, 1, sz, fl);
    if (rd != sz)
      {
	  fprintf (stderr, "read error \"%s\"\n", path);
	  return 0;
      }
    fclose (fl);

/* simple parsing without validation */
    gaiaXmlToBlob (cache, xml, rd, 1, NULL, &p_result, &len, NULL, NULL);
    if (p_result == NULL)
      {
	  fprintf (stderr, "unable to parse \"%s\"\n", path);
	  return 0;
      }

/* checking the payload type */
    iso = gaiaIsIsoMetadataXmlBlob (p_result, len);
    style = gaiaIsSldSeRasterStyleXmlBlob (p_result, len);
    style = gaiaIsSldSeVectorStyleXmlBlob (p_result, len);
    svg = gaiaIsSvgXmlBlob (p_result, len);
    if (mode == ISO_METADATA && iso && !style && !svg)
	;
    else if (mode == SLD_SE_STYLE && !iso && style && !svg)
	;
    else if (mode == SVG && !iso && !style && svg)
	;
    else
      {
	  fprintf (stderr, "mismatching type: \"%s\" iso=%d style=%d svg=%d\n",
		   path, iso, style, svg);
	  return 0;
      }

/* testing ISO Metadata attributes */
    file_id = gaiaXmlBlobGetFileId (p_result, len);
    parent_id = gaiaXmlBlobGetParentId (p_result, len);
    title = gaiaXmlBlobGetTitle (p_result, len);
    abstract = gaiaXmlBlobGetAbstract (p_result, len);
    gaiaXmlBlobGetGeometry (p_result, len, &geom_blob, &geom_size);
    if (mode == ISO_METADATA)
      {
	  /* verifying ISO Metadata attributes */
	  if (file_id == NULL)
	    {
		fprintf (stderr, "unexpected NULL FileIdentifier in \"%s\"\n",
			 path);
		return 0;
	    }
	  if (strcmp (file_id, "029097fd-2ef2-487c-a5ca-6ec7a3dbac53") != 0)
	    {
		fprintf (stderr, "unexpected FileIdentifier in \"%s\" [%s]\n",
			 path, file_id);
		return 0;
	    }
	  if (parent_id == NULL)
	    {
		fprintf (stderr, "unexpected NULL ParentIdentifier in \"%s\"\n",
			 path);
		return 0;
	    }
	  if (strcmp (parent_id, "024027fd-3ef2-487c-a8ca-6ec8a3dfac57") != 0)
	    {
		fprintf (stderr, "unexpected ParentIdentifier in \"%s\" [%s]\n",
			 path, parent_id);
		return 0;
	    }
	  if (title == NULL)
	    {
		fprintf (stderr, "unexpected NULL Title in \"%s\"\n", path);
		return 0;
	    }
	  if (strcmp (title, "Image2000 Product 1 (nl2) Multispectral") != 0)
	    {
		fprintf (stderr, "unexpected Title in \"%s\" [%s]\n", path,
			 title);
		return 0;
	    }
	  if (abstract == NULL)
	    {
		fprintf (stderr, "unexpected NULL Abstract in \"%s\"\n", path);
		return 0;
	    }
	  if (strcmp
	      (abstract,
	       "IMAGE2000 product 1 individual orthorectified scenes.") != 0)
	    {
		fprintf (stderr, "unexpected Abstract in \"%s\" [%s]\n", path,
			 abstract);
		return 0;
	    }
	  if (geom_blob == NULL)
	    {
		fprintf (stderr, "unexpected NULL Geometry in \"%s\"\n", path);
		return 0;
	    }
	  geom = gaiaFromSpatiaLiteBlobWkb (geom_blob, geom_size);
	  if (geom == NULL)
	    {
		fprintf (stderr, "unexpected invalid Geometry in \"%s\"\n",
			 path);
		return 0;
	    }
	  if (geom->Srid != 4326)
	    {
		fprintf (stderr, "unexpected Geometry SRID in \"%s\" [%d]\n",
			 path, geom->Srid);
		return 0;
	    }
	  if (geom->DeclaredType != GAIA_MULTIPOLYGON)
	    {
		fprintf (stderr, "unexpected Geometry Type in \"%s\" [%d]\n",
			 path, geom->DeclaredType);
		return 0;
	    }
	  if (geom->MinX != 3.93000000)
	    {
		fprintf (stderr, "unexpected Geometry MinX in \"%s\" [%1.8f]\n",
			 path, geom->MinX);
		return 0;
	    }
	  if (geom->MinY != 52.10000000)
	    {
		fprintf (stderr, "unexpected Geometry MinY in \"%s\" [%1.8f]\n",
			 path, geom->MinY);
		return 0;
	    }
	  if (geom->MaxX != 7.57000000)
	    {
		fprintf (stderr, "unexpected Geometry MaxX in \"%s\" [%1.8f]\n",
			 path, geom->MaxX);
		return 0;
	    }
	  if (geom->MaxY != 54.10000000)
	    {
		fprintf (stderr, "unexpected Geometry MaxY in \"%s\" [%1.8f]\n",
			 path, geom->MaxY);
		return 0;
	    }
	  gaiaFreeGeomColl (geom);
      }
    else
      {
	  /* not ISO Metadata */
	  if (strcmp (path, "stazioni_se.xml") == 0)
	    {
		if (strcmp (title, "Railway Stations - blue star") != 0)
		  {
		      fprintf (stderr, "unexpected Title in \"%s\"\n", path);
		      return 0;
		  }
		if (strcmp (abstract, "a simple SE Point Symbolizer") != 0)
		  {
		      fprintf (stderr, "unexpected Abstract in \"%s\"\n", path);
		      return 0;
		  }
	    }
	  else
	    {
		if (title != NULL)
		  {
		      fprintf (stderr, "unexpected Title in \"%s\"\n", path);
		      return 0;
		  }
		if (abstract != NULL)
		  {
		      fprintf (stderr, "unexpected Abstract in \"%s\"\n", path);
		      return 0;
		  }
	    }
      }

    free (p_result);
    free (xml);
    if (file_id)
	free (file_id);
    if (parent_id)
	free (parent_id);
    if (title)
	free (title);
    if (abstract)
	free (abstract);
    if (geom_blob)
	free (geom_blob);

    return 1;
}

static int
check_parse (void *cache, const char *path)
{
/* parsing an XML Sample */
    FILE *fl;
    int sz = 0;
    int rd;
    unsigned char *xml = NULL;
    int compressed_sz;
    int uncompressed_sz;
    int doc_sz;
    int formatted_sz;
    int formatted_txt_sz;
    unsigned char *p_result = NULL;
    unsigned char *out;
    char *txt;

/* loading the XMLDocument */
    fl = fopen (path, "rb");
    if (!fl)
      {
	  fprintf (stderr, "cannot open \"%s\"\n", path);
	  return 0;
      }
    if (fseek (fl, 0, SEEK_END) == 0)
	sz = ftell (fl);
    xml = malloc (sz);
    rewind (fl);
    rd = fread (xml, 1, sz, fl);
    if (rd != sz)
      {
	  fprintf (stderr, "read error \"%s\"\n", path);
	  return 0;
      }
    fclose (fl);

/* parsing the XMLDocument (no validation / compressed) */
    gaiaXmlToBlob (cache, xml, rd, 1, NULL, &p_result, &compressed_sz, NULL,
		   NULL);
    if (p_result == NULL)
      {
	  fprintf (stderr, "unable to parse(1) \"%s\"\n", path);
	  return 0;
      }
    doc_sz = gaiaXmlBlobGetDocumentSize (p_result, compressed_sz);
    gaiaXmlFromBlob (p_result, compressed_sz, 4, &out, &formatted_sz);
    if (out == NULL)
      {
	  fprintf (stderr, "unable to format(1) \"%s\"\n", path);
	  return 0;
      }
    free (out);
    txt = gaiaXmlTextFromBlob (p_result, compressed_sz, 2);
    if (txt == NULL)
      {
	  fprintf (stderr, "unable to format-text(1) \"%s\"\n", path);
	  return 0;
      }
    formatted_txt_sz = strlen (txt);
    free (txt);
    free (p_result);

/* parsing the XMLDocument (no validation / not compressed) */
    gaiaXmlToBlob (cache, xml, rd, 0, NULL, &p_result, &uncompressed_sz, NULL,
		   NULL);
    if (p_result == NULL)
      {
	  fprintf (stderr, "unable to parse(2) \"%s\"\n", path);
	  return 0;
      }
    free (p_result);

    if (strcmp (path, "books.xml") == 0)
      {
	  if (compressed_sz != 432)
	    {
		fprintf (stderr,
			 "books.xml: unexpected compressed size %d (expected 432)\n",
			 compressed_sz);
		return 0;
	    }
	  if (uncompressed_sz != 780)
	    {
		fprintf (stderr,
			 "books.xml: unexpected compressed size %d (expected 780)\n",
			 uncompressed_sz);
		return 0;
	    }
	  if (doc_sz != 741)
	    {
		fprintf (stderr,
			 "books.xml: unexpected document size %d (expected 741)\n",
			 doc_sz);
		return 0;
	    }
	  if (formatted_sz != 864)
	    {
		fprintf (stderr,
			 "books.xml: unexpected formatted size %d (expected 864)\n",
			 formatted_sz);
		return 0;
	    }
	  if (formatted_txt_sz != 803)
	    {
		fprintf (stderr,
			 "books.xml: unexpected formatted-text size %d (expected 803)\n",
			 formatted_txt_sz);
		return 0;
	    }
      }
    if (strcmp (path, "opera.xml") == 0)
      {
	  if (compressed_sz != 425)
	    {
		fprintf (stderr,
			 "opera.xml: unexpected compressed size %d (expected 425)\n",
			 compressed_sz);
		return 0;
	    }
	  if (uncompressed_sz != 951)
	    {
		fprintf (stderr,
			 "opera.xml: unexpected compressed size %d (expected 951)\n",
			 uncompressed_sz);
		return 0;
	    }
	  if (doc_sz != 912)
	    {
		fprintf (stderr,
			 "opera.xml: unexpected document size %d (expected 912)\n",
			 doc_sz);
		return 0;
	    }
	  if (formatted_sz != 970)
	    {
		fprintf (stderr,
			 "opera.xml: unexpected formatted size %d (expected 970)\n",
			 formatted_sz);
		return 0;
	    }
	  if (formatted_txt_sz != 909)
	    {
		fprintf (stderr,
			 "opera.xml: unexpected formatted-text size %d (expected 909)\n",
			 formatted_txt_sz);
		return 0;
	    }
      }
    if (strcmp (path, "movies.xml") == 0)
      {
	  if (compressed_sz != 577)
	    {
		fprintf (stderr,
			 "movies.xml: unexpected compressed size %d (expected 577)\n",
			 compressed_sz);
		return 0;
	    }
	  if (uncompressed_sz != 1809)
	    {
		fprintf (stderr,
			 "movies.xml: unexpected compressed size %d (expected 1809)\n",
			 uncompressed_sz);
		return 0;
	    }
	  if (doc_sz != 1770)
	    {
		fprintf (stderr,
			 "movies.xml: unexpected document size %d (expected 1770)\n",
			 doc_sz);
		return 0;
	    }
	  if (formatted_sz != 945)
	    {
		fprintf (stderr,
			 "movies.xml: unexpected formatted size %d (expected 945)\n",
			 formatted_sz);
		return 0;
	    }
	  if (formatted_txt_sz != 884)
	    {
		fprintf (stderr,
			 "movies.xml: unexpected formatted-text size %d (expected 884)\n",
			 formatted_txt_sz);
		return 0;
	    }
      }
    free (xml);

    return 1;
}

#endif

int
main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    void *cache = spatialite_alloc_connection ();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret =
	sqlite3_open_v2 (":memory:", &handle,
			 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "cannot open in-memory db: %s\n",
		   sqlite3_errmsg (handle));
	  sqlite3_close (handle);
	  return -1;
      }

    spatialite_init_ex (handle, cache, 0);

#ifdef ENABLE_LIBXML2		/* only if LIBXML2 is supported */

    if (!check_parse (cache, "books.xml"))
      {
	  fprintf (stderr, "unable to parse \"books.xml\"\n");
	  return -2;
      }
    if (!check_parse (cache, "opera.xml"))
      {
	  fprintf (stderr, "unable to parse \"opera.xml\"\n");
	  return -3;
      }
    if (!check_parse (cache, "movies.xml"))
      {
	  fprintf (stderr, "unable to parse \"movies.xml\"\n");
	  return -4;
      }

    if (!check_validate (cache, "books.xml"))
      {
	  fprintf (stderr, "unable to validate \"books.xml\"\n");
	  return -5;
      }
    if (!check_validate (cache, "opera.xml"))
      {
	  fprintf (stderr, "unable to validate \"opera.xml\"\n");
	  return -6;
      }
    if (!check_validate (cache, "movies.xml"))
      {
	  fprintf (stderr, "unable to validate \"movies.xml\"\n");
	  return -7;
      }
    if (!check_extended (cache, "inspire-data-example.xml", ISO_METADATA))
      {
	  fprintf (stderr, "unable to parse \"inspire-data-example.xml\"\n");
	  return -8;
      }
    if (!check_extended (cache, "stazioni_se.xml", SLD_SE_STYLE))
      {
	  fprintf (stderr, "unable to parse \"stazioni_se.xml\"\n");
	  return -9;
      }
    if (!check_extended (cache, "thunderstorm_mild.svg", SVG))
      {
	  fprintf (stderr, "unable to parse \"thunderstorm_mild.svg\"\n");
	  return -10;
      }

    if (!check_bad_xml (cache))
      {
	  fprintf (stderr, "unable to test not well-formed XML\n");
	  return -11;
      }
    if (!check_bad_schema (cache))
      {
	  fprintf (stderr, "unable to test invalid Schema\n");
	  return -12;
      }

#endif

    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK)
      {
	  fprintf (stderr, "sqlite3_close() error: %s\n",
		   sqlite3_errmsg (handle));
	  return -10;
      }

    spatialite_cleanup_ex (cache);

    spatialite_shutdown ();

    return 0;
}