Skip to content

Commit cdae0f6

Browse files
author
esseffe
committedNov 25, 2010
upgrading to SpatiaLite 2.4.0-RC4
git-svn-id: http://svn.osgeo.org/qgis/trunk@14763 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d3b07d4 commit cdae0f6

File tree

19 files changed

+186284
-55513
lines changed

19 files changed

+186284
-55513
lines changed
 

‎AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ Carson J. Q. Farmer <carson dot farmer at gmail dot com>
4040
Lorenzo Masini <lorenxo86 at gmail.com>
4141
Werner Macho <werner.macho at gmail.com>
4242
Giuseppe Sucameli <brush.tyler at gmail.com>
43+
Alessandro Furieri <a.furieri at lqt.it>

‎debian/copyright

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ reported:
3838
Lorenzo Masini <lorenxo86 at gmail.com>
3939
Werner Macho <werner.macho at gmail.com>
4040
Giuseppe Sucameli <brush.tyler at gmail.com>
41+
Alessandro Furieri <a.furieri at lqt.it>
4142

4243
Copyright:
4344

‎python/core/qgsapplication.sip

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
139139
//! Returns the path to the master qgis.db file.
140140
static const QString qgisMasterDbFilePath();
141141

142-
//! Returns the path to the spatialite template db file.
143-
//! @note added in 1.5
144-
static const QString qgisSpatialiteDbTemplatePath();
145-
146142
//! Returns the path to the settings directory in user's home dir
147143
static const QString qgisSettingsDirPath();
148144

‎src/app/qgsnewspatialitelayerdialog.cpp

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,57 @@ void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked()
187187
}
188188
}
189189

190+
void QgsNewSpatialiteLayerDialog::initializeSpatialMetadata(sqlite3 *sqlite_handle)
191+
{
192+
// attempting to perform self-initialization for a newly created DB
193+
int ret;
194+
char sql[1024];
195+
char *errMsg = NULL;
196+
int count;
197+
int i;
198+
char **results;
199+
int rows;
200+
int columns;
201+
202+
if (sqlite_handle == NULL)
203+
return;
204+
// checking if this DB is really empty
205+
strcpy(sql, "SELECT Count(*) from sqlite_master");
206+
ret = sqlite3_get_table(sqlite_handle, sql, &results, &rows, &columns, NULL);
207+
if (ret != SQLITE_OK)
208+
return;
209+
if (rows < 1)
210+
;
211+
else
212+
{
213+
for (i = 1; i <= rows; i++)
214+
count = atoi(results[(i * columns) + 0]);
215+
}
216+
sqlite3_free_table(results);
217+
218+
if (count > 0)
219+
return;
220+
221+
// all right, it's empty: proceding to initialize
222+
strcpy(sql, "SELECT InitSpatialMetadata()");
223+
ret = sqlite3_exec(sqlite_handle, sql, NULL, NULL, &errMsg);
224+
if (ret != SQLITE_OK)
225+
{
226+
QString errCause = tr( "Unable to initialize SpatialMetedata:\n" );
227+
errCause += QString::fromUtf8(errMsg);
228+
QMessageBox::warning( 0, tr( "SpatiaLite Database" ), errCause );
229+
sqlite3_free(errMsg);
230+
return;
231+
}
232+
spatial_ref_sys_init(sqlite_handle, 0);
233+
}
234+
190235
bool QgsNewSpatialiteLayerDialog::createDb()
191236
{
192237
QSettings settings;
238+
int ret;
239+
sqlite3 *sqlite_handle;
240+
char *errMsg = NULL;
193241

194242
if ( mDatabaseComboBox->currentText().isEmpty() )
195243
return false;
@@ -199,26 +247,41 @@ bool QgsNewSpatialiteLayerDialog::createDb()
199247
{
200248
QgsDebugMsg( "creating a new db" );
201249

202-
// copy the spatilite template to the user specified path
203-
QString spatialiteTemplate = QgsApplication::qgisSpatialiteDbTemplatePath();
204-
QFile spatialiteTemplateDb( spatialiteTemplate );
205-
206250
QFileInfo fullPath = QFileInfo( mDatabaseComboBox->currentText() );
207251
QDir path = fullPath.dir();
208252
QgsDebugMsg( QString( "making this dir: %1" ).arg( path.absolutePath() ) );
209253

210254
// Must be sure there is destination directory ~/.qgis
211255
QDir().mkpath( path.absolutePath( ) );
212256

213-
QgsDebugMsg( QString( "Copying %1 to %2" ).arg( spatialiteTemplate ).arg( newDb.fileName() ) );
214-
215-
//now copy the template db file into the chosen location
216-
if ( !spatialiteTemplateDb.copy( newDb.fileName() ) )
257+
// creating/opening the new database
258+
QString dbPath = newDb.fileName();
259+
spatialite_init(0);
260+
ret = sqlite3_open_v2(dbPath.toUtf8().constData(), &sqlite_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
261+
if (ret)
262+
{
263+
// an error occurred
264+
QString errCause = tr( "Could not create a new database\n" );
265+
errCause += QString::fromUtf8(sqlite3_errmsg(sqlite_handle));
266+
sqlite3_close(sqlite_handle);
267+
QMessageBox::warning( 0, tr( "SpatiaLite Database" ), errCause );
268+
pbnFindSRID->setEnabled( false );
269+
return false;
270+
}
271+
// activating Foreign Key constraints
272+
ret = sqlite3_exec(sqlite_handle, "PRAGMA foreign_keys = 1", NULL, 0, &errMsg);
273+
if (ret != SQLITE_OK)
217274
{
218-
QMessageBox::warning( 0, tr( "SpatiaLite Database" ), tr( "Could not copy the template database to new location" ) );
275+
QMessageBox::warning( 0, tr( "SpatiaLite Database" ), tr( "Unable to activate FOREIGN_KEY constraints" ) );
276+
sqlite3_free(errMsg);
277+
sqlite3_close(sqlite_handle);
219278
pbnFindSRID->setEnabled( false );
220279
return false;
221280
}
281+
initializeSpatialMetadata(sqlite_handle);
282+
283+
// all done: closing the DB connection
284+
sqlite3_close(sqlite_handle);
222285
}
223286

224287
QFileInfo fi( newDb );

‎src/app/qgsnewspatialitelayerdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNewSpatialiteL
5959
/** Create a new database */
6060
bool createDb();
6161

62+
/** Initializes SpatialMetadata db-tables */
63+
void initializeSpatialMetadata( sqlite3 *sqlite_handle );
64+
6265
static QString quotedIdentifier( QString id );
6366
static QString quotedValue( QString value );
6467
};

‎src/core/qgsapplication.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,6 @@ const QString QgsApplication::qgisMasterDbFilePath()
277277
return mPkgDataPath + QString( "/resources/qgis.db" );
278278
}
279279

