OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SQL_META_TABLE_H_ | 5 #ifndef SQL_META_TABLE_H_ |
6 #define SQL_META_TABLE_H_ | 6 #define SQL_META_TABLE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "sql/sql_export.h" | 12 #include "sql/sql_export.h" |
13 | 13 |
14 namespace sql { | 14 namespace sql { |
15 | 15 |
16 class Connection; | 16 class Connection; |
17 class Statement; | 17 class Statement; |
18 | 18 |
19 class SQL_EXPORT MetaTable { | 19 class SQL_EXPORT MetaTable { |
20 public: | 20 public: |
21 MetaTable(); | 21 MetaTable(); |
22 ~MetaTable(); | 22 ~MetaTable(); |
23 | 23 |
| 24 // Values for Get/SetMmapStatus(). |kMmapFailure| indicates that there was at |
| 25 // some point a read error and the database should not be memory-mapped, while |
| 26 // |kMmapSuccess| indicates that the entire file was read at some point and |
| 27 // can be memory-mapped without constraint. |
| 28 static int64_t kMmapFailure; |
| 29 static int64_t kMmapSuccess; |
| 30 |
24 // Returns true if the 'meta' table exists. | 31 // Returns true if the 'meta' table exists. |
25 static bool DoesTableExist(Connection* db); | 32 static bool DoesTableExist(Connection* db); |
26 | 33 |
27 // If the current version of the database is less than or equal to | 34 // If the current version of the database is less than or equal to |
28 // |deprecated_version|, raze the database. Must be called outside | 35 // |deprecated_version|, raze the database. Must be called outside |
29 // of a transaction. | 36 // of a transaction. |
30 // TODO(shess): At this time the database is razed IFF meta exists | 37 // TODO(shess): At this time the database is razed IFF meta exists |
31 // and contains a version row with value <= deprecated_version. It | 38 // and contains a version row with value <= deprecated_version. It |
32 // may make sense to also raze if meta exists but has no version | 39 // may make sense to also raze if meta exists but has no version |
33 // row, or if meta doesn't exist. In those cases if the database is | 40 // row, or if meta doesn't exist. In those cases if the database is |
34 // not already empty, it probably resulted from a broken | 41 // not already empty, it probably resulted from a broken |
35 // initialization. | 42 // initialization. |
36 // TODO(shess): Folding this into Init() would allow enforcing | 43 // TODO(shess): Folding this into Init() would allow enforcing |
37 // |deprecated_version|<|version|. But Init() is often called in a | 44 // |deprecated_version|<|version|. But Init() is often called in a |
38 // transaction. | 45 // transaction. |
39 static void RazeIfDeprecated(Connection* db, int deprecated_version); | 46 static void RazeIfDeprecated(Connection* db, int deprecated_version); |
40 | 47 |
| 48 // Used to tuck some data into the meta table about mmap status. The value |
| 49 // represents how much data in bytes has successfully been read from the |
| 50 // database, or |kMmapFailure| or |kMmapSuccess|. |
| 51 static bool GetMmapStatus(Connection* db, int64_t* status); |
| 52 static bool SetMmapStatus(Connection* db, int64_t status); |
| 53 |
41 // Initializes the MetaTableHelper, creating the meta table if necessary. For | 54 // Initializes the MetaTableHelper, creating the meta table if necessary. For |
42 // new tables, it will initialize the version number to |version| and the | 55 // new tables, it will initialize the version number to |version| and the |
43 // compatible version number to |compatible_version|. Versions must be | 56 // compatible version number to |compatible_version|. Versions must be |
44 // greater than 0 to distinguish missing versions (see GetVersionNumber()). | 57 // greater than 0 to distinguish missing versions (see GetVersionNumber()). |
| 58 // If there was no meta table (proxy for a fresh database), mmap status is set |
| 59 // to |kMmapSuccess|. |
45 bool Init(Connection* db, int version, int compatible_version); | 60 bool Init(Connection* db, int version, int compatible_version); |
46 | 61 |
47 // Resets this MetaTable object, making another call to Init() possible. | 62 // Resets this MetaTable object, making another call to Init() possible. |
48 void Reset(); | 63 void Reset(); |
49 | 64 |
50 // The version number of the database. This should be the version number of | 65 // The version number of the database. This should be the version number of |
51 // the creator of the file. The version number will be 0 if there is no | 66 // the creator of the file. The version number will be 0 if there is no |
52 // previously set version number. | 67 // previously set version number. |
53 // | 68 // |
54 // See also Get/SetCompatibleVersionNumber(). | 69 // See also Get/SetCompatibleVersionNumber(). |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 bool PrepareGetStatement(Statement* statement, const char* key); | 108 bool PrepareGetStatement(Statement* statement, const char* key); |
94 | 109 |
95 Connection* db_; | 110 Connection* db_; |
96 | 111 |
97 DISALLOW_COPY_AND_ASSIGN(MetaTable); | 112 DISALLOW_COPY_AND_ASSIGN(MetaTable); |
98 }; | 113 }; |
99 | 114 |
100 } // namespace sql | 115 } // namespace sql |
101 | 116 |
102 #endif // SQL_META_TABLE_H_ | 117 #endif // SQL_META_TABLE_H_ |
OLD | NEW |