Skip to content

Commit cdae0f6

Browse files
author
esseffe
committed
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

19 files changed

+186284
-55513
lines changed

AUTHORS

+1
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

+1
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

-4
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

+72-9
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

+3
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

-8
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

-4
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

+7-2
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

+1-3
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

-1
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

0 commit comments

Comments
 (0)