280-
/*!
281-
Returns the path to the spatialite template db file.
282-
*/
283-
const QString QgsApplication::qgisSpatialiteDbTemplatePath()
284-
{
285-
return mPkgDataPath + QString( "/resources/spatialite.db" );
286-
}
287-
288280
/*!
289281
Returns the path to the settings directory in user's home dir
290282
*/

‎src/core/qgsapplication.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ class CORE_EXPORT QgsApplication: public QApplication
9090
//! Returns the path to the master qgis.db file.
9191
static const QString qgisMasterDbFilePath();
9292

93-
//! Returns the path to the spatialite template db file.
94-
//! @note added in 1.5
95-
static const QString qgisSpatialiteDbTemplatePath();
96-
9793
//! Returns the path to the settings directory in user's home dir
9894
static const QString qgisSettingsDirPath();
9995

‎src/core/spatialite/headers/spatialite.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,23 @@ extern "C"
5757
#endif
5858

5959
SPATIALITE_DECLARE const char *spatialite_version (void);
60-
SPATIALITE_DECLARE const char *virtualtext_version (void);
6160
SPATIALITE_DECLARE void spatialite_init (int verbose);
6261
SPATIALITE_DECLARE int dump_shapefile (sqlite3 * sqlite, char *table,
6362
char *column, char *charset,
6463
char *shp_path, char *geom_type,
6564
int verbose, int *rows);
6665
SPATIALITE_DECLARE int load_shapefile (sqlite3 * sqlite, char *shp_path,
6766
char *table, char *charset, int srid,
68-
char *column, int verbose,
67+
char *column, int coerce2d,
68+
int compressed, int verbose,
6969
int *rows);
70+
SPATIALITE_DECLARE int load_dbf (sqlite3 * sqlite, char *shp_path,
71+
char *table, char *charset, int verbose,
72+
int *rows);
7073
SPATIALITE_DECLARE double math_round (double value);
7174
SPATIALITE_DECLARE sqlite3_int64 math_llabs (sqlite3_int64 value);
75+
SPATIALITE_DECLARE void spatial_ref_sys_init (sqlite3 * sqlite,
76+
int verbose);
7277

7378
#ifdef __cplusplus
7479
}

‎src/core/spatialite/headers/spatialite/gaiaaux.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@ extern "C"
5858

5959
/* function prototipes */
6060

61-
GAIAAUX_DECLARE const char *gaiaGetLocaleCharset ();
61+
GAIAAUX_DECLARE const char *gaiaGetLocaleCharset (void);
6262
GAIAAUX_DECLARE int gaiaConvertCharset (char **buf, const char *fromCs,
6363
const char *toCs);
64-
GAIAAUX_DECLARE int gaiaToUTF8 (char **buf, const char *fromCs,
65-
const char *toCs);
6664
GAIAAUX_DECLARE void *gaiaCreateUTF8Converter (const char *fromCS);
6765
GAIAAUX_DECLARE void gaiaFreeUTF8Converter (void *cvtCS);
6866
GAIAAUX_DECLARE char *gaiaConvertToUTF8 (void *cvtCS, const char *buf,

‎src/core/spatialite/headers/spatialite/gaiaexif.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ extern "C"
6767
#define GAIA_PDF_BLOB 7
6868
#define GAIA_GEOMETRY_BLOB 8
6969
#define GAIA_TIFF_BLOB 9
70-
#define GAIA_WAVELET_BLOB 10
7170

7271
/* constants used for EXIF value types */
7372
#define GAIA_EXIF_NONE 0

‎src/core/spatialite/headers/spatialite/gaiageo.h

Lines changed: 172 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ extern "C"
158158
/* constants used for VirtualNetwork */
159159
#define GAIA_NET_START 0x67
160160
#define GAIA_NET64_START 0x68
161+
#define GAIA_NET64_A_STAR_START 0x69
161162
#define GAIA_NET_END 0x87
162163
#define GAIA_NET_HEADER 0xc0
163164
#define GAIA_NET_CODE 0xa6
@@ -169,6 +170,7 @@ extern "C"
169170
#define GAIA_NET_TO 0xa2
170171
#define GAIA_NET_GEOM 0xa3
171172
#define GAIA_NET_NAME 0xa4
173+
#define GAIA_NET_A_STAR_COEFF 0xa5
172174
#define GAIA_NET_BLOCK 0xed
173175

174176
/* constants used for Coordinate Dimensions */
@@ -346,6 +348,7 @@ extern "C"
346348
double MaxY; /* MBR - BBOX */
347349
int DimensionModel; /* (x,y), (x,y,z), (x,y,m) or (x,y,z,m) */
348350
int DeclaredType; /* the declared TYPE for this Geometry */
351+
struct gaiaGeomCollStruct *Next; /* Vanuatu - used for linked list */
349352
} gaiaGeomColl;
350353
typedef gaiaGeomColl *gaiaGeomCollPtr;
351354

