Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Check Sqlite version to switch metadata initialization parameter
  • Loading branch information
giohappy committed May 28, 2014
1 parent afd4687 commit 8c67cdf
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/analysis/openstreetmap/qgsosmimport.cpp
Expand Up @@ -17,6 +17,7 @@

#include <spatialite.h>

#include <QStringList>
#include <QXmlStreamReader>


Expand Down Expand Up @@ -134,14 +135,30 @@ bool QgsOSMXmlImport::createIndexes()

bool QgsOSMXmlImport::createDatabase()
{
char **results;
int rows, columns;
if ( sqlite3_open_v2( mDbFileName.toUtf8().data(), &mDatabase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0 ) != SQLITE_OK )
return false;

bool above41 = false;
int ret = sqlite3_get_table( mDatabase, "select spatialite_version()", &results, &rows, &columns, NULL );
if ( ret == SQLITE_OK && rows == 1 && columns == 1 )
{
QString version = QString::fromUtf8( results[1] );
QStringList parts = version.split( " ", QString::SkipEmptyParts );
if ( parts.size() >= 1 )
{
QStringList verparts = parts[0].split( ".", QString::SkipEmptyParts );
above41 = verparts.size() >= 2 && ( verparts[0].toInt() > 4 || ( verparts[0].toInt() == 4 && verparts[1].toInt() >= 1 ) );
}
}
sqlite3_free_table( results );

const char* sqlInitStatements[] =
{
"PRAGMA cache_size = 100000", // TODO!!!
"PRAGMA synchronous = OFF", // TODO!!!
"SELECT InitSpatialMetadata(1)",
above41 ? "SELECT InitSpatialMetadata(1)" : "SELECT InitSpatialMetadata()",
"CREATE TABLE nodes ( id INTEGER PRIMARY KEY, lat REAL, lon REAL )",
"CREATE TABLE nodes_tags ( id INTEGER, k TEXT, v TEXT )",
"CREATE TABLE ways ( id INTEGER PRIMARY KEY )",
Expand Down

0 comments on commit 8c67cdf

Please sign in to comment.