Skip to content

Commit cfa85f3

Browse files
committedApr 20, 2012
- run tests with temporary copy of srs.db
- sync srs.db in a single transaction
1 parent 07a3bf5 commit cfa85f3

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed
 

‎src/core/qgsapplication.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgsgeometry.h"
2222

2323
#include <QDir>
24+
#include <QFile>
2425
#include <QFileOpenEvent>
2526
#include <QMessageBox>
2627
#include <QPalette>
@@ -454,6 +455,23 @@ const QString QgsApplication::iconsPath()
454455
*/
455456
const QString QgsApplication::srsDbFilePath()
456457
{
458+
if ( ABISYM( mRunningFromBuildDir ) )
459+
{
460+
QString tempCopy = QDir::tempPath() + "/srs.db";
461+
462+
if ( !QFile( tempCopy ).exists() )
463+
{
464+
QFile f( ABISYM( mPkgDataPath ) + "/resources/srs.db" );
465+
if ( !f.copy( tempCopy ) )
466+
{
467+
qFatal( "Could not create temporary copy" );
468+
}
469+
}
470+
471+
return tempCopy;
472+
}
473+
474+
QString svgSubDir( ABISYM( mRunningFromBuildDir ) ? "/images/svg/" : "/svg/" );
457475
return ABISYM( mPkgDataPath ) + QString( "/resources/srs.db" );
458476
}
459477

‎src/core/qgscoordinatereferencesystem.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <cmath>
2121

2222
#include <QDir>
23+
#include <QTemporaryFile>
2324
#include <QDomNode>
2425
#include <QDomElement>
2526
#include <QFileInfo>
@@ -1423,10 +1424,17 @@ QString QgsCoordinateReferenceSystem::quotedValue( QString value )
14231424
int QgsCoordinateReferenceSystem::syncDb()
14241425
{
14251426
int updated = 0, errors = 0;
1427+
14261428
sqlite3 *database;
14271429
if ( sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().constData(), &database ) != SQLITE_OK )
14281430
{
1429-
qCritical( "Can't open database: %s [%s]\n", QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
1431+
qCritical( "Could not open database: %s [%s]\n", QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
1432+
return -1;
1433+
}
1434+
1435+
if ( sqlite3_exec( database, "BEGIN TRANSACTION", 0, 0, 0 ) != SQLITE_OK )
1436+
{
1437+
qCritical( "Could not begin transaction: %s [%s]\n", QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
14301438
return -1;
14311439
}
14321440

@@ -1520,7 +1528,6 @@ int QgsCoordinateReferenceSystem::syncDb()
15201528
if ( proj4 != params )
15211529
{
15221530
char *errMsg = NULL;
1523-
15241531
sql = QString( "UPDATE tbl_srs SET parameters=%1 WHERE auth_name=%2 AND auth_id=%3" )
15251532
.arg( quotedValue( proj4 ) )
15261533
.arg( quotedValue( auth_name ) )
@@ -1548,6 +1555,13 @@ int QgsCoordinateReferenceSystem::syncDb()
15481555
OSRDestroySpatialReference( crs );
15491556

15501557
sqlite3_finalize( select );
1558+
1559+
if ( sqlite3_exec( database, "COMMIT", 0, 0, 0 ) != SQLITE_OK )
1560+
{
1561+
qCritical( "Could not commit transaction: %s [%s]\n", QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
1562+
return -1;
1563+
}
1564+
15511565
sqlite3_close( database );
15521566

15531567
if ( errors > 0 )

‎src/crssync/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ int main( int argc, char ** argv )
6565
std::cout << -res << " CRSs could not be updated." << std::endl;
6666
}
6767

68-
return 0;
68+
exit( 0 );
6969
}

0 commit comments

Comments
 (0)
Please sign in to comment.