[core] harden OfflineDatabase

This commit is contained in:
Konstantin Käfer
2018-06-13 15:50:23 +02:00
parent a3b6fc1498
commit fa7b70945f
16 changed files with 1156 additions and 358 deletions

View File

@@ -23,13 +23,6 @@
namespace mapbox {
namespace sqlite {
// https://www.sqlite.org/rescode.html#ok
static_assert(mbgl::underlying_type(ResultCode::OK) == 0, "error");
// https://www.sqlite.org/rescode.html#cantopen
static_assert(mbgl::underlying_type(ResultCode::CantOpen) == 14, "error");
// https://www.sqlite.org/rescode.html#notadb
static_assert(mbgl::underlying_type(ResultCode::NotADB) == 26, "error");
void checkQueryError(const QSqlQuery& query) {
QSqlError lastError = query.lastError();
if (lastError.type() != QSqlError::NoError) {
@@ -114,6 +107,11 @@ mapbox::util::variant<Database, Exception> Database::tryOpen(const std::string &
connectOptions.append("QSQLITE_OPEN_READONLY");
}
if (filename.compare(0, 5, "file:") == 0) {
if (!connectOptions.isEmpty()) connectOptions.append(';');
connectOptions.append("QSQLITE_OPEN_URI");
}
db.setConnectOptions(connectOptions);
db.setDatabaseName(QString(filename.c_str()));