@@ -374,7 +377,7 @@ extern "C"
374377
char *Name; /* field name */
375378
unsigned char Type; /* field type */
376379
int Offset; /* buffer offset [this field begins at *buffer+offset* and extends for *length* bytes */
377-
unsigned char Length; /* field total length [in bytes] */
380+
unsigned char Length; /* field total lenght [in bytes] */
378381
unsigned char Decimals; /* decimal positions */
379382
gaiaValuePtr Value; /* the current multitype value for this attribute */
380383
struct gaiaDbfFieldStruct *Next; /* pointer to next element in linked list */
@@ -391,12 +394,30 @@ extern "C"
391394
} gaiaDbfList;
392395
typedef gaiaDbfList *gaiaDbfListPtr;
393396

397+
typedef struct gaiaDbfStruct
398+
{
399+
/* DBF TYPE */
400+
int endian_arch;
401+
int Valid; /* 1 = ready to process */
402+
char *Path; /* the DBF path */
403+
FILE *flDbf; /* the DBF file handle */
404+
gaiaDbfListPtr Dbf; /* the DBF attributes list */
405+
unsigned char *BufDbf; /* the DBF I/O buffer */
406+
int DbfHdsz; /* the DBF header length */
407+
int DbfReclen; /* the DBF record length */
408+
int DbfSize; /* current DBF size */
409+
int DbfRecno; /* current DBF record number */
410+
void *IconvObj; /* opaque reference to ICONV converter */
411+
char *LastError; /* last error message */
412+
} gaiaDbf;
413+
typedef gaiaDbf *gaiaDbfPtr;
414+
394415
typedef struct gaiaShapefileStruct
395416
{
396417
/* SHAPEFILE TYPE */
397418
int endian_arch;
398419
int Valid; /* 1 = ready to process */
399-
int ReadOnly; /* read or wite mode */
420+
int ReadOnly; /* read or write mode */
400421
char *Path; /* the shapefile abstract path [no suffixes] */
401422
FILE *flShx; /* the SHX file handle */
402423
FILE *flShp; /* the SHP file handle */
@@ -423,6 +444,95 @@ extern "C"
423444
} gaiaShapefile;
424445
typedef gaiaShapefile *gaiaShapefilePtr;
425446

447+
typedef struct gaiaOutBufferStruct
448+
{
449+
/* a struct handling a dynamically growing output buffer */
450+
char *Buffer;
451+
int WriteOffset;
452+
int BufferSize;
453+
int Error;
454+
} gaiaOutBuffer;
455+
typedef gaiaOutBuffer *gaiaOutBufferPtr;
456+
457+
#ifndef OMIT_ICONV /* ICONV enabled: supporting text reader */
458+
459+
#define VRTTXT_FIELDS_MAX 65535
460+
#define VRTTXT_BLOCK_MAX 65535
461+
462+
#define VRTTXT_TEXT 1
463+
#define VRTTXT_INTEGER 2
464+
#define VRTTXT_DOUBLE 3
465+
#define VRTTXT_NULL 4
466+
467+
struct vrttxt_line
468+
{
469+
/* a struct representing a full LINE (aka Record) */
470+
off_t offset;
471+
int len;
472+
int field_offsets[VRTTXT_FIELDS_MAX];
473+
int num_fields;
474+
int error;
475+
};
476+
477+
struct vrttxt_row
478+
{
479+
/* a struct storing Row offsets */
480+
int line_no;
481+
off_t offset;
482+
int len;
483+
int num_fields;
484+
};
485+
486+
struct vrttxt_row_block
487+
{
488+
/*
489+
/ for efficiency sake, individuale Row offsets
490+
/ are grouped in reasonably sized blocks
491+
*/
492+
struct vrttxt_row rows[VRTTXT_BLOCK_MAX];
493+
int num_rows;
494+
int min_line_no;
495+
int max_line_no;
496+
struct vrttxt_row_block *next;
497+
};
498+
499+
struct vrttxt_column_header
500+
{
501+
/* a struct representing a Column (aka Field) header */
502+
char *name;
503+
int type;
504+
};
505+
506+
typedef struct vrttxt_reader
507+
{
508+
/* the main TXT-Reader struct */
509+
struct vrttxt_column_header columns[VRTTXT_FIELDS_MAX];
510+
FILE *text_file;
511+
void *toUtf8; /* the UTF-8 ICONV converter */
512+
char field_separator;
513+
char text_separator;
514+
char decimal_separator;
515+
int first_line_titles;
516+
int error;
517+
struct vrttxt_row_block *first;
518+
struct vrttxt_row_block *last;
519+
struct vrttxt_row **rows;
520+
int num_rows;
521+
int line_no;
522+
int max_fields;
523+
int current_buf_sz;
524+
int current_buf_off;
525+
char *line_buffer;
526+
char *field_buffer;
527+
int field_offsets[VRTTXT_FIELDS_MAX];
528+
int field_lens[VRTTXT_FIELDS_MAX];
529+
int max_current_field;
530+
int current_line_ready;
531+
} gaiaTextReader;
532+
typedef gaiaTextReader *gaiaTextReaderPtr;
533+
534+
#endif /* end ICONV (text reader) */
535+
426536
/* function prototipes */
427537

