Commit Graph

25 Commits

Author SHA1 Message Date
Konstantin Käfer
4004a85a79 [android] explicitly set temp directory for SQLite3 2018-09-26 13:47:28 +02:00
Konstantin Käfer
084c28f0bb [core] recreate offline database when it is deleted out from under our feet 2018-08-14 17:03:46 -07:00
Konstantin Käfer
0ecdbebb09 [core] consolidate database opening workflow
Before this change, we've tried to open the database in read/write, but not create mode. In situations where the database didn't exist yet, this logged an error to the console, and we proceeded to opening it again in read/write/create mode, which actually created the file. The reason we did this is so that we could detect really old caching databases from January 2016 in case a developer upgraded from an older SDK (iOS v3.1 and earlier, Android v3.2 and earlier) that didn't have https://github.com/mapbox/mapbox-gl-native/pull/3715 yet.

However, these error messages, while innocent, look scary in the console and some users suspect that it's a bug. This change opens the file directly in read/write/create mode, omitting the first failed attempt. To handle old cache databases, we're now deleting the `http_cache` table, which was the only table in those old databases, and create the new schema, rather than deleting the entire file and recreating the Database object. In most scenarios, this will lead to one fewer opening attempt, while the database migration will continue to work for the few users who upgrade all the way from a January 2016 SDK.

Additionally, this fixes a mismatch between the Qt and non-Qt implementation: Qt doesn't support opening a file in read/write mode without the create flag. This means that we've seen a different control flow on Qt compared to the non-Qt implementation when opening a database.
2018-06-12 17:41:16 +02:00
Konstantin Käfer
79394ee47d [core] remove unused flags from SQLite header 2018-06-12 17:41:16 +02:00
Konstantin Käfer
4477dd4119 [core] support moving Database object during a Transaction 2018-06-12 17:41:16 +02:00
John Firebaugh
a1195f6a9d Avoid exceptions for flow control during database creation
Unfortuntely, it's difficult to avoid all exceptions, because sqlite3_open_v2 does not reliably return SQLITE_NOTADB if the file is not a database. However, this should avoid cases where developers misinterpret the SQLITE_CANTOPEN exception as a crash, which is the common case.
2018-05-09 07:32:16 -07:00
Konstantin Käfer
136e536159 [core, qt] move self-resetting Statement/Query object to shared header 2018-03-02 14:26:25 +01:00
Konstantin Käfer
5ca38bbde9 [core] refactor SQLite error/status codes 2018-03-02 14:26:25 +01:00
Bruno de Oliveira Abinader
04a3a7383a [core] Remove unused bool() functions 2017-04-14 12:33:13 -07:00
Bruno de Oliveira Abinader
eb772258cf [core] Replace sqlite3.h dependency in offline database 2017-01-23 19:06:53 +02:00
Bruno de Oliveira Abinader
b8863a6dca [core] Move sqlite::Statement::check to pimpl 2017-01-23 19:06:53 +02:00
Bruno de Oliveira Abinader
80d72123df [core] Move lastInsertRowId/changes to sqlite::Statement 2017-01-23 19:06:53 +02:00
Bruno de Oliveira Abinader
97b433edc9 [core] Private implementation for SQLite interface 2017-01-23 19:06:53 +02:00
Jason Wray
e26fa4dd4c [core] Move SQLite logging setup to before database initialization
- Ensure that sqlite3_config() is always called before db init.
- Should only be called once, now.
- Move sqliteVersionCheck into mapbox::sqlite namespace.
2016-09-09 05:42:20 -04:00
Jason Wray
4ef8f815c9 [core] Implement SQLite error logging (#6291) 2016-09-08 13:01:19 -04:00
Bruno de Oliveira Abinader
c20c1d6a6b [core] Avoid redundant 'inline' usage 2016-06-18 23:46:50 +03:00
John Firebaugh
c3bed1dab8 [core] Fix race condition that could lead to a UNIQUE constraint failure (#4677) 2016-04-11 19:46:45 -07:00
John Firebaugh
db3620c58f [core] Implement an eviction policy for OfflineDatabase
When inserting an cached resource, or removing a region, remove least-recently used resources and tiles, not used by offline regions, until the used database size, as calculated by multiplying the number of in-use pages by the page size, is less than the maximum cache size minus 5 times the page size.

In addition, OfflineDatabase may be configured to ignore cache puts of individual resources larger than a certain size.

This policy is similar but not identical to the former SQLiteCache policy:

* It accounts for offline, by exempting resources required by offline regions from eviction.
* It must delete from two tables (resources and tiles), rather than one. Currently the strategy is naive: evict 50 rows at a time from each table.
* It makes maximumCacheSize and maximumCacheEntrySize completely independent. The SQLiteCache implementation evicted when `usedSize > maximumCacheSize - 2 * maximumCacheEntrySize`. This evicts when `usedSize > maximumCacheSize - 5 * pageSize`.
* It uses a non-unlimited default value for maximumCacheSize: 50 MB. We should have always had a limit in place; "a cache without an eviction policy is a resource leak".
2016-02-10 15:40:20 -08:00
John Firebaugh
5910124010 [core] Reset SQLite statements after use in order to release locks 2016-02-10 15:40:20 -08:00
John Firebaugh
96e0e5252e [core] Disable SQLite busy timeouts so that multiple readers can access the same database 2016-02-10 15:40:20 -08:00
John Firebaugh
4bde1b0c88 [core] Explicit operator bool 2016-02-10 15:40:20 -08:00
John Firebaugh
c3c4c7b9a6 [core] Interface and implementation for offline 2016-02-10 15:40:20 -08:00
John Firebaugh
dbfa932ed1 [core] Eliminate macros in sqlite3.cpp 2016-01-19 13:39:18 -08:00
Konstantin Käfer
c279fb1717 [core] throw values, catch references 2015-12-03 15:38:36 +01:00
Konstantin Käfer
272fa8935e make storage lib separate so we can build without storage libs 2015-02-04 10:49:07 +01:00