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
3 // found in the LICENSE file.
5 #ifndef SQL_META_TABLE_H_
6 #define SQL_META_TABLE_H_
11 #include "base/basictypes.h"
12 #include "sql/sql_export.h"
19 class SQL_EXPORT MetaTable
{
24 // Returns true if the 'meta' table exists.
25 static bool DoesTableExist(Connection
* db
);
27 // Initializes the MetaTableHelper, creating the meta table if necessary. For
28 // new tables, it will initialize the version number to |version| and the
29 // compatible version number to |compatible_version|. Versions must be
30 // greater than 0 to distinguish missing versions (see GetVersionNumber()).
31 bool Init(Connection
* db
, int version
, int compatible_version
);
33 // Resets this MetaTable object, making another call to Init() possible.
36 // The version number of the database. This should be the version number of
37 // the creator of the file. The version number will be 0 if there is no
38 // previously set version number.
40 // See also Get/SetCompatibleVersionNumber().
41 void SetVersionNumber(int version
);
42 int GetVersionNumber();
44 // The compatible version number is the lowest version of the code that this
45 // database can be read by. If there are minor changes or additions, old
46 // versions of the code can still work with the database without failing.
48 // For example, if an optional column is added to a table in version 3, the
49 // new code will set the version to 3, and the compatible version to 2, since
50 // the code expecting version 2 databases can still read and write the table.
52 // Rule of thumb: check the version number when you're upgrading, but check
53 // the compatible version number to see if you can read the file at all. If
54 // it's larger than you code is expecting, fail.
56 // The compatible version number will be 0 if there is no previously set
57 // compatible version number.
58 void SetCompatibleVersionNumber(int version
);
59 int GetCompatibleVersionNumber();
61 // Set the given arbitrary key with the given data. Returns true on success.
62 bool SetValue(const char* key
, const std::string
& value
);
63 bool SetValue(const char* key
, int value
);
64 bool SetValue(const char* key
, int64 value
);
66 // Retrieves the value associated with the given key. This will use sqlite's
67 // type conversion rules. It will return true on success.
68 bool GetValue(const char* key
, std::string
* value
);
69 bool GetValue(const char* key
, int* value
);
70 bool GetValue(const char* key
, int64
* value
);
72 // Deletes the key from the table.
73 bool DeleteKey(const char* key
);
76 // Conveniences to prepare the two types of statements used by
78 void PrepareSetStatement(Statement
* statement
, const char* key
);
79 bool PrepareGetStatement(Statement
* statement
, const char* key
);
83 DISALLOW_COPY_AND_ASSIGN(MetaTable
);
88 #endif // SQL_META_TABLE_H_