428538
GAIAGEO_DECLARE int gaiaEndianArch (void);
@@ -608,13 +718,6 @@ extern "C"
608718
unsigned int size);
609719
GAIAGEO_DECLARE void gaiaToWkb (gaiaGeomCollPtr geom,
610720
unsigned char **result, int *size);
611-
GAIAGEO_DECLARE int gaiaFromWkbNoCheck (const unsigned char *in,
612-
unsigned int szin,
613-
unsigned char **out, int *szout,
614-
int srid);
615-
GAIAGEO_DECLARE int gaiaToWkbNoCheck (const unsigned char *in,
616-
unsigned int szin,
617-
unsigned char **out, int *szout);
618721
GAIAGEO_DECLARE char *gaiaToHexWkb (gaiaGeomCollPtr geom);
619722
GAIAGEO_DECLARE void gaiaFreeValue (gaiaValuePtr p);
620723
GAIAGEO_DECLARE void gaiaSetNullValue (gaiaDbfFieldPtr field);
@@ -659,11 +762,28 @@ extern "C"
659762
GAIAGEO_DECLARE int gaiaWriteShpEntity (gaiaShapefilePtr shp,
660763
gaiaDbfListPtr entity);
661764
GAIAGEO_DECLARE void gaiaFlushShpHeaders (gaiaShapefilePtr shp);
765+
GAIAGEO_DECLARE gaiaDbfPtr gaiaAllocDbf (void);
766+
GAIAGEO_DECLARE void gaiaFreeDbf (gaiaDbfPtr dbf);
767+
GAIAGEO_DECLARE void gaiaOpenDbfRead (gaiaDbfPtr dbf,
768+
const char *path,
769+
const char *charFrom,
770+
const char *charTo);
771+
GAIAGEO_DECLARE int gaiaReadDbfEntity (gaiaDbfPtr shp, int current_row,
772+
int *deleted);
662773
GAIAGEO_DECLARE gaiaGeomCollPtr gaiaParseWkt (const unsigned char
663774
*dirty_buffer, short type);
664-
GAIAGEO_DECLARE void gaiaOutWkt (gaiaGeomCollPtr geom, char **result);
665-
GAIAGEO_DECLARE void gaiaOutSvg (gaiaGeomCollPtr geom, char **result,
666-
int relative, int precision);
775+
GAIAGEO_DECLARE void gaiaOutWkt (gaiaOutBufferPtr out_buf,
776+
gaiaGeomCollPtr geom);
777+
GAIAGEO_DECLARE void gaiaOutSvg (gaiaOutBufferPtr out_buf,
778+
gaiaGeomCollPtr geom, int relative,
779+
int precision);
780+
GAIAGEO_DECLARE void gaiaOutBareKml (gaiaOutBufferPtr out_buf,
781+
gaiaGeomCollPtr geom, int precision);
782+
GAIAGEO_DECLARE void gaiaOutFullKml (gaiaOutBufferPtr out_buf,
783+
const char *name, const char *desc,
784+
gaiaGeomCollPtr geom, int precision);
785+
GAIAGEO_DECLARE void gaiaOutGml (gaiaOutBufferPtr out_buf, int version,
786+
int precision, gaiaGeomCollPtr geom);
667787
GAIAGEO_DECLARE gaiaGeomCollPtr gaiaFromFgf (const unsigned char *blob,
668788
unsigned int size);
669789
GAIAGEO_DECLARE void gaiaToFgf (gaiaGeomCollPtr geom,
@@ -752,6 +872,21 @@ extern "C"
752872
double *coords, int vert);
753873
GAIAGEO_DECLARE int gaiaConvertLength (double value, int unit_from,
754874
int unit_to, double *cvt);
875+
GAIAGEO_DECLARE int gaiaLineGetPoint (gaiaLinestringPtr ln, int v,
876+
double *x, double *y, double *z,
877+
double *m);
878+
GAIAGEO_DECLARE int gaiaLineSetPoint (gaiaLinestringPtr ln, int v, double x,
879+
double y, double z, double m);
880+
GAIAGEO_DECLARE int gaiaRingGetPoint (gaiaRingPtr rng, int v, double *x,
881+
double *y, double *z, double *m);
882+
GAIAGEO_DECLARE int gaiaRingSetPoint (gaiaRingPtr rng, int v, double x,
883+
double y, double z, double m);
884+
GAIAGEO_DECLARE gaiaGeomCollPtr gaiaSanitize (gaiaGeomCollPtr org);
885+
GAIAGEO_DECLARE int gaiaIsToxic (gaiaGeomCollPtr org);
886+
GAIAGEO_DECLARE void gaiaOutBufferInitialize (gaiaOutBufferPtr buf);
887+
GAIAGEO_DECLARE void gaiaOutBufferReset (gaiaOutBufferPtr buf);
888+
GAIAGEO_DECLARE void gaiaAppendToOutBuffer (gaiaOutBufferPtr buf,
889+
const char *text);
755890

756891
#ifndef OMIT_PROJ /* including PROJ.4 */
757892

@@ -765,6 +900,12 @@ extern "C"
765900

766901
#ifndef OMIT_GEOS /* including GEOS */
767902

903+
GAIAGEO_DECLARE void gaiaResetGeosMsg (void);
904+
GAIAGEO_DECLARE const char *gaiaGetGeosErrorMsg (void);
905+
GAIAGEO_DECLARE const char *gaiaGetGeosWarningMsg (void);
906+
GAIAGEO_DECLARE void gaiaSetGeosErrorMsg (const char *msg);
907+
GAIAGEO_DECLARE void gaiaSetGeosWarningMsg (const char *msg);
908+
768909
GAIAGEO_DECLARE int gaiaGeomCollEquals (gaiaGeomCollPtr geom1,
769910
gaiaGeomCollPtr geom2);
770911
GAIAGEO_DECLARE int gaiaGeomCollDisjoint (gaiaGeomCollPtr geom1,
@@ -832,6 +973,25 @@ extern "C"
832973

833974
#endif /* end including GEOS */
834975

976+
#ifndef OMIT_ICONV /* ICONV enabled: supporting text reader */
977+
GAIAGEO_DECLARE gaiaTextReaderPtr gaiaTextReaderAlloc (const char *path,
978+
char field_separator,
979+
char text_separator,
980+
char
981+
decimal_separator,
982+
int
983+
first_line_titles,
984+
const char
985+
*encoding);
986+
GAIAGEO_DECLARE void gaiaTextReaderDestroy (gaiaTextReaderPtr reader);
987+
GAIAGEO_DECLARE int gaiaTextReaderParse (gaiaTextReaderPtr reader);
988+
GAIAGEO_DECLARE int gaiaTextReaderGetRow (gaiaTextReaderPtr reader,
989+
int row_num);
990+
GAIAGEO_DECLARE int gaiaTextReaderFetchField (gaiaTextReaderPtr reader,
991+
int field_num, int *type,
992+
const char **value);
993+
#endif /* end ICONV (text reader) */
994+
835995
#ifdef __cplusplus
836996
}
837997
#endif

