Skip to content

Commit db5b1df

Browse files
committedNov 15, 2017
Remove direct usage of sqlite3 handles in core
1 parent 042f2cd commit db5b1df

8 files changed

+259
-303
lines changed
 

‎src/core/qgsapplication.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "qgsreferencedgeometry.h"
4545
#include "qgs3drendererregistry.h"
4646
#include "qgslayoutcontext.h"
47+
#include "qgssqliteutils.h"
4748

4849
#include "gps/qgsgpsconnectionregistry.h"
4950
#include "processing/qgsprocessingregistry.h"
@@ -1432,8 +1433,8 @@ bool QgsApplication::createDatabase( QString *errorMessage )
14321433
else
14331434
{
14341435
// migrate if necessary
1435-
sqlite3 *db = nullptr;
1436-
if ( sqlite3_open( QgsApplication::qgisUserDatabaseFilePath().toUtf8().constData(), &db ) != SQLITE_OK )
1436+
sqlite3_database_unique_ptr database;
1437+
if ( database.open( QgsApplication::qgisUserDatabaseFilePath() ) != SQLITE_OK )
14371438
{
14381439
if ( errorMessage )
14391440
{
@@ -1443,11 +1444,11 @@ bool QgsApplication::createDatabase( QString *errorMessage )
14431444
}
14441445

14451446
char *errmsg = nullptr;
1446-
int res = sqlite3_exec( db, "SELECT epsg FROM tbl_srs LIMIT 0", nullptr, nullptr, &errmsg );
1447+
int res = sqlite3_exec( database.get(), "SELECT epsg FROM tbl_srs LIMIT 0", nullptr, nullptr, &errmsg );
14471448
if ( res == SQLITE_OK )
14481449
{
14491450
// epsg column exists => need migration
1450-
if ( sqlite3_exec( db,
1451+
if ( sqlite3_exec( database.get(),
14511452
"ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;"
14521453
"CREATE TABLE tbl_srs ("
14531454
"srs_id INTEGER PRIMARY KEY,"
@@ -1470,7 +1471,6 @@ bool QgsApplication::createDatabase( QString *errorMessage )
14701471
*errorMessage = tr( "Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
14711472
}
14721473
sqlite3_free( errmsg );
1473-
sqlite3_close( db );
14741474
return false;
14751475
}
14761476
}
@@ -1479,12 +1479,12 @@ bool QgsApplication::createDatabase( QString *errorMessage )
14791479
sqlite3_free( errmsg );
14801480
}
14811481

1482-
if ( sqlite3_exec( db, "DROP VIEW vw_srs", nullptr, nullptr, &errmsg ) != SQLITE_OK )
1482+
if ( sqlite3_exec( database.get(), "DROP VIEW vw_srs", nullptr, nullptr, &errmsg ) != SQLITE_OK )
14831483
{
14841484
QgsDebugMsg( QString( "vw_srs didn't exists in private qgis.db: %1" ).arg( errmsg ) );
14851485
}
14861486

1487-
if ( sqlite3_exec( db,
1487+
if ( sqlite3_exec( database.get(),
14881488
"CREATE VIEW vw_srs AS"
14891489
" SELECT"
14901490
" a.description AS description"
@@ -1505,11 +1505,8 @@ bool QgsApplication::createDatabase( QString *errorMessage )
15051505
*errorMessage = tr( "Update of view in private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
15061506
}
15071507
sqlite3_free( errmsg );
1508-
sqlite3_close( db );
15091508
return false;
15101509
}
1511-
1512-
sqlite3_close( db );
15131510
}
15141511
return true;
15151512
}

0 commit comments

Comments
 (0)
Please sign in to comment.