mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-27 00:03:38 -04:00
- run tests with temporary copy of srs.db
- sync srs.db in a single transaction
This commit is contained in:
parent
07a3bf5e32
commit
cfa85f37ab
@ -21,6 +21,7 @@
|
|||||||
#include "qgsgeometry.h"
|
#include "qgsgeometry.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
#include <QFileOpenEvent>
|
#include <QFileOpenEvent>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
@ -454,6 +455,23 @@ const QString QgsApplication::iconsPath()
|
|||||||
*/
|
*/
|
||||||
const QString QgsApplication::srsDbFilePath()
|
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" );
|
return ABISYM( mPkgDataPath ) + QString( "/resources/srs.db" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QTemporaryFile>
|
||||||
#include <QDomNode>
|
#include <QDomNode>
|
||||||
#include <QDomElement>
|
#include <QDomElement>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@ -1423,10 +1424,17 @@ QString QgsCoordinateReferenceSystem::quotedValue( QString value )
|
|||||||
int QgsCoordinateReferenceSystem::syncDb()
|
int QgsCoordinateReferenceSystem::syncDb()
|
||||||
{
|
{
|
||||||
int updated = 0, errors = 0;
|
int updated = 0, errors = 0;
|
||||||
|
|
||||||
sqlite3 *database;
|
sqlite3 *database;
|
||||||
if ( sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().constData(), &database ) != SQLITE_OK )
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1520,7 +1528,6 @@ int QgsCoordinateReferenceSystem::syncDb()
|
|||||||
if ( proj4 != params )
|
if ( proj4 != params )
|
||||||
{
|
{
|
||||||
char *errMsg = NULL;
|
char *errMsg = NULL;
|
||||||
|
|
||||||
sql = QString( "UPDATE tbl_srs SET parameters=%1 WHERE auth_name=%2 AND auth_id=%3" )
|
sql = QString( "UPDATE tbl_srs SET parameters=%1 WHERE auth_name=%2 AND auth_id=%3" )
|
||||||
.arg( quotedValue( proj4 ) )
|
.arg( quotedValue( proj4 ) )
|
||||||
.arg( quotedValue( auth_name ) )
|
.arg( quotedValue( auth_name ) )
|
||||||
@ -1548,6 +1555,13 @@ int QgsCoordinateReferenceSystem::syncDb()
|
|||||||
OSRDestroySpatialReference( crs );
|
OSRDestroySpatialReference( crs );
|
||||||
|
|
||||||
sqlite3_finalize( select );
|
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 );
|
sqlite3_close( database );
|
||||||
|
|
||||||
if ( errors > 0 )
|
if ( errors > 0 )
|
||||||
|
@ -65,5 +65,5 @@ int main( int argc, char ** argv )
|
|||||||
std::cout << -res << " CRSs could not be updated." << std::endl;
|
std::cout << -res << " CRSs could not be updated." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user