blob: 15dac32e197961744d4a01c6acf58d0ff60eee5b [file] [log] [blame]
[email protected]2eec0a22012-07-24 01:59:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]e5ffd0e42009-09-11 21:30:562// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Victor Costancfbfa602018-08-01 23:24:465#ifndef SQL_DATABASE_H_
6#define SQL_DATABASE_H_
[email protected]e5ffd0e42009-09-11 21:30:567
avi0b519202015-12-21 07:25:198#include <stddef.h>
tfarina720d4f32015-05-11 22:31:269#include <stdint.h>
mostynbd82cd9952016-04-11 20:05:3410#include <memory>
[email protected]e5ffd0e42009-09-11 21:30:5611#include <set>
[email protected]7d6aee4e2009-09-12 01:12:3312#include <string>
Victor Costan87cf8c72018-07-19 19:36:0413#include <utility>
[email protected]80abf152013-05-22 12:42:4214#include <vector>
[email protected]e5ffd0e42009-09-11 21:30:5615
[email protected]c3881b372013-05-17 08:39:4616#include "base/callback.h"
[email protected]9fe37552011-12-23 17:07:2017#include "base/compiler_specific.h"
Victor Costane56cc682018-12-27 01:53:4618#include "base/component_export.h"
Dmitry Skibaa9ad8fe42017-08-16 21:02:4819#include "base/containers/flat_map.h"
shessc8cd2a162015-10-22 20:30:4620#include "base/gtest_prod_util.h"
tfarina720d4f32015-05-11 22:31:2621#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1522#include "base/memory/ref_counted.h"
Etienne Pierre-Doraya71d7af2019-02-07 02:07:5423#include "base/optional.h"
Victor Costan12daa3ac92018-07-19 01:05:5824#include "base/sequence_checker.h"
Etienne Pierre-Doray0400dfb62018-12-03 19:12:2525#include "base/threading/scoped_blocking_call.h"
Victor Costan7f6abbbe2018-07-29 02:57:2726#include "sql/internal_api_token.h"
Victor Costan12daa3ac92018-07-19 01:05:5827#include "sql/statement_id.h"
[email protected]e5ffd0e42009-09-11 21:30:5628
[email protected]e5ffd0e42009-09-11 21:30:5629struct sqlite3;
30struct sqlite3_stmt;
31
[email protected]a3ef4832013-02-02 05:12:3332namespace base {
33class FilePath;
shess58b8df82015-06-03 00:19:3234class HistogramBase;
dskibab4199f82016-11-21 20:16:1335namespace trace_event {
ssid1f4e5362016-12-08 20:41:3836class ProcessMemoryDump;
Victor Costan87cf8c72018-07-19 19:36:0437} // namespace trace_event
38} // namespace base
[email protected]a3ef4832013-02-02 05:12:3339
[email protected]e5ffd0e42009-09-11 21:30:5640namespace sql {
41
Victor Costancfbfa602018-08-01 23:24:4642class DatabaseMemoryDumpProvider;
[email protected]e5ffd0e42009-09-11 21:30:5643class Statement;
44
shess58b8df82015-06-03 00:19:3245namespace test {
shess976814402016-06-21 06:56:2546class ScopedErrorExpecter;
Victor Costan87cf8c72018-07-19 19:36:0447} // namespace test
shess58b8df82015-06-03 00:19:3248
Victor Costan87cf8c72018-07-19 19:36:0449// Handle to an open SQLite database.
50//
51// Instances of this class are thread-unsafe and DCHECK that they are accessed
52// on the same sequence.
Victor Costane56cc682018-12-27 01:53:4653class COMPONENT_EXPORT(SQL) Database {
[email protected]e5ffd0e42009-09-11 21:30:5654 private:
55 class StatementRef; // Forward declaration, see real one below.
56
57 public:
[email protected]765b44502009-10-02 05:01:4258 // The database is opened by calling Open[InMemory](). Any uncommitted
59 // transactions will be rolled back when this object is deleted.
Victor Costancfbfa602018-08-01 23:24:4660 Database();
61 ~Database();
[email protected]e5ffd0e42009-09-11 21:30:5662
Ken Rockot01687422020-08-17 18:00:5963 // Allows mmapping to be disabled globally by default in the calling process.
64 // Must be called before any threads attempt to create a Database.
65 //
66 // TODO(crbug.com/1117049): Remove this global configuration.
67 static void DisableMmapByDefault();
68
[email protected]e5ffd0e42009-09-11 21:30:5669 // Pre-init configuration ----------------------------------------------------
70
[email protected]765b44502009-10-02 05:01:4271 // Sets the page size that will be used when creating a new database. This
[email protected]e5ffd0e42009-09-11 21:30:5672 // must be called before Init(), and will only have an effect on new
73 // databases.
74 //
Victor Costan7f6abbbe2018-07-29 02:57:2775 // The page size must be a power of two between 512 and 65536 inclusive.
Victor Costan87cf8c72018-07-19 19:36:0476 void set_page_size(int page_size) {
Victor Costan7f6abbbe2018-07-29 02:57:2777 DCHECK_GE(page_size, 512);
78 DCHECK_LE(page_size, 65536);
79 DCHECK(!(page_size & (page_size - 1)))
Victor Costan87cf8c72018-07-19 19:36:0480 << "page_size must be a power of two";
81
82 page_size_ = page_size;
83 }
[email protected]e5ffd0e42009-09-11 21:30:5684
Victor Costan7f6abbbe2018-07-29 02:57:2785 // The page size that will be used when creating a new database.
86 int page_size() const { return page_size_; }
87
[email protected]e5ffd0e42009-09-11 21:30:5688 // Sets the number of pages that will be cached in memory by sqlite. The
89 // total cache size in bytes will be page_size * cache_size. This must be
[email protected]765b44502009-10-02 05:01:4290 // called before Open() to have an effect.
Victor Costan87cf8c72018-07-19 19:36:0491 void set_cache_size(int cache_size) {
92 DCHECK_GE(cache_size, 0);
93
94 cache_size_ = cache_size;
95 }
[email protected]e5ffd0e42009-09-11 21:30:5696
Shubham Aggarwalbe4f97ce2020-06-19 15:58:5797 // Returns whether a database will be opened in WAL mode.
98 bool UseWALMode() const;
99
100 // Enables/disables WAL mode (https://www.sqlite.org/wal.html) when
101 // opening a new database.
102 //
103 // WAL mode is currently not fully supported on FuchsiaOS. It will only be
104 // turned on if the database is also using exclusive locking mode.
105 // (https://crbug.com/1082059)
106 //
107 // Note: Changing page size is not supported when in WAL mode. So running
108 // 'PRAGMA page_size = <new-size>' or using set_page_size will result in
109 // no-ops.
110 //
111 // This must be called before Open() to have an effect.
112 void want_wal_mode(bool enabled) { want_wal_mode_ = enabled; }
113
[email protected]e5ffd0e42009-09-11 21:30:56114 // Call to put the database in exclusive locking mode. There is no "back to
115 // normal" flag because of some additional requirements sqlite puts on this
[email protected]4ab952f2014-04-01 20:18:16116 // transaction (requires another access to the DB) and because we don't
[email protected]e5ffd0e42009-09-11 21:30:56117 // actually need it.
118 //
119 // Exclusive mode means that the database is not unlocked at the end of each
120 // transaction, which means there may be less time spent initializing the
121 // next transaction because it doesn't have to re-aquire locks.
122 //
[email protected]765b44502009-10-02 05:01:42123 // This must be called before Open() to have an effect.
[email protected]e5ffd0e42009-09-11 21:30:56124 void set_exclusive_locking() { exclusive_locking_ = true; }
125
shessa62504d2016-11-07 19:26:12126 // Call to use alternative status-tracking for mmap. Usually this is tracked
127 // in the meta table, but some databases have no meta table.
128 // TODO(shess): Maybe just have all databases use the alt option?
129 void set_mmap_alt_status() { mmap_alt_status_ = true; }
130
Victor Costan87cf8c72018-07-19 19:36:04131 // Opt out of memory-mapped file I/O.
shess7dbd4dee2015-10-06 17:39:16132 void set_mmap_disabled() { mmap_disabled_ = true; }
133
[email protected]c3881b372013-05-17 08:39:46134 // Set an error-handling callback. On errors, the error number (and
135 // statement, if available) will be passed to the callback.
136 //
137 // If no callback is set, the default action is to crash in debug
138 // mode or return failure in release mode.
Victor Costanc7e7f2e2018-07-18 20:07:55139 using ErrorCallback = base::RepeatingCallback<void(int, Statement*)>;
[email protected]c3881b372013-05-17 08:39:46140 void set_error_callback(const ErrorCallback& callback) {
141 error_callback_ = callback;
142 }
Victor Costan87cf8c72018-07-19 19:36:04143 bool has_error_callback() const { return !error_callback_.is_null(); }
144 void reset_error_callback() { error_callback_.Reset(); }
[email protected]c3881b372013-05-17 08:39:46145
Victor Costancfbfa602018-08-01 23:24:46146 // Set this to enable additional per-database histogramming. Must be called
shess58b8df82015-06-03 00:19:32147 // before Open().
148 void set_histogram_tag(const std::string& tag);
[email protected]c088e3a32013-01-03 23:59:14149
[email protected]210ce0af2013-05-15 09:10:39150 // Record a sparse UMA histogram sample under
151 // |name|+"."+|histogram_tag_|. If |histogram_tag_| is empty, no
152 // histogram is recorded.
Will Harrisb8693592018-08-28 22:58:44153 void AddTaggedHistogram(const std::string& name, int sample) const;
[email protected]210ce0af2013-05-15 09:10:39154
Etienne Bergerone7681c72020-01-17 00:51:20155 // Track various API calls and results. Values correspond to UMA
shess58b8df82015-06-03 00:19:32156 // histograms, do not modify, or add or delete other than directly
157 // before EVENT_MAX_VALUE.
158 enum Events {
159 // Number of statements run, either with sql::Statement or Execute*().
Victor Costan5e785e32019-02-26 20:39:31160 EVENT_STATEMENT_RUN_DEPRECATED = 0,
shess58b8df82015-06-03 00:19:32161
162 // Number of rows returned by statements run.
Victor Costan5e785e32019-02-26 20:39:31163 EVENT_STATEMENT_ROWS_DEPRECATED,
shess58b8df82015-06-03 00:19:32164
165 // Number of statements successfully run (all steps returned SQLITE_DONE or
166 // SQLITE_ROW).
Victor Costan5e785e32019-02-26 20:39:31167 EVENT_STATEMENT_SUCCESS_DEPRECATED,
shess58b8df82015-06-03 00:19:32168
169 // Number of statements run by Execute() or ExecuteAndReturnErrorCode().
Victor Costan5e785e32019-02-26 20:39:31170 EVENT_EXECUTE_DEPRECATED,
shess58b8df82015-06-03 00:19:32171
172 // Number of rows changed by autocommit statements.
Victor Costan5e785e32019-02-26 20:39:31173 EVENT_CHANGES_AUTOCOMMIT_DEPRECATED,
shess58b8df82015-06-03 00:19:32174
175 // Number of rows changed by statements in transactions.
Victor Costan5e785e32019-02-26 20:39:31176 EVENT_CHANGES_DEPRECATED,
shess58b8df82015-06-03 00:19:32177
178 // Count actual SQLite transaction statements (not including nesting).
Victor Costan5e785e32019-02-26 20:39:31179 EVENT_BEGIN_DEPRECATED,
180 EVENT_COMMIT_DEPRECATED,
181 EVENT_ROLLBACK_DEPRECATED,
shess58b8df82015-06-03 00:19:32182
shessd90aeea82015-11-13 02:24:31183 // Track success and failure in GetAppropriateMmapSize().
184 // GetAppropriateMmapSize() should record at most one of these per run. The
185 // case of mapping everything is not recorded.
Victor Costan5e785e32019-02-26 20:39:31186 EVENT_MMAP_META_MISSING, // No meta table present.
187 EVENT_MMAP_META_FAILURE_READ, // Failed reading meta table.
188 EVENT_MMAP_META_FAILURE_UPDATE, // Failed updating meta table.
189 EVENT_MMAP_VFS_FAILURE, // Failed to access VFS.
190 EVENT_MMAP_FAILED, // Failure from past run.
191 EVENT_MMAP_FAILED_NEW, // Read error in this run.
192 EVENT_MMAP_SUCCESS_NEW_DEPRECATED, // Read to EOF in this run.
193 EVENT_MMAP_SUCCESS_PARTIAL_DEPRECATED, // Read but did not reach EOF.
194 EVENT_MMAP_SUCCESS_NO_PROGRESS_DEPRECATED, // Read quota exhausted.
shessd90aeea82015-11-13 02:24:31195
Victor Costancfbfa602018-08-01 23:24:46196 EVENT_MMAP_STATUS_FAILURE_READ, // Failure reading MmapStatus view.
197 EVENT_MMAP_STATUS_FAILURE_UPDATE, // Failure updating MmapStatus view.
shessa62504d2016-11-07 19:26:12198
shess58b8df82015-06-03 00:19:32199 // Leave this at the end.
200 // TODO(shess): |EVENT_MAX| causes compile fail on Windows.
Victor Costan5e785e32019-02-26 20:39:31201 EVENT_MAX_VALUE,
shess58b8df82015-06-03 00:19:32202 };
203 void RecordEvent(Events event, size_t count);
Victor Costan87cf8c72018-07-19 19:36:04204 void RecordOneEvent(Events event) { RecordEvent(event, 1); }
shess58b8df82015-06-03 00:19:32205
[email protected]579446c2013-12-16 18:36:52206 // Run "PRAGMA integrity_check" and post each line of
207 // results into |messages|. Returns the success of running the
208 // statement - per the SQLite documentation, if no errors are found the
209 // call should succeed, and a single value "ok" should be in messages.
210 bool FullIntegrityCheck(std::vector<std::string>* messages);
211
212 // Runs "PRAGMA quick_check" and, unlike the FullIntegrityCheck method,
213 // interprets the results returning true if the the statement executes
214 // without error and results in a single "ok" value.
215 bool QuickIntegrityCheck() WARN_UNUSED_RESULT;
[email protected]80abf152013-05-22 12:42:42216
afakhry7c9abe72016-08-05 17:33:19217 // Meant to be called from a client error callback so that it's able to
218 // get diagnostic information about the database.
219 std::string GetDiagnosticInfo(int extended_error, Statement* statement);
220
ssid1f4e5362016-12-08 20:41:38221 // Reports memory usage into provided memory dump with the given name.
222 bool ReportMemoryUsage(base::trace_event::ProcessMemoryDump* pmd,
223 const std::string& dump_name);
dskibab4199f82016-11-21 20:16:13224
[email protected]e5ffd0e42009-09-11 21:30:56225 // Initialization ------------------------------------------------------------
226
Victor Costancfbfa602018-08-01 23:24:46227 // Initializes the SQL database for the given file, returning true if the
[email protected]35f2094c2009-12-29 22:46:55228 // file could be opened. You can call this or OpenInMemory.
[email protected]a3ef4832013-02-02 05:12:33229 bool Open(const base::FilePath& path) WARN_UNUSED_RESULT;
[email protected]765b44502009-10-02 05:01:42230
Victor Costancfbfa602018-08-01 23:24:46231 // Initializes the SQL database for a temporary in-memory database. There
[email protected]765b44502009-10-02 05:01:42232 // will be no associated file on disk, and the initial database will be
[email protected]35f2094c2009-12-29 22:46:55233 // empty. You can call this or Open.
[email protected]9fe37552011-12-23 17:07:20234 bool OpenInMemory() WARN_UNUSED_RESULT;
[email protected]765b44502009-10-02 05:01:42235
[email protected]8d409412013-07-19 18:25:30236 // Create a temporary on-disk database. The database will be
237 // deleted after close. This kind of database is similar to
238 // OpenInMemory() for small databases, but can page to disk if the
239 // database becomes large.
240 bool OpenTemporary() WARN_UNUSED_RESULT;
241
[email protected]41a97c812013-02-07 02:35:38242 // Returns true if the database has been successfully opened.
Victor Costan87cf8c72018-07-19 19:36:04243 bool is_open() const { return static_cast<bool>(db_); }
[email protected]e5ffd0e42009-09-11 21:30:56244
245 // Closes the database. This is automatically performed on destruction for
246 // you, but this allows you to close the database early. You must not call
247 // any other functions after closing it. It is permissable to call Close on
248 // an uninitialized or already-closed database.
249 void Close();
250
[email protected]8ada10f2013-12-21 00:42:34251 // Reads the first <cache-size>*<page-size> bytes of the file to prime the
252 // filesystem cache. This can be more efficient than faulting pages
253 // individually. Since this involves blocking I/O, it should only be used if
254 // the caller will immediately read a substantial amount of data from the
255 // database.
[email protected]e5ffd0e42009-09-11 21:30:56256 //
[email protected]8ada10f2013-12-21 00:42:34257 // TODO(shess): Design a set of histograms or an experiment to inform this
258 // decision. Preloading should almost always improve later performance
259 // numbers for this database simply because it pulls operations forward, but
260 // if the data isn't actually used soon then preloading just slows down
261 // everything else.
[email protected]e5ffd0e42009-09-11 21:30:56262 void Preload();
263
Victor Costan52bef812018-12-05 07:41:49264 // Release all non-essential memory associated with this database connection.
265 void TrimMemory();
[email protected]be7995f12013-07-18 18:49:14266
[email protected]8e0c01282012-04-06 19:36:49267 // Raze the database to the ground. This approximates creating a
268 // fresh database from scratch, within the constraints of SQLite's
269 // locking protocol (locks and open handles can make doing this with
270 // filesystem operations problematic). Returns true if the database
271 // was razed.
272 //
273 // false is returned if the database is locked by some other
Carlos Knippschild46800c9f2017-09-02 02:21:43274 // process.
[email protected]8e0c01282012-04-06 19:36:49275 //
276 // NOTE(shess): Raze() will DCHECK in the following situations:
277 // - database is not open.
Victor Costancfbfa602018-08-01 23:24:46278 // - the database has a transaction open.
[email protected]8e0c01282012-04-06 19:36:49279 // - a SQLite issue occurs which is structural in nature (like the
280 // statements used are broken).
281 // Since Raze() is expected to be called in unexpected situations,
282 // these all return false, since it is unlikely that the caller
283 // could fix them.
[email protected]6d42f152012-11-10 00:38:24284 //
285 // The database's page size is taken from |page_size_|. The
286 // existing database's |auto_vacuum| setting is lost (the
287 // possibility of corruption makes it unreliable to pull it from the
288 // existing database). To re-enable on the empty database requires
289 // running "PRAGMA auto_vacuum = 1;" then "VACUUM".
290 //
291 // NOTE(shess): For Android, SQLITE_DEFAULT_AUTOVACUUM is set to 1,
292 // so Raze() sets auto_vacuum to 1.
293 //
Victor Costancfbfa602018-08-01 23:24:46294 // TODO(shess): Raze() needs a database so cannot clear SQLITE_NOTADB.
295 // TODO(shess): Bake auto_vacuum into Database's API so it can
[email protected]6d42f152012-11-10 00:38:24296 // just pick up the default.
[email protected]8e0c01282012-04-06 19:36:49297 bool Raze();
[email protected]8e0c01282012-04-06 19:36:49298
[email protected]41a97c812013-02-07 02:35:38299 // Breaks all outstanding transactions (as initiated by
[email protected]8d409412013-07-19 18:25:30300 // BeginTransaction()), closes the SQLite database, and poisons the
Victor Costancfbfa602018-08-01 23:24:46301 // object so that all future operations against the Database (or
[email protected]8d409412013-07-19 18:25:30302 // its Statements) fail safely, without side effects.
[email protected]41a97c812013-02-07 02:35:38303 //
[email protected]8d409412013-07-19 18:25:30304 // This is intended as an alternative to Close() in error callbacks.
305 // Close() should still be called at some point.
306 void Poison();
307
308 // Raze() the database and Poison() the handle. Returns the return
309 // value from Raze().
310 // TODO(shess): Rename to RazeAndPoison().
[email protected]41a97c812013-02-07 02:35:38311 bool RazeAndClose();
312
Victor Costancfbfa602018-08-01 23:24:46313 // Delete the underlying database files associated with |path|. This should be
314 // used on a database which is not opened by any Database instance. Open
315 // Database instances pointing to the database can cause odd results or
316 // corruption (for instance if a hot journal is deleted but the associated
317 // database is not).
[email protected]8d2e39e2013-06-24 05:55:08318 //
319 // Returns true if the database file and associated journals no
320 // longer exist, false otherwise. If the database has never
321 // existed, this will return true.
322 static bool Delete(const base::FilePath& path);
323
[email protected]e5ffd0e42009-09-11 21:30:56324 // Transactions --------------------------------------------------------------
325
326 // Transaction management. We maintain a virtual transaction stack to emulate
327 // nested transactions since sqlite can't do nested transactions. The
328 // limitation is you can't roll back a sub transaction: if any transaction
329 // fails, all transactions open will also be rolled back. Any nested
330 // transactions after one has rolled back will return fail for Begin(). If
331 // Begin() fails, you must not call Commit or Rollback().
332 //
333 // Normally you should use sql::Transaction to manage a transaction, which
334 // will scope it to a C++ context.
335 bool BeginTransaction();
336 void RollbackTransaction();
337 bool CommitTransaction();
338
[email protected]8d409412013-07-19 18:25:30339 // Rollback all outstanding transactions. Use with care, there may
340 // be scoped transactions on the stack.
341 void RollbackAllTransactions();
342
[email protected]e5ffd0e42009-09-11 21:30:56343 // Returns the current transaction nesting, which will be 0 if there are
344 // no open transactions.
345 int transaction_nesting() const { return transaction_nesting_; }
346
[email protected]8d409412013-07-19 18:25:30347 // Attached databases---------------------------------------------------------
348
Victor Costan7f6abbbe2018-07-29 02:57:27349 // SQLite supports attaching multiple database files to a single connection.
[email protected]8d409412013-07-19 18:25:30350 //
Victor Costan7f6abbbe2018-07-29 02:57:27351 // Attach the database in |other_db_path| to the current connection under
352 // |attachment_point|. |attachment_point| must only contain characters from
353 // [a-zA-Z0-9_].
Victor Costan8a87f7e52017-11-10 01:29:30354 //
355 // On the SQLite version shipped with Chrome (3.21+, Oct 2017), databases can
356 // be attached while a transaction is opened. However, these databases cannot
Victor Costan70bedf22018-07-18 21:21:14357 // be detached until the transaction is committed or aborted.
Victor Costan7f6abbbe2018-07-29 02:57:27358 //
359 // These APIs are only exposed for use in recovery. They are extremely subtle
360 // and are not useful for features built on top of //sql.
[email protected]8d409412013-07-19 18:25:30361 bool AttachDatabase(const base::FilePath& other_db_path,
Victor Costan7f6abbbe2018-07-29 02:57:27362 const char* attachment_point,
363 InternalApiToken);
364 bool DetachDatabase(const char* attachment_point, InternalApiToken);
[email protected]8d409412013-07-19 18:25:30365
[email protected]e5ffd0e42009-09-11 21:30:56366 // Statements ----------------------------------------------------------------
367
368 // Executes the given SQL string, returning true on success. This is
369 // normally used for simple, 1-off statements that don't take any bound
370 // parameters and don't return any data (e.g. CREATE TABLE).
[email protected]9fe37552011-12-23 17:07:20371 //
[email protected]eff1fa522011-12-12 23:50:59372 // This will DCHECK if the |sql| contains errors.
[email protected]9fe37552011-12-23 17:07:20373 //
374 // Do not use ignore_result() to ignore all errors. Use
375 // ExecuteAndReturnErrorCode() and ignore only specific errors.
376 bool Execute(const char* sql) WARN_UNUSED_RESULT;
[email protected]e5ffd0e42009-09-11 21:30:56377
[email protected]eff1fa522011-12-12 23:50:59378 // Like Execute(), but returns the error code given by SQLite.
[email protected]9fe37552011-12-23 17:07:20379 int ExecuteAndReturnErrorCode(const char* sql) WARN_UNUSED_RESULT;
[email protected]eff1fa522011-12-12 23:50:59380
[email protected]e5ffd0e42009-09-11 21:30:56381 // Returns a statement for the given SQL using the statement cache. It can
382 // take a nontrivial amount of work to parse and compile a statement, so
383 // keeping commonly-used ones around for future use is important for
384 // performance.
385 //
Victor Costan613b4302018-11-20 05:32:43386 // The SQL_FROM_HERE macro is the recommended way of generating a StatementID.
387 // Code that generates custom IDs must ensure that a StatementID is never used
388 // for different SQL statements. Failing to meet this requirement results in
389 // incorrect behavior, and should be caught by a DCHECK.
390 //
391 // The SQL statement passed in |sql| must match the SQL statement reported
392 // back by SQLite. Mismatches are caught by a DCHECK, so any code that has
393 // automated test coverage or that was manually tested on a DCHECK build will
394 // not exhibit this problem. Mismatches generally imply that the statement
395 // passed in has extra whitespace or comments surrounding it, which waste
396 // storage and CPU cycles.
397 //
[email protected]eff1fa522011-12-12 23:50:59398 // If the |sql| has an error, an invalid, inert StatementRef is returned (and
399 // the code will crash in debug). The caller must deal with this eventuality,
400 // either by checking validity of the |sql| before calling, by correctly
401 // handling the return of an inert statement, or both.
[email protected]e5ffd0e42009-09-11 21:30:56402 //
[email protected]e5ffd0e42009-09-11 21:30:56403 // Example:
Victor Costancfbfa602018-08-01 23:24:46404 // sql::Statement stmt(database_.GetCachedStatement(
[email protected]3273dce2010-01-27 16:08:08405 // SQL_FROM_HERE, "SELECT * FROM foo"));
[email protected]e5ffd0e42009-09-11 21:30:56406 // if (!stmt)
407 // return false; // Error creating statement.
Victor Costan12daa3ac92018-07-19 01:05:58408 scoped_refptr<StatementRef> GetCachedStatement(StatementID id,
[email protected]e5ffd0e42009-09-11 21:30:56409 const char* sql);
410
[email protected]eff1fa522011-12-12 23:50:59411 // Used to check a |sql| statement for syntactic validity. If the statement is
412 // valid SQL, returns true.
413 bool IsSQLValid(const char* sql);
414
[email protected]e5ffd0e42009-09-11 21:30:56415 // Returns a non-cached statement for the given SQL. Use this for SQL that
416 // is only executed once or only rarely (there is overhead associated with
417 // keeping a statement cached).
418 //
419 // See GetCachedStatement above for examples and error information.
420 scoped_refptr<StatementRef> GetUniqueStatement(const char* sql);
421
Shubham Aggarwalbe4f97ce2020-06-19 15:58:57422 // Performs a passive checkpoint on the main attached database if it is in
423 // WAL mode. Returns true if the checkpoint was successful and false in case
424 // of an error. It is a no-op if the database is not in WAL mode.
425 //
426 // Note: Checkpointing is a very slow operation and will block any writes
427 // until it is finished. Please use with care.
428 bool CheckpointDatabase();
429
[email protected]e5ffd0e42009-09-11 21:30:56430 // Info querying -------------------------------------------------------------
431
shessa62504d2016-11-07 19:26:12432 // Returns true if the given structure exists. Instead of test-then-create,
433 // callers should almost always prefer the "IF NOT EXISTS" version of the
434 // CREATE statement.
[email protected]e2cadec82011-12-13 02:00:53435 bool DoesIndexExist(const char* index_name) const;
shessa62504d2016-11-07 19:26:12436 bool DoesTableExist(const char* table_name) const;
437 bool DoesViewExist(const char* table_name) const;
[email protected]e2cadec82011-12-13 02:00:53438
[email protected]e5ffd0e42009-09-11 21:30:56439 // Returns true if a column with the given name exists in the given table.
Victor Costan1ff47e92018-12-07 11:10:43440 //
441 // Calling this method on a VIEW returns an unspecified result.
442 //
443 // This should only be used by migration code for legacy features that do not
444 // use MetaTable, and need an alternative way of figuring out the database's
445 // current version.
[email protected]1ed78a32009-09-15 20:24:17446 bool DoesColumnExist(const char* table_name, const char* column_name) const;
[email protected]e5ffd0e42009-09-11 21:30:56447
448 // Returns sqlite's internal ID for the last inserted row. Valid only
449 // immediately after an insert.
tfarina720d4f32015-05-11 22:31:26450 int64_t GetLastInsertRowId() const;
[email protected]e5ffd0e42009-09-11 21:30:56451
[email protected]1ed78a32009-09-15 20:24:17452 // Returns sqlite's count of the number of rows modified by the last
453 // statement executed. Will be 0 if no statement has executed or the database
454 // is closed.
455 int GetLastChangeCount() const;
456
[email protected]e5ffd0e42009-09-11 21:30:56457 // Errors --------------------------------------------------------------------
458
459 // Returns the error code associated with the last sqlite operation.
460 int GetErrorCode() const;
461
[email protected]767718e52010-09-21 23:18:49462 // Returns the errno associated with GetErrorCode(). See
463 // SQLITE_LAST_ERRNO in SQLite documentation.
464 int GetLastErrno() const;
465
[email protected]e5ffd0e42009-09-11 21:30:56466 // Returns a pointer to a statically allocated string associated with the
467 // last sqlite operation.
468 const char* GetErrorMessage() const;
469
[email protected]92cd00a2013-08-16 11:09:58470 // Return a reproducible representation of the schema equivalent to
471 // running the following statement at a sqlite3 command-line:
472 // SELECT type, name, tbl_name, sql FROM sqlite_master ORDER BY 1, 2, 3, 4;
473 std::string GetSchema() const;
474
shess976814402016-06-21 06:56:25475 // Returns |true| if there is an error expecter (see SetErrorExpecter), and
476 // that expecter returns |true| when passed |error|. Clients which provide an
477 // |error_callback| should use IsExpectedSqliteError() to check for unexpected
Sigurdur Asgeirsson8d82bd02017-09-25 21:05:52478 // errors; if one is detected, DLOG(DCHECK) is generally appropriate (see
shess976814402016-06-21 06:56:25479 // OnSqliteError implementation).
480 static bool IsExpectedSqliteError(int error);
[email protected]74cdede2013-09-25 05:39:57481
Victor Costance678e72018-07-24 10:25:00482 // Computes the path of a database's rollback journal.
483 //
484 // The journal file is created at the beginning of the database's first
485 // transaction. The file may be removed and re-created between transactions,
486 // depending on whether the database is opened in exclusive mode, and on
487 // configuration options. The journal file does not exist when the database
488 // operates in WAL mode.
489 //
490 // This is intended for internal use and tests. To preserve our ability to
491 // iterate on our SQLite configuration, features must avoid relying on
492 // the existence of specific files.
493 static base::FilePath JournalPath(const base::FilePath& db_path);
494
495 // Computes the path of a database's write-ahead log (WAL).
496 //
497 // The WAL file exists while a database is opened in WAL mode.
498 //
499 // This is intended for internal use and tests. To preserve our ability to
500 // iterate on our SQLite configuration, features must avoid relying on
501 // the existence of specific files.
502 static base::FilePath WriteAheadLogPath(const base::FilePath& db_path);
503
504 // Computes the path of a database's shared memory (SHM) file.
505 //
506 // The SHM file is used to coordinate between multiple processes using the
507 // same database in WAL mode. Thus, this file only exists for databases using
508 // WAL and not opened in exclusive mode.
509 //
510 // This is intended for internal use and tests. To preserve our ability to
511 // iterate on our SQLite configuration, features must avoid relying on
512 // the existence of specific files.
513 static base::FilePath SharedMemoryFilePath(const base::FilePath& db_path);
514
Victor Costan7f6abbbe2018-07-29 02:57:27515 // Default page size for newly created databases.
516 //
517 // Guaranteed to match SQLITE_DEFAULT_PAGE_SIZE.
518 static constexpr int kDefaultPageSize = 4096;
[email protected]8d409412013-07-19 18:25:30519
Victor Costan7f6abbbe2018-07-29 02:57:27520 // Internal state accessed by other classes in //sql.
521 sqlite3* db(InternalApiToken) const { return db_; }
522 bool poisoned(InternalApiToken) const { return poisoned_; }
523
524 private:
shess976814402016-06-21 06:56:25525 // Allow test-support code to set/reset error expecter.
526 friend class test::ScopedErrorExpecter;
[email protected]4350e322013-06-18 22:18:10527
[email protected]eff1fa522011-12-12 23:50:59528 // Statement accesses StatementRef which we don't want to expose to everybody
[email protected]e5ffd0e42009-09-11 21:30:56529 // (they should go through Statement).
530 friend class Statement;
531
Victor Costancfbfa602018-08-01 23:24:46532 FRIEND_TEST_ALL_PREFIXES(SQLDatabaseTest, CachedStatement);
533 FRIEND_TEST_ALL_PREFIXES(SQLDatabaseTest, CollectDiagnosticInfo);
534 FRIEND_TEST_ALL_PREFIXES(SQLDatabaseTest, GetAppropriateMmapSize);
535 FRIEND_TEST_ALL_PREFIXES(SQLDatabaseTest, GetAppropriateMmapSizeAltStatus);
536 FRIEND_TEST_ALL_PREFIXES(SQLDatabaseTest, OnMemoryDump);
537 FRIEND_TEST_ALL_PREFIXES(SQLDatabaseTest, RegisterIntentToUpload);
shessf7fcc452017-04-19 22:10:41538 FRIEND_TEST_ALL_PREFIXES(SQLiteFeaturesTest, WALNoClose);
shessc8cd2a162015-10-22 20:30:46539
[email protected]765b44502009-10-02 05:01:42540 // Internal initialize function used by both Init and InitInMemory. The file
541 // name is always 8 bits since we want to use the 8-bit version of
542 // sqlite3_open. The string can also be sqlite's special ":memory:" string.
[email protected]fed734a2013-07-17 04:45:13543 //
544 // |retry_flag| controls retrying the open if the error callback
545 // addressed errors using RazeAndClose().
Victor Costancfbfa602018-08-01 23:24:46546 enum Retry { NO_RETRY = 0, RETRY_ON_POISON };
[email protected]fed734a2013-07-17 04:45:13547 bool OpenInternal(const std::string& file_name, Retry retry_flag);
[email protected]765b44502009-10-02 05:01:42548
[email protected]41a97c812013-02-07 02:35:38549 // Internal close function used by Close() and RazeAndClose().
550 // |forced| indicates that orderly-shutdown checks should not apply.
551 void CloseInternal(bool forced);
552
Etienne Pierre-Doraya71d7af2019-02-07 02:07:54553 // Construct a ScopedBlockingCall to annotate IO calls, but only if
Etienne Bergerone7681c72020-01-17 00:51:20554 // database wasn't open in memory. ScopedBlockingCall uses |from_here| to
555 // declare its blocking execution scope (see https://www.crbug/934302).
Etienne Pierre-Doraya71d7af2019-02-07 02:07:54556 void InitScopedBlockingCall(
Etienne Bergerone7681c72020-01-17 00:51:20557 const base::Location& from_here,
Etienne Pierre-Doraya71d7af2019-02-07 02:07:54558 base::Optional<base::ScopedBlockingCall>* scoped_blocking_call) const {
[email protected]35f7e5392012-07-27 19:54:50559 if (!in_memory_)
Etienne Bergerone7681c72020-01-17 00:51:20560 scoped_blocking_call->emplace(from_here, base::BlockingType::MAY_BLOCK);
[email protected]35f7e5392012-07-27 19:54:50561 }
562
shessa62504d2016-11-07 19:26:12563 // Internal helper for Does*Exist() functions.
564 bool DoesSchemaItemExist(const char* name, const char* type) const;
[email protected]e2cadec82011-12-13 02:00:53565
shess976814402016-06-21 06:56:25566 // Accessors for global error-expecter, for injecting behavior during tests.
567 // See test/scoped_error_expecter.h.
Victor Costanc7e7f2e2018-07-18 20:07:55568 using ErrorExpecterCallback = base::RepeatingCallback<bool(int)>;
shess976814402016-06-21 06:56:25569 static ErrorExpecterCallback* current_expecter_cb_;
570 static void SetErrorExpecter(ErrorExpecterCallback* expecter);
571 static void ResetErrorExpecter();
[email protected]4350e322013-06-18 22:18:10572
[email protected]e5ffd0e42009-09-11 21:30:56573 // A StatementRef is a refcounted wrapper around a sqlite statement pointer.
574 // Refcounting allows us to give these statements out to sql::Statement
575 // objects while also optionally maintaining a cache of compiled statements
576 // by just keeping a refptr to these objects.
577 //
578 // A statement ref can be valid, in which case it can be used, or invalid to
579 // indicate that the statement hasn't been created yet, has an error, or has
580 // been destroyed.
581 //
Victor Costancfbfa602018-08-01 23:24:46582 // The Database may revoke a StatementRef in some error cases, so callers
[email protected]e5ffd0e42009-09-11 21:30:56583 // should always check validity before using.
Victor Costane56cc682018-12-27 01:53:46584 class COMPONENT_EXPORT(SQL) StatementRef
585 : public base::RefCounted<StatementRef> {
[email protected]e5ffd0e42009-09-11 21:30:56586 public:
Victor Costan3b02cdf2018-07-18 00:39:56587 REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE();
588
Victor Costancfbfa602018-08-01 23:24:46589 // |database| is the sql::Database instance associated with
[email protected]41a97c812013-02-07 02:35:38590 // the statement, and is used for tracking outstanding statements
Victor Costanbd623112018-07-18 04:17:27591 // and for error handling. Set to nullptr for invalid or untracked
592 // refs. |stmt| is the actual statement, and should only be null
[email protected]41a97c812013-02-07 02:35:38593 // to create an invalid ref. |was_valid| indicates whether the
Etienne Bergeron95a01c2a2019-02-26 21:32:50594 // statement should be considered valid for diagnostic purposes.
Victor Costancfbfa602018-08-01 23:24:46595 // |was_valid| can be true for a null |stmt| if the Database has
[email protected]41a97c812013-02-07 02:35:38596 // been forcibly closed by an error handler.
Victor Costancfbfa602018-08-01 23:24:46597 StatementRef(Database* database, sqlite3_stmt* stmt, bool was_valid);
[email protected]e5ffd0e42009-09-11 21:30:56598
599 // When true, the statement can be used.
600 bool is_valid() const { return !!stmt_; }
601
[email protected]41a97c812013-02-07 02:35:38602 // When true, the statement is either currently valid, or was
Victor Costancfbfa602018-08-01 23:24:46603 // previously valid but the database was forcibly closed. Used
[email protected]41a97c812013-02-07 02:35:38604 // for diagnostic checks.
605 bool was_valid() const { return was_valid_; }
606
Victor Costancfbfa602018-08-01 23:24:46607 // If we've not been linked to a database, this will be null.
Victor Costanbd623112018-07-18 04:17:27608 //
Victor Costancfbfa602018-08-01 23:24:46609 // TODO(shess): database_ can be nullptr in case of
Victor Costanbd623112018-07-18 04:17:27610 // GetUntrackedStatement(), which prevents Statement::OnError() from
611 // forwarding errors.
Victor Costancfbfa602018-08-01 23:24:46612 Database* database() const { return database_; }
[email protected]e5ffd0e42009-09-11 21:30:56613
614 // Returns the sqlite statement if any. If the statement is not active,
Victor Costanbd623112018-07-18 04:17:27615 // this will return nullptr.
[email protected]e5ffd0e42009-09-11 21:30:56616 sqlite3_stmt* stmt() const { return stmt_; }
617
Victor Costanbd623112018-07-18 04:17:27618 // Destroys the compiled statement and sets it to nullptr. The statement
619 // will no longer be active. |forced| is used to indicate if
Victor Costancfbfa602018-08-01 23:24:46620 // orderly-shutdown checks should apply (see Database::RazeAndClose()).
[email protected]41a97c812013-02-07 02:35:38621 void Close(bool forced);
[email protected]e5ffd0e42009-09-11 21:30:56622
Etienne Pierre-Doraya71d7af2019-02-07 02:07:54623 // Construct a ScopedBlockingCall to annotate IO calls, but only if
Etienne Bergerone7681c72020-01-17 00:51:20624 // database wasn't open in memory. ScopedBlockingCall uses |from_here| to
625 // declare its blocking execution scope (see https://www.crbug/934302).
Etienne Pierre-Doraya71d7af2019-02-07 02:07:54626 void InitScopedBlockingCall(
Etienne Bergerone7681c72020-01-17 00:51:20627 const base::Location& from_here,
Etienne Pierre-Doraya71d7af2019-02-07 02:07:54628 base::Optional<base::ScopedBlockingCall>* scoped_blocking_call) const {
Victor Costancfbfa602018-08-01 23:24:46629 if (database_)
Etienne Bergerone7681c72020-01-17 00:51:20630 database_->InitScopedBlockingCall(from_here, scoped_blocking_call);
Victor Costanc7e7f2e2018-07-18 20:07:55631 }
[email protected]35f7e5392012-07-27 19:54:50632
[email protected]e5ffd0e42009-09-11 21:30:56633 private:
[email protected]877d55d2009-11-05 21:53:08634 friend class base::RefCounted<StatementRef>;
635
636 ~StatementRef();
637
Victor Costancfbfa602018-08-01 23:24:46638 Database* database_;
[email protected]e5ffd0e42009-09-11 21:30:56639 sqlite3_stmt* stmt_;
[email protected]41a97c812013-02-07 02:35:38640 bool was_valid_;
[email protected]e5ffd0e42009-09-11 21:30:56641
642 DISALLOW_COPY_AND_ASSIGN(StatementRef);
643 };
644 friend class StatementRef;
645
646 // Executes a rollback statement, ignoring all transaction state. Used
647 // internally in the transaction management code.
648 void DoRollback();
649
650 // Called by a StatementRef when it's being created or destroyed. See
651 // open_statements_ below.
652 void StatementRefCreated(StatementRef* ref);
653 void StatementRefDeleted(StatementRef* ref);
654
[email protected]2f496b42013-09-26 18:36:58655 // Called when a sqlite function returns an error, which is passed
656 // as |err|. The return value is the error code to be reflected
Victor Costanbd623112018-07-18 04:17:27657 // back to client code. |stmt| is non-null if the error relates to
658 // an sql::Statement instance. |sql| is non-nullptr if the error
[email protected]2f496b42013-09-26 18:36:58659 // relates to non-statement sql code (Execute, for instance). Both
Victor Costanbd623112018-07-18 04:17:27660 // can be null, but both should never be set.
[email protected]2f496b42013-09-26 18:36:58661 // NOTE(shess): Originally, the return value was intended to allow
662 // error handlers to transparently convert errors into success.
663 // Unfortunately, transactions are not generally restartable, so
664 // this did not work out.
shess9e77283d2016-06-13 23:53:20665 int OnSqliteError(int err, Statement* stmt, const char* sql) const;
[email protected]faa604e2009-09-25 22:38:59666
[email protected]5b96f3772010-09-28 16:30:57667 // Like |Execute()|, but retries if the database is locked.
Victor Costancfbfa602018-08-01 23:24:46668 bool ExecuteWithTimeout(const char* sql,
669 base::TimeDelta ms_timeout) WARN_UNUSED_RESULT;
[email protected]5b96f3772010-09-28 16:30:57670
shess9e77283d2016-06-13 23:53:20671 // Implementation helper for GetUniqueStatement() and GetUntrackedStatement().
672 // |tracking_db| is the db the resulting ref should register with for
Victor Costanbd623112018-07-18 04:17:27673 // outstanding statement tracking, which should be |this| to track or null to
shess9e77283d2016-06-13 23:53:20674 // not track.
Victor Costancfbfa602018-08-01 23:24:46675 scoped_refptr<StatementRef> GetStatementImpl(sql::Database* tracking_db,
676 const char* sql) const;
shess9e77283d2016-06-13 23:53:20677
678 // Helper for implementing const member functions. Like GetUniqueStatement(),
679 // except the StatementRef is not entered into |open_statements_|, so an
680 // outstanding StatementRef from this function can block closing the database.
681 // The StatementRef will not call OnSqliteError(), because that can call
682 // |error_callback_| which can close the database.
[email protected]2eec0a22012-07-24 01:59:58683 scoped_refptr<StatementRef> GetUntrackedStatement(const char* sql) const;
684
Victor Costancfbfa602018-08-01 23:24:46685 bool IntegrityCheckHelper(const char* pragma_sql,
686 std::vector<std::string>* messages)
687 WARN_UNUSED_RESULT;
[email protected]579446c2013-12-16 18:36:52688
shess7dbd4dee2015-10-06 17:39:16689 // Release page-cache memory if memory-mapped I/O is enabled and the database
690 // was changed. Passing true for |implicit_change_performed| allows
691 // overriding the change detection for cases like DDL (CREATE, DROP, etc),
692 // which do not participate in the total-rows-changed tracking.
693 void ReleaseCacheMemoryIfNeeded(bool implicit_change_performed);
694
shessc8cd2a162015-10-22 20:30:46695 // Returns the results of sqlite3_db_filename(), which should match the path
696 // passed to Open().
697 base::FilePath DbPath() const;
698
shessc8cd2a162015-10-22 20:30:46699 // Helper to collect diagnostic info for a corrupt database.
700 std::string CollectCorruptionInfo();
701
702 // Helper to collect diagnostic info for errors.
703 std::string CollectErrorInfo(int error, Statement* stmt) const;
704
shessd90aeea82015-11-13 02:24:31705 // Calculates a value appropriate to pass to "PRAGMA mmap_size = ". So errors
706 // can make it unsafe to map a file, so the file is read using regular I/O,
707 // with any errors causing 0 (don't map anything) to be returned. If the
708 // entire file is read without error, a large value is returned which will
709 // allow the entire file to be mapped in most cases.
710 //
711 // Results are recorded in the database's meta table for future reference, so
712 // the file should only be read through once.
713 size_t GetAppropriateMmapSize();
714
shessa62504d2016-11-07 19:26:12715 // Helpers for GetAppropriateMmapSize().
716 bool GetMmapAltStatus(int64_t* status);
717 bool SetMmapAltStatus(int64_t status);
718
Victor Costanbd623112018-07-18 04:17:27719 // The actual sqlite database. Will be null before Init has been called or if
[email protected]e5ffd0e42009-09-11 21:30:56720 // Init resulted in an error.
721 sqlite3* db_;
722
723 // Parameters we'll configure in sqlite before doing anything else. Zero means
724 // use the default value.
725 int page_size_;
726 int cache_size_;
Shubham Aggarwalbe4f97ce2020-06-19 15:58:57727
[email protected]e5ffd0e42009-09-11 21:30:56728 bool exclusive_locking_;
Shubham Aggarwalbe4f97ce2020-06-19 15:58:57729 bool want_wal_mode_;
[email protected]e5ffd0e42009-09-11 21:30:56730
Victor Costanc7e7f2e2018-07-18 20:07:55731 // Holds references to all cached statements so they remain active.
732 //
733 // flat_map is appropriate here because the codebase has ~400 cached
734 // statements, and each statement is at most one insertion in the map
735 // throughout a process' lifetime.
736 base::flat_map<StatementID, scoped_refptr<StatementRef>> statement_cache_;
[email protected]e5ffd0e42009-09-11 21:30:56737
738 // A list of all StatementRefs we've given out. Each ref must register with
739 // us when it's created or destroyed. This allows us to potentially close
740 // any open statements when we encounter an error.
Victor Costanc7e7f2e2018-07-18 20:07:55741 std::set<StatementRef*> open_statements_;
[email protected]e5ffd0e42009-09-11 21:30:56742
743 // Number of currently-nested transactions.
744 int transaction_nesting_;
745
746 // True if any of the currently nested transactions have been rolled back.
747 // When we get to the outermost transaction, this will determine if we do
748 // a rollback instead of a commit.
749 bool needs_rollback_;
750
[email protected]35f7e5392012-07-27 19:54:50751 // True if database is open with OpenInMemory(), False if database is open
752 // with Open().
753 bool in_memory_;
754
Victor Costancfbfa602018-08-01 23:24:46755 // |true| if the Database was closed using RazeAndClose(). Used
[email protected]41a97c812013-02-07 02:35:38756 // to enable diagnostics to distinguish calls to never-opened
757 // databases (incorrect use of the API) from calls to once-valid
758 // databases.
759 bool poisoned_;
760
shessa62504d2016-11-07 19:26:12761 // |true| to use alternate storage for tracking mmap status.
762 bool mmap_alt_status_;
763
Victor Costancfbfa602018-08-01 23:24:46764 // |true| if SQLite memory-mapped I/O is not desired for this database.
shess7dbd4dee2015-10-06 17:39:16765 bool mmap_disabled_;
766
Victor Costancfbfa602018-08-01 23:24:46767 // |true| if SQLite memory-mapped I/O was enabled for this database.
shess7dbd4dee2015-10-06 17:39:16768 // Used by ReleaseCacheMemoryIfNeeded().
769 bool mmap_enabled_;
770
771 // Used by ReleaseCacheMemoryIfNeeded() to track if new changes have happened
772 // since memory was last released.
773 int total_changes_at_last_release_;
774
[email protected]c3881b372013-05-17 08:39:46775 ErrorCallback error_callback_;
776
[email protected]210ce0af2013-05-15 09:10:39777 // Tag for auxiliary histograms.
778 std::string histogram_tag_;
[email protected]c088e3a32013-01-03 23:59:14779
shess58b8df82015-06-03 00:19:32780 // Linear histogram for RecordEvent().
781 base::HistogramBase* stats_histogram_;
782
ssid3be5b1ec2016-01-13 14:21:57783 // Stores the dump provider object when db is open.
Victor Costancfbfa602018-08-01 23:24:46784 std::unique_ptr<DatabaseMemoryDumpProvider> memory_dump_provider_;
ssid3be5b1ec2016-01-13 14:21:57785
Victor Costancfbfa602018-08-01 23:24:46786 DISALLOW_COPY_AND_ASSIGN(Database);
[email protected]e5ffd0e42009-09-11 21:30:56787};
788
789} // namespace sql
790
Victor Costancfbfa602018-08-01 23:24:46791#endif // SQL_DATABASE_H_