Skip to content

Commit

Permalink
upgrading to SpatiaLite 2.4.0-RC4
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14763 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
esseffe committed Nov 25, 2010
1 parent d3b07d4 commit cdae0f6
Show file tree
Hide file tree
Showing 19 changed files with 186,284 additions and 55,513 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -40,3 +40,4 @@ Carson J. Q. Farmer <carson dot farmer at gmail dot com>
Lorenzo Masini <lorenxo86 at gmail.com>
Werner Macho <werner.macho at gmail.com>
Giuseppe Sucameli <brush.tyler at gmail.com>
Alessandro Furieri <a.furieri at lqt.it>
1 change: 1 addition & 0 deletions debian/copyright
Expand Up @@ -38,6 +38,7 @@ reported:
Lorenzo Masini <lorenxo86 at gmail.com>
Werner Macho <werner.macho at gmail.com>
Giuseppe Sucameli <brush.tyler at gmail.com>
Alessandro Furieri <a.furieri at lqt.it>

Copyright:

Expand Down
4 changes: 0 additions & 4 deletions python/core/qgsapplication.sip
Expand Up @@ -139,10 +139,6 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
//! Returns the path to the master qgis.db file.
static const QString qgisMasterDbFilePath();

//! Returns the path to the spatialite template db file.
//! @note added in 1.5
static const QString qgisSpatialiteDbTemplatePath();

//! Returns the path to the settings directory in user's home dir
static const QString qgisSettingsDirPath();

Expand Down
81 changes: 72 additions & 9 deletions src/app/qgsnewspatialitelayerdialog.cpp
Expand Up @@ -187,9 +187,57 @@ void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked()
}
}

void QgsNewSpatialiteLayerDialog::initializeSpatialMetadata(sqlite3 *sqlite_handle)
{
// attempting to perform self-initialization for a newly created DB
int ret;
char sql[1024];
char *errMsg = NULL;
int count;
int i;
char **results;
int rows;
int columns;

if (sqlite_handle == NULL)
return;
// checking if this DB is really empty
strcpy(sql, "SELECT Count(*) from sqlite_master");
ret = sqlite3_get_table(sqlite_handle, sql, &results, &rows, &columns, NULL);
if (ret != SQLITE_OK)
return;
if (rows < 1)
;
else
{
for (i = 1; i <= rows; i++)
count = atoi(results[(i * columns) + 0]);
}
sqlite3_free_table(results);

if (count > 0)
return;

// all right, it's empty: proceding to initialize
strcpy(sql, "SELECT InitSpatialMetadata()");
ret = sqlite3_exec(sqlite_handle, sql, NULL, NULL, &errMsg);
if (ret != SQLITE_OK)
{
QString errCause = tr( "Unable to initialize SpatialMetedata:\n" );
errCause += QString::fromUtf8(errMsg);
QMessageBox::warning( 0, tr( "SpatiaLite Database" ), errCause );
sqlite3_free(errMsg);
return;
}
spatial_ref_sys_init(sqlite_handle, 0);
}

bool QgsNewSpatialiteLayerDialog::createDb()
{
QSettings settings;
int ret;
sqlite3 *sqlite_handle;
char *errMsg = NULL;

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

// copy the spatilite template to the user specified path
QString spatialiteTemplate = QgsApplication::qgisSpatialiteDbTemplatePath();
QFile spatialiteTemplateDb( spatialiteTemplate );

QFileInfo fullPath = QFileInfo( mDatabaseComboBox->currentText() );
QDir path = fullPath.dir();
QgsDebugMsg( QString( "making this dir: %1" ).arg( path.absolutePath() ) );

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

QgsDebugMsg( QString( "Copying %1 to %2" ).arg( spatialiteTemplate ).arg( newDb.fileName() ) );

//now copy the template db file into the chosen location
if ( !spatialiteTemplateDb.copy( newDb.fileName() ) )
// creating/opening the new database
QString dbPath = newDb.fileName();
spatialite_init(0);
ret = sqlite3_open_v2(dbPath.toUtf8().constData(), &sqlite_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if (ret)
{
// an error occurred
QString errCause = tr( "Could not create a new database\n" );
errCause += QString::fromUtf8(sqlite3_errmsg(sqlite_handle));
sqlite3_close(sqlite_handle);
QMessageBox::warning( 0, tr( "SpatiaLite Database" ), errCause );
pbnFindSRID->setEnabled( false );
return false;
}
// activating Foreign Key constraints
ret = sqlite3_exec(sqlite_handle, "PRAGMA foreign_keys = 1", NULL, 0, &errMsg);
if (ret != SQLITE_OK)
{
QMessageBox::warning( 0, tr( "SpatiaLite Database" ), tr( "Could not copy the template database to new location" ) );
QMessageBox::warning( 0, tr( "SpatiaLite Database" ), tr( "Unable to activate FOREIGN_KEY constraints" ) );
sqlite3_free(errMsg);
sqlite3_close(sqlite_handle);
pbnFindSRID->setEnabled( false );
return false;
}
initializeSpatialMetadata(sqlite_handle);

// all done: closing the DB connection
sqlite3_close(sqlite_handle);
}

QFileInfo fi( newDb );
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsnewspatialitelayerdialog.h
Expand Up @@ -59,6 +59,9 @@ class QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNewSpatialiteL
/** Create a new database */
bool createDb();

/** Initializes SpatialMetadata db-tables */
void initializeSpatialMetadata( sqlite3 *sqlite_handle );

static QString quotedIdentifier( QString id );
static QString quotedValue( QString value );
};
Expand Down
8 changes: 0 additions & 8 deletions src/core/qgsapplication.cpp
Expand Up @@ -277,14 +277,6 @@ const QString QgsApplication::qgisMasterDbFilePath()
return mPkgDataPath + QString( "/resources/qgis.db" );
}

