| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_TEST_TEST_HELPERS_H_ | 5 #ifndef SQL_TEST_TEST_HELPERS_H_ |
| 6 #define SQL_TEST_TEST_HELPERS_H_ | 6 #define SQL_TEST_TEST_HELPERS_H_ |
| 7 | 7 |
| 8 #include <string> |
| 9 |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 10 | 12 |
| 11 // Collection of test-only convenience functions. | 13 // Collection of test-only convenience functions. |
| 12 | 14 |
| 13 namespace base { | 15 namespace base { |
| 14 class FilePath; | 16 class FilePath; |
| 15 } | 17 } |
| 16 | 18 |
| 17 namespace sql { | 19 namespace sql { |
| 18 class Connection; | 20 class Connection; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace sql { | 23 namespace sql { |
| 22 namespace test { | 24 namespace test { |
| 23 | 25 |
| 26 // SQLite stores the database size in the header, and if the actual |
| 27 // OS-derived size is smaller, the database is considered corrupt. |
| 28 // [This case is actually a common form of corruption in the wild.] |
| 29 // This helper sets the in-header size to one page larger than the |
| 30 // actual file size. The resulting file will return SQLITE_CORRUPT |
| 31 // for most operations unless PRAGMA writable_schema is turned ON. |
| 32 // |
| 33 // Returns false if any error occurs accessing the file. |
| 34 bool CorruptSizeInHeader(const base::FilePath& db_path) WARN_UNUSED_RESULT; |
| 35 |
| 24 // Return the number of tables in sqlite_master. | 36 // Return the number of tables in sqlite_master. |
| 25 size_t CountSQLTables(sql::Connection* db) WARN_UNUSED_RESULT; | 37 size_t CountSQLTables(sql::Connection* db) WARN_UNUSED_RESULT; |
| 26 | 38 |
| 27 // Return the number of indices in sqlite_master. | 39 // Return the number of indices in sqlite_master. |
| 28 size_t CountSQLIndices(sql::Connection* db) WARN_UNUSED_RESULT; | 40 size_t CountSQLIndices(sql::Connection* db) WARN_UNUSED_RESULT; |
| 29 | 41 |
| 30 // Returns the number of columns in the named table. 0 indicates an | 42 // Returns the number of columns in the named table. 0 indicates an |
| 31 // error (probably no such table). | 43 // error (probably no such table). |
| 32 size_t CountTableColumns(sql::Connection* db, const char* table) | 44 size_t CountTableColumns(sql::Connection* db, const char* table) |
| 33 WARN_UNUSED_RESULT; | 45 WARN_UNUSED_RESULT; |
| 34 | 46 |
| 35 // Sets |*count| to the number of rows in |table|. Returns false in | 47 // Sets |*count| to the number of rows in |table|. Returns false in |
| 36 // case of error, such as the table not existing. | 48 // case of error, such as the table not existing. |
| 37 bool CountTableRows(sql::Connection* db, const char* table, size_t* count); | 49 bool CountTableRows(sql::Connection* db, const char* table, size_t* count); |
| 38 | 50 |
| 39 // Creates a SQLite database at |db_path| from the sqlite .dump output | 51 // Creates a SQLite database at |db_path| from the sqlite .dump output |
| 40 // at |sql_path|. Returns false if |db_path| already exists, or if | 52 // at |sql_path|. Returns false if |db_path| already exists, or if |
| 41 // sql_path does not exist or cannot be read, or if there is an error | 53 // sql_path does not exist or cannot be read, or if there is an error |
| 42 // executing the statements. | 54 // executing the statements. |
| 43 bool CreateDatabaseFromSQL(const base::FilePath& db_path, | 55 bool CreateDatabaseFromSQL(const base::FilePath& db_path, |
| 44 const base::FilePath& sql_path) WARN_UNUSED_RESULT; | 56 const base::FilePath& sql_path) WARN_UNUSED_RESULT; |
| 45 | 57 |
| 58 // Return the results of running "PRAGMA integrity_check" on |db|. |
| 59 // TODO(shess): sql::Connection::IntegrityCheck() is basically the |
| 60 // same, but not as convenient for testing. Maybe combine. |
| 61 std::string IntegrityCheck(sql::Connection* db) WARN_UNUSED_RESULT; |
| 62 |
| 46 } // namespace test | 63 } // namespace test |
| 47 } // namespace sql | 64 } // namespace sql |
| 48 | 65 |
| 49 #endif // SQL_TEST_TEST_HELPERS_H_ | 66 #endif // SQL_TEST_TEST_HELPERS_H_ |
| OLD | NEW |