‎src/core/spatialite/headers/spatialite/spatialite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
4343
*/
4444

4545
int virtualshape_extension_init (sqlite3 * db);
46+
int virtualdbf_extension_init (sqlite3 * db);
4647
int virtualtext_extension_init (sqlite3 * db);
4748
int virtualnetwork_extension_init (sqlite3 * db);
4849
int virtualfdo_extension_init (sqlite3 * db);

‎src/core/spatialite/headers/spatialite/sqlite3.h

Lines changed: 2335 additions & 1697 deletions
Large diffs are not rendered by default.

‎src/core/spatialite/headers/spatialite/sqlite3ext.h

Lines changed: 230 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,232 @@
1+
/*
2+
** alias MACROs to avoid any potential collision
3+
** for linker symbols declared into the sqlite3 code
4+
** internally embedded into SpatiaLite
5+
*/
6+
#define sqlite3_version SPLite3_version
7+
#define sqlite3_libversion SPLite3_libversion
8+
#define sqlite3_sourceid SPLite3_sourceid
9+
#define sqlite3_libversion_number SPLite3_libversion_number
10+
#define sqlite3_compileoption_used SPLite3_compileoption_used
11+
#define sqlite3_compileoption_get SPLite3_compileoption_get
12+
#define sqlite3_threadsafe SPLite3_threadsafe
13+
#define sqlite3_close SPLite3_close
14+
#define sqlite3_exec SPLite3_exec
15+
#define sqlite3_initialize SPLite3_initialize
16+
#define sqlite3_shutdown SPLite3_shutdown
17+
#define sqlite3_os_init SPLite3_os_init
18+
#define sqlite3_os_end SPLite3_os_end
19+
#define sqlite3_config SPLite3_config
20+
#define sqlite3_db_config SPLite3_db_config
21+
#define sqlite3_extended_result_codes SPLite3_extended_result_codes
22+
#define sqlite3_last_insert_rowid SPLite3_last_insert_rowid
23+
#define sqlite3_changes SPLite3_changes
24+
#define sqlite3_total_changes SPLite3_total_changes
25+
#define sqlite3_interrupt SPLite3_interrupt
26+
#define sqlite3_complete SPLite3_complete
27+
#define sqlite3_complete16 SPLite3_complete16
28+
#define sqlite3_busy_handler SPLite3_busy_handler
29+
#define sqlite3_busy_timeout SPLite3_busy_timeout
30+
#define sqlite3_get_table SPLite3_get_table
31+
#define sqlite3_free_table SPLite3_free_table
32+
#define sqlite3_mprintf SPLite3_mprintf
33+
#define sqlite3_vmprintf SPLite3_vmprintf
34+
#define sqlite3_snprintf SPLite3_snprintf
35+
#define sqlite3_malloc SPLite3_malloc
36+
#define sqlite3_realloc SPLite3_realloc
37+
#define sqlite3_free SPLite3_free
38+
#define sqlite3_memory_used SPLite3_memory_used
39+
#define sqlite3_memory_highwater SPLite3_memory_highwater
40+
#define sqlite3_randomness SPLite3_randomness
41+
#define sqlite3_set_authorizer SPLite3_set_authorizer
42+
#define sqlite3_trace SPLite3_trace
43+
#define sqlite3_progress_handler SPLite3_progress_handler
44+
#define sqlite3_open SPLite3_open
45+
#define sqlite3_open16 SPLite3_open16
46+
#define sqlite3_open_v2 SPLite3_open_v2
47+
#define sqlite3_errcode SPLite3_errcode
48+
#define sqlite3_extended_errcode SPLite3_extended_errcode
49+
#define sqlite3_errmsg SPLite3_errmsg
50+
#define sqlite3_errmsg16 SPLite3_errmsg16
51+
#define sqlite3_limit SPLite3_limit
52+
#define sqlite3_prepare SPLite3_prepare
53+
#define sqlite3_prepare_v2 SPLite3_prepare_v2
54+
#define sqlite3_prepare16 SPLite3_prepare16
55+
#define sqlite3_prepare16_v2 SPLite3_prepare16_v2
56+
#define sqlite3_sql SPLite3_sql
57+
#define sqlite3_bind_blob SPLite3_bind_blob
58+
#define sqlite3_bind_double SPLite3_bind_double
59+
#define sqlite3_bind_int SPLite3_bind_int
60+
#define sqlite3_bind_int64 SPLite3_bind_int64
61+
#define sqlite3_bind_null SPLite3_bind_null
62+
#define sqlite3_bind_text SPLite3_bind_text
63+
#define sqlite3_bind_text16 SPLite3_bind_text16
64+
#define sqlite3_bind_value SPLite3_bind_value
65+
#define sqlite3_bind_zeroblob SPLite3_bind_zeroblob
66+
#define sqlite3_bind_parameter_count SPLite3_bind_parameter_count
67+
#define sqlite3_bind_parameter_name SPLite3_bind_parameter_name
68+
#define sqlite3_bind_parameter_index SPLite3_bind_parameter_index
69+
#define sqlite3_clear_bindings SPLite3_clear_bindings
70+
#define sqlite3_column_count SPLite3_column_count
71+
#define sqlite3_column_name SPLite3_column_name
72+
#define sqlite3_column_name16 SPLite3_column_name16
73+
#define sqlite3_column_database_name SPLite3_column_database_name
74+
#define sqlite3_column_database_name16 SPLite3_column_database_name16
75+
#define sqlite3_column_table_name SPLite3_column_table_name
76+
#define sqlite3_column_table_name16 SPLite3_column_table_name16
77+
#define sqlite3_column_origin_name SPLite3_column_origin_name
78+
#define sqlite3_column_origin_name16 SPLite3_column_origin_name16
79+
#define sqlite3_column_decltype SPLite3_column_decltype
80+
#define sqlite3_column_decltype16 SPLite3_column_decltype16
81+
#define sqlite3_step SPLite3_step
82+
#define sqlite3_data_count SPLite3_data_count
83+
#define sqlite3_column_blob SPLite3_column_blob
84+
#define sqlite3_column_bytes SPLite3_column_bytes
85+
#define sqlite3_column_bytes16 SPLite3_column_bytes16
86+
#define sqlite3_column_double SPLite3_column_double
87+
#define sqlite3_column_int SPLite3_column_int
88+
#define sqlite3_column_int64 SPLite3_column_int64
89+
#define sqlite3_column_text SPLite3_column_text
90+
#define sqlite3_column_text16 SPLite3_column_text16
91+
#define sqlite3_column_type SPLite3_column_type
92+
#define sqlite3_column_value SPLite3_column_value
93+
#define sqlite3_finalize SPLite3_finalize
94+
#define sqlite3_reset SPLite3_reset
95+
#define sqlite3_create_function SPLite3_create_function
96+
#define sqlite3_create_function16 SPLite3_create_function16
97+
#define sqlite3_create_function_v2 SPLite3_create_function_v2
98+
#define sqlite3_value_blob SPLite3_value_blob
99+
#define sqlite3_value_bytes SPLite3_value_bytes
100+
#define sqlite3_value_bytes16 SPLite3_value_bytes16
101+
#define sqlite3_value_double SPLite3_value_double
102+
#define sqlite3_value_int SPLite3_value_int
103+
#define sqlite3_value_int64 SPLite3_value_int64
104+
#define sqlite3_value_text SPLite3_value_text
105+
#define sqlite3_value_text16 SPLite3_value_text16
106+
#define sqlite3_value_text16le SPLite3_value_text16le
107+
#define sqlite3_value_text16be SPLite3_value_text16be
108+
#define sqlite3_value_type SPLite3_value_type
109+
#define sqlite3_value_numeric_type SPLite3_value_numeric_type
110+
#define sqlite3_aggregate_context SPLite3_aggregate_context
111+
#define sqlite3_user_data SPLite3_user_data
112+
#define sqlite3_context_db_handle SPLite3_context_db_handle
113+
#define sqlite3_get_auxdata SPLite3_get_auxdata
114+
#define sqlite3_set_auxdata SPLite3_set_auxdata
115+
#define sqlite3_result_blob SPLite3_result_blob
116+
#define sqlite3_result_double SPLite3_result_double
117+
#define sqlite3_result_error SPLite3_result_error
118+
#define sqlite3_result_error16 SPLite3_result_error16
119+
#define sqlite3_result_error_toobig SPLite3_result_error_toobig
120+
#define sqlite3_result_error_nomem SPLite3_result_error_nomem
121+
#define sqlite3_result_error_code SPLite3_result_error_code
122+
#define sqlite3_result_int SPLite3_result_int
123+
#define sqlite3_result_int64 SPLite3_result_int64
124+
#define sqlite3_result_null SPLite3_result_null
125+
#define sqlite3_result_text SPLite3_result_text
126+
#define sqlite3_result_text16 SPLite3_result_text16
127+
#define sqlite3_result_text16le SPLite3_result_text16le
128+
#define sqlite3_result_text16be SPLite3_result_text16be
129+
#define sqlite3_result_value SPLite3_result_value
130+
#define sqlite3_result_zeroblob SPLite3_result_zeroblob
131+
#define sqlite3_create_collation SPLite3_create_collation
132+
#define sqlite3_create_collation_v2 SPLite3_create_collation_v2
133+
#define sqlite3_create_collation16 SPLite3_create_collation16
134+
#define sqlite3_collation_needed SPLite3_collation_needed
135+
#define sqlite3_collation_needed16 SPLite3_collation_needed16
136+
#define sqlite3_key SPLite3_key
137+
#define sqlite3_rekey SPLite3_rekey
138+
#define sqlite3_activate_see SPLite3_activate_see
139+
#define sqlite3_activate_cerod SPLite3_activate_cerod
140+
#define sqlite3_sleep SPLite3_sleep
141+
#define sqlite3_temp_directory SPLite3_temp_directory
142+
#define sqlite3_get_autocommit SPLite3_get_autocommit
143+
#define sqlite3_db_handle SPLite3_db_handle
144+
#define sqlite3_next_stmt SPLite3_next_stmt
145+
#define sqlite3_commit_hook SPLite3_commit_hook
146+
#define sqlite3_rollback_hook SPLite3_rollback_hook
147+
#define sqlite3_update_hook SPLite3_update_hook
148+
#define sqlite3_enable_shared_cache SPLite3_enable_shared_cache
149+
#define sqlite3_release_memory SPLite3_release_memory
150+
#define sqlite3_soft_heap_limit64 SPLite3_soft_heap_limit64
151+
#define sqlite3_table_column_metadata SPLite3_table_column_metadata
152+
#define sqlite3_load_extension SPLite3_load_extension
153+
#define sqlite3_enable_load_extension SPLite3_enable_load_extension
154+
#define sqlite3_auto_extension SPLite3_auto_extension
155+
#define sqlite3_reset_auto_extension SPLite3_reset_auto_extension
156+
#define sqlite3_create_module SPLite3_create_module
157+
#define sqlite3_create_module_v2 SPLite3_create_module_v2
158+
#define sqlite3_declare_vtab SPLite3_declare_vtab
159+
#define sqlite3_overload_function SPLite3_overload_function
160+
#define sqlite3_blob_open SPLite3_blob_open
161+
#define sqlite3_blob_close SPLite3_blob_close
162+
#define sqlite3_blob_bytes SPLite3_blob_bytes
163+
#define sqlite3_blob_read SPLite3_blob_read
164+
#define sqlite3_blob_write SPLite3_blob_write
165+
#define sqlite3_vfs_find SPLite3_vfs_find
166+
#define sqlite3_vfs_register SPLite3_vfs_register
167+
#define sqlite3_vfs_unregister SPLite3_vfs_unregister
168+
#define sqlite3_mutex_alloc SPLite3_mutex_alloc
169+
#define sqlite3_mutex_free SPLite3_mutex_free
170+
#define sqlite3_mutex_enter SPLite3_mutex_enter
171+
#define sqlite3_mutex_try SPLite3_mutex_try
172+
#define sqlite3_mutex_leave SPLite3_mutex_leave
173+
#define sqlite3_mutex_held SPLite3_mutex_held
174+
#define sqlite3_mutex_notheld SPLite3_mutex_notheld
175+
#define sqlite3_db_mutex SPLite3_db_mutex
176+
#define sqlite3_file_control SPLite3_file_control
177+
#define sqlite3_test_control SPLite3_test_control
178+
#define sqlite3_status SPLite3_status
179+
#define sqlite3_db_status SPLite3_db_status
180+
#define sqlite3_stmt_status SPLite3_stmt_status
181+
#define sqlite3_backup_init SPLite3_backup_init
182+
#define sqlite3_backup_step SPLite3_backup_step
183+
#define sqlite3_backup_finish SPLite3_backup_finish
184+
#define sqlite3_backup_remaining SPLite3_backup_remaining
185+
#define sqlite3_backup_pagecount SPLite3_backup_pagecount
186+
#define sqlite3_unlock_notify SPLite3_unlock_notify
187+
#define sqlite3_strnicmp SPLite3_strnicmp
188+
#define sqlite3_log SPLite3_log
189+
#define sqlite3_wal_hook SPLite3_wal_hook
190+
#define sqlite3_wal_autocheckpoint SPLite3_wal_autocheckpoint
191+
#define sqlite3_wal_checkpoint SPLite3_wal_checkpoint
192+
#define sqlite3_rtree_geometry_callback SPLite3_rtree_geometry_callback
193+
#define sqlite3_memdebug_vfs_oom_test SPLite3_memdebug_vfs_oom_test
194+
#define sqlite3_memory_alarm SPLite3_memory_alarm
195+
#define sqlite3_soft_heap_limit SPLite3_soft_heap_limit
196+
#define sqlite3_io_error_hit SPLite3_io_error_hit
197+
#define sqlite3_io_error_hardhit SPLite3_io_error_hardhit
198+
#define sqlite3_io_error_pending SPLite3_io_error_pending
199+
#define sqlite3_io_error_persist SPLite3_io_error_persist
200+
#define sqlite3_io_error_benign SPLite3_io_error_benign
201+
#define sqlite3_diskfull_pending SPLite3_diskfull_pending
202+
#define sqlite3_diskfull SPLite3_diskfull
203+
#define sqlite3_open_file_count SPLite3_open_file_count
204+
#define sqlite3_sync_count SPLite3_sync_count
205+
#define sqlite3_fullsync_count SPLite3_fullsync_count
206+
#define sqlite3_current_time SPLite3_current_time
207+
#define sqlite3_hostid_num SPLite3_hostid_num
208+
#define sqlite3_os_type SPLite3_os_type
209+
#define sqlite3_win32_mbcs_to_utf8 SPLite3_win32_mbcs_to_utf8
210+
#define sqlite3_pager_readdb_count SPLite3_pager_readdb_count
211+
#define sqlite3_pager_writedb_count SPLite3_pager_writedb_count
212+
#define sqlite3_pager_writej_count SPLite3_pager_writej_count
213+
#define sqlite3_opentemp_count SPLite3_opentemp_count
214+
#define sqlite3_expired SPLite3_expired
215+
#define sqlite3_aggregate_count SPLite3_aggregate_count
216+
#define sqlite3_transfer_bindings SPLite3_transfer_bindings
217+
#define sqlite3_search_count SPLite3_search_count
218+
#define sqlite3_interrupt_count SPLite3_interrupt_count
219+
#define sqlite3_sort_count SPLite3_sort_count
220+
#define sqlite3_max_blobsize SPLite3_max_blobsize
221+
#define sqlite3_found_count SPLite3_found_count
222+
#define sqlite3_like_count SPLite3_like_count
223+
#define sqlite3_xferopt_count SPLite3_xferopt_count
224+
#define sqlite3_profile SPLite3_profile
225+
#define sqlite3_global_recover SPLite3_global_recover
226+
#define sqlite3_thread_cleanup SPLite3_thread_cleanup
227+
#define sqlite3_fts3_enable_parentheses SPLite3_fts3_enable_parentheses
228+
/* end SpatiaLite/sqlite3 alias macros */
229+
1230
/*
2231
** 2006 June 7
3232
**
@@ -14,8 +243,6 @@
14243
** an SQLite instance. Shared libraries that intend to be loaded
15244
** as extensions by SQLite should #include this file instead of
16245
** sqlite3.h.
17-
**
18-
** @(#) $Id: sqlite3ext.h,v 1.25 2008/10/12 00:27:54 shane Exp $
19246
*/
20247
#ifndef _SQLITE3EXT_H_
21248
#define _SQLITE3EXT_H_
@@ -197,7 +424,7 @@ struct sqlite3_api_routines {
197424

198425
/*
199426
** The following macros redefine the API routines so that they are
200-
** redirected through the global sqlite3_api structure.
427+
** redirected throught the global sqlite3_api structure.
201428
**
202429
** This header file is also used by the loadext.c source file
203430
** (part of the main SQLite library - not an extension) so that

‎src/core/spatialite/spatialite.c

Lines changed: 139624 additions & 20100 deletions
Large diffs are not rendered by default.

‎src/core/spatialite/sqlite3.c

Lines changed: 43764 additions & 33663 deletions
Large diffs are not rendered by default.

‎src/plugins/offline_editing/offline_editing.cpp

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,56 @@ void QgsOfflineEditing::synchronize( QgsLegendInterface* legendInterface )
253253
sqlite3_close( db );
254254
}
255255

256+
void QgsOfflineEditing::initializeSpatialMetadata(sqlite3 *sqlite_handle)
257+
{
258+
// attempting to perform self-initialization for a newly created DB
259+
int ret;
260+
char sql[1024];
261+
char *errMsg = NULL;
262+
int count;
263+
int i;
264+
char **results;
265+
int rows;
266+
int columns;
267+
268+
if (sqlite_handle == NULL)
269+
return;
270+
// checking if this DB is really empty
271+
strcpy(sql, "SELECT Count(*) from sqlite_master");
272+
ret = sqlite3_get_table(sqlite_handle, sql, &results, &rows, &columns, NULL);
273+
if (ret != SQLITE_OK)
274+
return;
275+
if (rows < 1)
276+
;
277+
else
278+
{
279+
for (i = 1; i <= rows; i++)
280+
count = atoi(results[(i * columns) + 0]);
281+
}
282+
sqlite3_free_table(results);
283+
284+
if (count > 0)
285+
return;
286+
287+
// all right, it's empty: proceding to initialize
288+
strcpy(sql, "SELECT InitSpatialMetadata()");
289+
ret = sqlite3_exec(sqlite_handle, sql, NULL, NULL, &errMsg);
290+
if (ret != SQLITE_OK)
291+
{
292+
QString errCause = tr( "Unable to initialize SpatialMetedata:\n" );
293+
errCause += QString::fromUtf8(errMsg);
294+
showWarning( errCause );
295+
sqlite3_free(errMsg);
296+
return;
297+
}
298+
spatial_ref_sys_init(sqlite_handle, 0);
299+
}
300+
256301
bool QgsOfflineEditing::createSpatialiteDB( const QString& offlineDbPath )
257302
{
303+
int ret;
304+
sqlite3 *sqlite_handle;
305+
char *errMsg = NULL;
258306
QFile newDb( offlineDbPath );
259307
if ( newDb.exists() )
260308
{
@@ -263,22 +311,38 @@ bool QgsOfflineEditing::createSpatialiteDB( const QString& offlineDbPath )
263311

264312
// see also QgsNewSpatialiteLayerDialog::createDb()
265313

266-
// copy the spatialite template to the user specified path
267-
QString spatialiteTemplate = QgsApplication::qgisSpatialiteDbTemplatePath();
268-
QFile spatialiteTemplateDb( spatialiteTemplate );
269-
270314
QFileInfo fullPath = QFileInfo( offlineDbPath );
271315
QDir path = fullPath.dir();
272316

273317
// Must be sure there is destination directory ~/.qgis
274318
QDir().mkpath( path.absolutePath( ) );
275319

276-
// now copy the template db file into the chosen location
277-
if ( !spatialiteTemplateDb.copy( newDb.fileName() ) )
320+
// creating/opening the new database
321+
QString dbPath = newDb.fileName();
322+
spatialite_init(0);
323+
ret = sqlite3_open_v2(dbPath.toUtf8().constData(), &sqlite_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
324+
if (ret)
325+
{
326+
// an error occurred
327+
QString errCause = tr( "Could not create a new database\n" );
328+
errCause += QString::fromUtf8(sqlite3_errmsg(sqlite_handle));
329+
sqlite3_close(sqlite_handle);
330+
showWarning( errCause );
331+
return false;
332+
}
333+
// activating Foreign Key constraints
334+
ret = sqlite3_exec(sqlite_handle, "PRAGMA foreign_keys = 1", NULL, 0, &errMsg);
335+
if (ret != SQLITE_OK)
278336
{
279-
showWarning( tr( "Could not copy the template database to new location" ) );
337+
showWarning( tr( "Unable to activate FOREIGN_KEY constraints" ) );
338+
sqlite3_free(errMsg);
339+
sqlite3_close(sqlite_handle);
280340
return false;
281341
}
342+
initializeSpatialMetadata(sqlite_handle);
343+
344+
// all done: closing the DB connection
345+
sqlite3_close(sqlite_handle);
282346

283347
return true;
284348
}

‎src/plugins/offline_editing/offline_editing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class QgsOfflineEditing : public QObject
4444
void synchronize( QgsLegendInterface* legendInterface );
4545

4646
private:
47+
void initializeSpatialMetadata( sqlite3 *sqlite_handle );
4748
bool createSpatialiteDB( const QString& offlineDbPath );
4849
void createLoggingTables( sqlite3* db );
4950
void copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, const QString& offlineDbPath );

‎src/providers/spatialite/qgsspatialiteprovider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ email : a.furieri@lqt.it
1616

1717
extern "C"
1818
{
19+
#include <sys/types.h>
1920
#include <sqlite3.h>
2021
#include <spatialite/gaiageo.h>
2122
#include <spatialite.h>

0 commit comments

Comments
 (0)
Please sign in to comment.