Skip to content

Commit

Permalink
open sqlite3 database readonly where possible (another followup on 91…
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed May 21, 2012
1 parent 4dfa15f commit 81a612c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
18 changes: 9 additions & 9 deletions src/app/qgscustomprojectiondialog.cpp
Expand Up @@ -163,7 +163,7 @@ long QgsCustomProjectionDialog::getRecordCount()
int myResult;
long myRecordCount = 0;
//check the db is available
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down Expand Up @@ -198,7 +198,7 @@ QString QgsCustomProjectionDialog::getProjectionFamilyName( QString theProjectio
int myResult;
QString myName;
//check the db is available
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down Expand Up @@ -229,7 +229,7 @@ QString QgsCustomProjectionDialog::getEllipsoidName( QString theEllipsoidAcronym
int myResult;
QString myName;
//check the db is available
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down Expand Up @@ -260,7 +260,7 @@ QString QgsCustomProjectionDialog::getProjectionFamilyAcronym( QString theProjec
int myResult;
QString myName;
//check the db is available
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down Expand Up @@ -291,7 +291,7 @@ QString QgsCustomProjectionDialog::getEllipsoidAcronym( QString theEllipsoidName
int myResult;
QString myName;
//check the db is available
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down Expand Up @@ -323,7 +323,7 @@ void QgsCustomProjectionDialog::on_pbnFirst_clicked()
sqlite3_stmt *myPreparedStatement;
int myResult;
//check the db is available
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down Expand Up @@ -395,7 +395,7 @@ void QgsCustomProjectionDialog::on_pbnPrevious_clicked()
sqlite3_stmt *myPreparedStatement;
int myResult;
//check the db is available
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down Expand Up @@ -468,7 +468,7 @@ void QgsCustomProjectionDialog::on_pbnNext_clicked()
sqlite3_stmt *myPreparedStatement;
int myResult;
//check the db is available
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down Expand Up @@ -537,7 +537,7 @@ void QgsCustomProjectionDialog::on_pbnLast_clicked()
sqlite3_stmt *myPreparedStatement;
int myResult;
//check the db is available
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsoptions.cpp
Expand Up @@ -982,7 +982,7 @@ void QgsOptions::getEllipsoidList()

cmbEllipsoid->addItem( ELLIPS_FLAT_DESC );
//check the db is available
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down Expand Up @@ -1015,7 +1015,7 @@ QString QgsOptions::getEllipsoidAcronym( QString theEllipsoidName )
int myResult;
QString myName( ELLIPS_FLAT );
//check the db is available
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down Expand Up @@ -1047,7 +1047,7 @@ QString QgsOptions::getEllipsoidName( QString theEllipsoidAcronym )
int myResult;
QString myName( ELLIPS_FLAT_DESC );
//check the db is available
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdistancearea.cpp
Expand Up @@ -99,7 +99,7 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )
}

//check the db is available
myResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult )
{
QgsMessageLog::logMessage( QObject::tr( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaplayer.cpp
Expand Up @@ -614,7 +614,7 @@ bool QgsMapLayer::loadNamedStyleFromDb( const QString db, const QString theURI,
if ( !QFile( db ).exists() )
return false;

myResult = sqlite3_open( db.toUtf8().data(), &myDatabase );
myResult = sqlite3_open_v2( db.toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult != SQLITE_OK )
{
return false;
Expand Down
14 changes: 7 additions & 7 deletions src/gui/qgsprojectionselector.cpp
Expand Up @@ -332,7 +332,7 @@ QString QgsProjectionSelector::selectedProj4String()
QgsDebugMsg( "db = " + databaseFileName );

sqlite3 *database;
int rc = sqlite3_open( databaseFileName.toUtf8().data(), &database );
int rc = sqlite3_open_v2( databaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
if ( rc )
{
showDBMissingWarning( databaseFileName );
Expand Down Expand Up @@ -401,7 +401,7 @@ QString QgsProjectionSelector::getSelectedExpression( QString expression )
// assuming that it will never be used anywhere else. Given the low overhead,
// opening it each time seems to be a reasonable approach at this time.
sqlite3 *database;
int rc = sqlite3_open( databaseFileName.toUtf8().data(), &database );
int rc = sqlite3_open_v2( databaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
if ( rc )
{
showDBMissingWarning( databaseFileName );
Expand Down Expand Up @@ -520,7 +520,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> *crsFilter )
const char *tail;
sqlite3_stmt *stmt;
//check the db is available
int result = sqlite3_open( databaseFileName.toUtf8().constData(), &database );
int result = sqlite3_open_v2( databaseFileName.toUtf8().constData(), &database, SQLITE_OPEN_READONLY, NULL );
if ( result )
{
// XXX This will likely never happen since on open, sqlite creates the
Expand Down Expand Up @@ -599,7 +599,7 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )

// open the database containing the spatial reference data
sqlite3 *database;
int rc = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &database );
int rc = sqlite3_open_v2( mSrsDatabaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
if ( rc )
{
// XXX This will likely never happen since on open, sqlite creates the
Expand Down Expand Up @@ -873,7 +873,7 @@ long QgsProjectionSelector::getLargestCRSIDMatch( QString theSql )
QString databaseFileName = QgsApplication::qgisUserDbFilePath();
if ( QFileInfo( databaseFileName ).exists() ) //only bother trying to open if the file exists
{
result = sqlite3_open( databaseFileName.toUtf8().data(), &database );
result = sqlite3_open_v2( databaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
if ( result )
{
// XXX This will likely never happen since on open, sqlite creates the
Expand All @@ -899,7 +899,7 @@ long QgsProjectionSelector::getLargestCRSIDMatch( QString theSql )
else
{
//only bother looking in srs.db if it wasnt found above
result = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &database );
result = sqlite3_open_v2( mSrsDatabaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
if ( result )
{
QgsDebugMsg( QString( "Can't open * user * database: %1" ).arg( sqlite3_errmsg( database ) ) );
Expand Down Expand Up @@ -929,7 +929,7 @@ QStringList QgsProjectionSelector::authorities()
const char *tail;
sqlite3_stmt *stmt;

int result = sqlite3_open( mSrsDatabaseFileName.toUtf8().data(), &database );
int result = sqlite3_open_v2( mSrsDatabaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, NULL );
if ( result )
{
QgsDebugMsg( QString( "Can't open * user * database: %1" ).arg( sqlite3_errmsg( database ) ) );
Expand Down
2 changes: 1 addition & 1 deletion src/helpviewer/qgshelpviewer.cpp
Expand Up @@ -219,7 +219,7 @@ int QgsHelpViewer::connectDb( const QString &helpDbPath )
if ( QFileInfo( helpDbPath ).exists() )
{
int rc;
rc = sqlite3_open( helpDbPath.toUtf8().data(), &db );
rc = sqlite3_open_v2( helpDbPath.toUtf8().data(), &db, SQLITE_OPEN_READONLY, NULL );
result = rc;
}
else
Expand Down

0 comments on commit 81a612c

Please sign in to comment.