/*!
Returns the path to the spatialite template db file.
*/
const QString QgsApplication::qgisSpatialiteDbTemplatePath()
{
return mPkgDataPath + QString( "/resources/spatialite.db" );
}

/*!
Returns the path to the settings directory in user's home dir
*/
Expand Down
4 changes: 0 additions & 4 deletions src/core/qgsapplication.h
Expand Up @@ -90,10 +90,6 @@ class CORE_EXPORT QgsApplication: public QApplication
//! Returns the path to the master qgis.db file.
static const QString qgisMasterDbFilePath();

//! Returns the path to the spatialite template db file.
//! @note added in 1.5
static const QString qgisSpatialiteDbTemplatePath();

//! Returns the path to the settings directory in user's home dir
static const QString qgisSettingsDirPath();

Expand Down
9 changes: 7 additions & 2 deletions src/core/spatialite/headers/spatialite.h
Expand Up @@ -57,18 +57,23 @@ extern "C"
#endif

SPATIALITE_DECLARE const char *spatialite_version (void);
SPATIALITE_DECLARE const char *virtualtext_version (void);
SPATIALITE_DECLARE void spatialite_init (int verbose);
SPATIALITE_DECLARE int dump_shapefile (sqlite3 * sqlite, char *table,
char *column, char *charset,
char *shp_path, char *geom_type,
int verbose, int *rows);
SPATIALITE_DECLARE int load_shapefile (sqlite3 * sqlite, char *shp_path,
char *table, char *charset, int srid,
char *column, int verbose,
char *column, int coerce2d,
int compressed, int verbose,
int *rows);
SPATIALITE_DECLARE int load_dbf (sqlite3 * sqlite, char *shp_path,
char *table, char *charset, int verbose,
int *rows);
SPATIALITE_DECLARE double math_round (double value);
SPATIALITE_DECLARE sqlite3_int64 math_llabs (sqlite3_int64 value);
SPATIALITE_DECLARE void spatial_ref_sys_init (sqlite3 * sqlite,
int verbose);

#ifdef __cplusplus
}
Expand Down
4 changes: 1 addition & 3 deletions src/core/spatialite/headers/spatialite/gaiaaux.h
Expand Up @@ -58,11 +58,9 @@ extern "C"

/* function prototipes */

GAIAAUX_DECLARE const char *gaiaGetLocaleCharset ();
GAIAAUX_DECLARE const char *gaiaGetLocaleCharset (void);
GAIAAUX_DECLARE int gaiaConvertCharset (char **buf, const char *fromCs,
const char *toCs);
GAIAAUX_DECLARE int gaiaToUTF8 (char **buf, const char *fromCs,
const char *toCs);
GAIAAUX_DECLARE void *gaiaCreateUTF8Converter (const char *fromCS);
GAIAAUX_DECLARE void gaiaFreeUTF8Converter (void *cvtCS);
GAIAAUX_DECLARE char *gaiaConvertToUTF8 (void *cvtCS, const char *buf,
Expand Down
1 change: 0 additions & 1 deletion src/core/spatialite/headers/spatialite/gaiaexif.h
Expand Up @@ -67,7 +67,6 @@ extern "C"
#define GAIA_PDF_BLOB 7
#define GAIA_GEOMETRY_BLOB 8
#define GAIA_TIFF_BLOB 9
#define GAIA_WAVELET_BLOB 10

/* constants used for EXIF value types */
#define GAIA_EXIF_NONE 0
Expand Down

0 comments on commit cdae0f6

Please sign in to comment.