summaryrefslogtreecommitdiff
path: root/platform/default/sqlite3.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-02-23 16:20:09 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-02-24 13:38:14 -0800
commit1bdeddab2cbda01117fac756367f76526b14bb9e (patch)
tree1daf22e2d9f2a865c84acd788405aa145ae0d154 /platform/default/sqlite3.cpp
parent65c06e62707a9982dedf39a88904bce04df1e227 (diff)
downloadqtlocation-mapboxgl-1bdeddab2cbda01117fac756367f76526b14bb9e.tar.gz
[core] Fix subtle bug in OfflineDatabase with updated resources
SQLite REPLACE is *not* UPSERT. If a conflict occurs, it first deletes the existing row, then inserts a new row. This means that AUTOINCREMENT primary keys change. This will break foreign keys to that value, which we use. Instead we must try an UPDATE, and fall back to an INSERT if the UPDATE changes zero rows.
Diffstat (limited to 'platform/default/sqlite3.cpp')
-rw-r--r--platform/default/sqlite3.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/platform/default/sqlite3.cpp b/platform/default/sqlite3.cpp
index 72296c6843..bf0bbfc683 100644
--- a/platform/default/sqlite3.cpp
+++ b/platform/default/sqlite3.cpp
@@ -292,6 +292,24 @@ template <> std::chrono::system_clock::time_point Statement::get(int offset) {
return std::chrono::system_clock::from_time_t(sqlite3_column_int64(stmt, offset));
}
+template <> optional<int64_t> Statement::get(int offset) {
+ assert(stmt);
+ if (sqlite3_column_type(stmt, offset) == SQLITE_NULL) {
+ return optional<int64_t>();
+ } else {
+ return get<int64_t>(offset);
+ }
+}
+
+template <> optional<double> Statement::get(int offset) {
+ assert(stmt);
+ if (sqlite3_column_type(stmt, offset) == SQLITE_NULL) {
+ return optional<double>();
+ } else {
+ return get<double>(offset);
+ }
+}
+
template <> optional<std::string> Statement::get(int offset) {
assert(stmt);
if (sqlite3_column_type(stmt, offset) == SQLITE_NULL) {