Skip to content

Commit 81a612c

Browse files
committed
open sqlite3 database readonly where possible (another followup on 9154e4e)
1 parent 4dfa15f commit 81a612c

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

src/app/qgscustomprojectiondialog.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ long QgsCustomProjectionDialog::getRecordCount()
163163
int myResult;
164164
long myRecordCount = 0;
165165
//check the db is available
166-
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase );
166+
myResult = sqlite3_open_v2( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
167167
if ( myResult != SQLITE_OK )
168168
{
169169
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
@@ -198,7 +198,7 @@ QString QgsCustomProjectionDialog::getProjectionFamilyName( QString theProjectio
198198
int myResult;
199199
QString myName;
200200
//check the db is available
201-
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
201+
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
202202
if ( myResult != SQLITE_OK )
203203
{
204204
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
@@ -229,7 +229,7 @@ QString QgsCustomProjectionDialog::getEllipsoidName( QString theEllipsoidAcronym
229229
int myResult;
230230
QString myName;
231231
//check the db is available
232-
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
232+
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
233233
if ( myResult != SQLITE_OK )
234234
{
235235
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
@@ -260,7 +260,7 @@ QString QgsCustomProjectionDialog::getProjectionFamilyAcronym( QString theProjec
260260
int myResult;
261261
QString myName;
262262
//check the db is available
263-
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
263+
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
264264
if ( myResult != SQLITE_OK )
265265
{
266266
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
@@ -291,7 +291,7 @@ QString QgsCustomProjectionDialog::getEllipsoidAcronym( QString theEllipsoidName
291291
int myResult;
292292
QString myName;
293293
//check the db is available
294-
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
294+
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
295295
if ( myResult != SQLITE_OK )
296296
{
297297
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
@@ -323,7 +323,7 @@ void QgsCustomProjectionDialog::on_pbnFirst_clicked()
323323
sqlite3_stmt *myPreparedStatement;
324324
int myResult;
325325
//check the db is available
326-
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase );
326+
myResult = sqlite3_open_v2( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
327327
if ( myResult != SQLITE_OK )
328328
{
329329
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
@@ -395,7 +395,7 @@ void QgsCustomProjectionDialog::on_pbnPrevious_clicked()
395395
sqlite3_stmt *myPreparedStatement;
396396
int myResult;
397397
//check the db is available
398-
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase );
398+
myResult = sqlite3_open_v2( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
399399
if ( myResult != SQLITE_OK )
400400
{
401401
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
@@ -468,7 +468,7 @@ void QgsCustomProjectionDialog::on_pbnNext_clicked()
468468
sqlite3_stmt *myPreparedStatement;
469469
int myResult;
470470
//check the db is available
471-
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase );
471+
myResult = sqlite3_open_v2( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
472472
if ( myResult != SQLITE_OK )
473473
{
474474
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
@@ -537,7 +537,7 @@ void QgsCustomProjectionDialog::on_pbnLast_clicked()
537537
sqlite3_stmt *myPreparedStatement;
538538
int myResult;
539539
//check the db is available
540-
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase );
540+
myResult = sqlite3_open_v2( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
541541
if ( myResult != SQLITE_OK )
542542
{
543543
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );

src/app/qgsoptions.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ void QgsOptions::getEllipsoidList()
982982

983983
cmbEllipsoid->addItem( ELLIPS_FLAT_DESC );
984984
//check the db is available
985-
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
985+
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
986986
if ( myResult )
987987
{
988988
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
@@ -1015,7 +1015,7 @@ QString QgsOptions::getEllipsoidAcronym( QString theEllipsoidName )
10151015
int myResult;
10161016
QString myName( ELLIPS_FLAT );
10171017
//check the db is available
1018-
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
1018+
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
10191019
if ( myResult )
10201020
{
10211021
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
@@ -1047,7 +1047,7 @@ QString QgsOptions::getEllipsoidName( QString theEllipsoidAcronym )
10471047
int myResult;
10481048
QString myName( ELLIPS_FLAT_DESC );
10491049
//check the db is available
1050-
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
1050+
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
10511051
if ( myResult )
10521052
{
10531053
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );

src/core/qgsdistancearea.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )
9999
}
100100

101101
//check the db is available
102-
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
102+
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
103103
if ( myResult )
104104
{
105105
QgsMessageLog::logMessage( QObject::tr( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );

src/core/qgsmaplayer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ bool QgsMapLayer::loadNamedStyleFromDb( const QString db, const QString theURI,
614614
if ( !QFile( db ).exists() )
615615
return false;
616616

617-
myResult = sqlite3_open( db.toUtf8().data(), &myDatabase );
617+
myResult = sqlite3_open_v2( db.toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
618618
if ( myResult != SQLITE_OK )
619619
{
620620
return false;

src/gui/qgsprojectionselector.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ QString QgsProjectionSelector::selectedProj4String()
332332
QgsDebugMsg( "db = " + databaseFileName );
333333

334334
sqlite3 *database;
335-
int rc = sqlite3_open( databaseFileName.toUtf8().data(), &database );
335+
int rc = sqlite3_open_v2( databaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
336336
if ( rc )
337337
{
338338
showDBMissingWarning( databaseFileName );
@@ -401,7 +401,7 @@ QString QgsProjectionSelector::getSelectedExpression( QString expression )
401401
// assuming that it will never be used anywhere else. Given the low overhead,
402402
// opening it each time seems to be a reasonable approach at this time.
403403
sqlite3 *database;
404-
int rc = sqlite3_open( databaseFileName.toUtf8().data(), &database );
404+
int rc = sqlite3_open_v2( databaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
405405
if ( rc )
406406
{
407407
showDBMissingWarning( databaseFileName );
@@ -520,7 +520,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> *crsFilter )
520520
const char *tail;
521521
sqlite3_stmt *stmt;
522522
//check the db is available
523-
int result = sqlite3_open( databaseFileName.toUtf8().constData(), &database );
523+
int result = sqlite3_open_v2( databaseFileName.toUtf8().constData(), &database, SQLITE_OPEN_READONLY, NULL );
524524
if ( result )
525525
{
526526
// XXX This will likely never happen since on open, sqlite creates the
@@ -599,7 +599,7 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
599599

600600
// open the database containing the spatial reference data
601601
sqlite3 *database;
602-
int rc = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &database );
602+
int rc = sqlite3_open_v2( mSrsDatabaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
603603
if ( rc )
604604
{
605605
// XXX This will likely never happen since on open, sqlite creates the
@@ -873,7 +873,7 @@ long QgsProjectionSelector::getLargestCRSIDMatch( QString theSql )
873873
QString databaseFileName = QgsApplication::qgisUserDbFilePath();
874874
if ( QFileInfo( databaseFileName ).exists() ) //only bother trying to open if the file exists
875875
{
876-
result = sqlite3_open( databaseFileName.toUtf8().data(), &database );
876+
result = sqlite3_open_v2( databaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
877877
if ( result )
878878
{
879879
// XXX This will likely never happen since on open, sqlite creates the
@@ -899,7 +899,7 @@ long QgsProjectionSelector::getLargestCRSIDMatch( QString theSql )
899899
else
900900
{
901901
//only bother looking in srs.db if it wasnt found above
902-
result = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &database );
902+
result = sqlite3_open_v2( mSrsDatabaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
903903
if ( result )
904904
{
905905
QgsDebugMsg( QString( "Can't open * user * database: %1" ).arg( sqlite3_errmsg( database ) ) );
@@ -929,7 +929,7 @@ QStringList QgsProjectionSelector::authorities()
929929
const char *tail;
930930
sqlite3_stmt *stmt;
931931

932-
int result = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &database );
932+
int result = sqlite3_open_v2( mSrsDatabaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
933933
if ( result )
934934
{
935935
QgsDebugMsg( QString( "Can't open * user * database: %1" ).arg( sqlite3_errmsg( database ) ) );

src/helpviewer/qgshelpviewer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ int QgsHelpViewer::connectDb( const QString &helpDbPath )
219219
if ( QFileInfo( helpDbPath ).exists() )
220220
{
221221
int rc;
222-
rc = sqlite3_open( helpDbPath.toUtf8().data(), &db );
222+
rc = sqlite3_open_v2( helpDbPath.toUtf8().data(), &db, SQLITE_OPEN_READONLY, NULL );
223223
result = rc;
224224
}
225225
else

0 commit comments

Comments
 (0)