Skip to content

Commit

Permalink
- run tests with temporary copy of srs.db
Browse files Browse the repository at this point in the history
- sync srs.db in a single transaction
  • Loading branch information
jef-n committed Apr 20, 2012
1 parent 07a3bf5 commit cfa85f3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgsgeometry.h"

#include <QDir>
#include <QFile>
#include <QFileOpenEvent>
#include <QMessageBox>
#include <QPalette>
Expand Down Expand Up @@ -454,6 +455,23 @@ const QString QgsApplication::iconsPath()
*/
const QString QgsApplication::srsDbFilePath()
{
if ( ABISYM( mRunningFromBuildDir ) )
{
QString tempCopy = QDir::tempPath() + "/srs.db";

if ( !QFile( tempCopy ).exists() )
{
QFile f( ABISYM( mPkgDataPath ) + "/resources/srs.db" );
if ( !f.copy( tempCopy ) )
{
qFatal( "Could not create temporary copy" );
}
}

return tempCopy;
}

QString svgSubDir( ABISYM( mRunningFromBuildDir ) ? "/images/svg/" : "/svg/" );
return ABISYM( mPkgDataPath ) + QString( "/resources/srs.db" );
}

Expand Down
18 changes: 16 additions & 2 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -20,6 +20,7 @@
#include <cmath>

#include <QDir>
#include <QTemporaryFile>
#include <QDomNode>
#include <QDomElement>
#include <QFileInfo>
Expand Down Expand Up @@ -1423,10 +1424,17 @@ QString QgsCoordinateReferenceSystem::quotedValue( QString value )
int QgsCoordinateReferenceSystem::syncDb()
{
int updated = 0, errors = 0;

sqlite3 *database;
if ( sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().constData(), &database ) != SQLITE_OK )
{
qCritical( "Can't open database: %s [%s]\n", QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
qCritical( "Could not open database: %s [%s]\n", QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
return -1;
}

if ( sqlite3_exec( database, "BEGIN TRANSACTION", 0, 0, 0 ) != SQLITE_OK )
{
qCritical( "Could not begin transaction: %s [%s]\n", QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
return -1;
}

Expand Down Expand Up @@ -1520,7 +1528,6 @@ int QgsCoordinateReferenceSystem::syncDb()
if ( proj4 != params )
{
char *errMsg = NULL;

sql = QString( "UPDATE tbl_srs SET parameters=%1 WHERE auth_name=%2 AND auth_id=%3" )
.arg( quotedValue( proj4 ) )
.arg( quotedValue( auth_name ) )
Expand Down Expand Up @@ -1548,6 +1555,13 @@ int QgsCoordinateReferenceSystem::syncDb()
OSRDestroySpatialReference( crs );

sqlite3_finalize( select );

if ( sqlite3_exec( database, "COMMIT", 0, 0, 0 ) != SQLITE_OK )
{
qCritical( "Could not commit transaction: %s [%s]\n", QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
return -1;
}

sqlite3_close( database );

if ( errors > 0 )
Expand Down
2 changes: 1 addition & 1 deletion src/crssync/main.cpp
Expand Up @@ -65,5 +65,5 @@ int main( int argc, char ** argv )
std::cout << -res << " CRSs could not be updated." << std::endl;
}

return 0;
exit( 0 );
}

0 comments on commit cfa85f3

Please sign in to comment.