| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_COMMON_SQLITEUTILS_H_ | 5 #ifndef CHROME_COMMON_SQLITEUTILS_H_ |
| 6 #define CHROME_COMMON_SQLITEUTILS_H_ | 6 #define CHROME_COMMON_SQLITEUTILS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 | 12 |
| 13 #include "third_party/sqlite/preprocessed/sqlite3.h" | 13 #include "third_party/sqlite/preprocessed/sqlite3.h" |
| 14 | 14 |
| 15 // forward declarations of classes defined here | 15 // forward declarations of classes defined here |
| 16 class FilePath; |
| 16 class SQLTransaction; | 17 class SQLTransaction; |
| 17 class SQLNestedTransaction; | 18 class SQLNestedTransaction; |
| 18 class SQLNestedTransactionSite; | 19 class SQLNestedTransactionSite; |
| 19 class scoped_sqlite3_stmt_ptr; | 20 class scoped_sqlite3_stmt_ptr; |
| 20 class SQLStatement; | 21 class SQLStatement; |
| 21 | 22 |
| 22 //------------------------------------------------------------------------------ | 23 //------------------------------------------------------------------------------ |
| 23 // A wrapper for sqlite transactions that rollsback when the wrapper | 24 // A wrapper for sqlite transactions that rollsback when the wrapper |
| 24 // goes out of scope if the caller has not already called Commit or Rollback. | 25 // goes out of scope if the caller has not already called Commit or Rollback. |
| 25 // Note: the constructor does NOT Begin a transaction. | 26 // Note: the constructor does NOT Begin a transaction. |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 bool column_string(int index, std::string* str); | 305 bool column_string(int index, std::string* str); |
| 305 std::string column_string(int index); | 306 std::string column_string(int index); |
| 306 const wchar_t* column_text16(int index); | 307 const wchar_t* column_text16(int index); |
| 307 bool column_string16(int index, std::wstring* str); | 308 bool column_string16(int index, std::wstring* str); |
| 308 std::wstring column_string16(int index); | 309 std::wstring column_string16(int index); |
| 309 | 310 |
| 310 private: | 311 private: |
| 311 DISALLOW_COPY_AND_ASSIGN(SQLStatement); | 312 DISALLOW_COPY_AND_ASSIGN(SQLStatement); |
| 312 }; | 313 }; |
| 313 | 314 |
| 315 // TODO(estade): wrap the following static functions in a namespace. |
| 316 |
| 317 // Opens the DB in the file pointed to by |filepath|. |
| 318 // See http://www.sqlite.org/capi3ref.html#sqlite3_open for an explanation |
| 319 // of the return value. |
| 320 int OpenSqliteDb(const FilePath& filepath, sqlite3** database); |
| 321 |
| 314 // Returns true if there is a table with the given name in the database. | 322 // Returns true if there is a table with the given name in the database. |
| 315 // For the version where a database name is specified, it may be NULL or the | 323 // For the version where a database name is specified, it may be NULL or the |
| 316 // empty string if no database name is necessary. | 324 // empty string if no database name is necessary. |
| 317 bool DoesSqliteTableExist(sqlite3* db, | 325 bool DoesSqliteTableExist(sqlite3* db, |
| 318 const char* db_name, | 326 const char* db_name, |
| 319 const char* table_name); | 327 const char* table_name); |
| 320 inline bool DoesSqliteTableExist(sqlite3* db, const char* table_name) { | 328 inline bool DoesSqliteTableExist(sqlite3* db, const char* table_name) { |
| 321 return DoesSqliteTableExist(db, NULL, table_name); | 329 return DoesSqliteTableExist(db, NULL, table_name); |
| 322 } | 330 } |
| 323 | 331 |
| 324 | |
| 325 // Test whether a table has a column matching the provided name and type. | 332 // Test whether a table has a column matching the provided name and type. |
| 326 // Returns true if the column exist and false otherwise. There are two | 333 // Returns true if the column exist and false otherwise. There are two |
| 327 // versions, one that takes a database name, the other that doesn't. The | 334 // versions, one that takes a database name, the other that doesn't. The |
| 328 // database name can be NULL or empty if no name is desired. | 335 // database name can be NULL or empty if no name is desired. |
| 329 // | 336 // |
| 330 // Column type is optional, it can be NULL or empty. If specified, we the | 337 // Column type is optional, it can be NULL or empty. If specified, we the |
| 331 // function will check that the column is of the correct type (case-sensetive). | 338 // function will check that the column is of the correct type (case-sensetive). |
| 332 bool DoesSqliteColumnExist(sqlite3* db, | 339 bool DoesSqliteColumnExist(sqlite3* db, |
| 333 const char* datbase_name, | 340 const char* datbase_name, |
| 334 const char* table_name, | 341 const char* table_name, |
| 335 const char* column_name, | 342 const char* column_name, |
| 336 const char* column_type); | 343 const char* column_type); |
| 337 inline bool DoesSqliteColumnExist(sqlite3* db, | 344 inline bool DoesSqliteColumnExist(sqlite3* db, |
| 338 const char* table_name, | 345 const char* table_name, |
| 339 const char* column_name, | 346 const char* column_name, |
| 340 const char* column_type) { | 347 const char* column_type) { |
| 341 return DoesSqliteColumnExist(db, NULL, table_name, column_name, column_type); | 348 return DoesSqliteColumnExist(db, NULL, table_name, column_name, column_type); |
| 342 } | 349 } |
| 343 | 350 |
| 344 // Test whether a table has one or more rows. Returns true if the table | 351 // Test whether a table has one or more rows. Returns true if the table |
| 345 // has one or more rows and false if the table is empty or doesn't exist. | 352 // has one or more rows and false if the table is empty or doesn't exist. |
| 346 bool DoesSqliteTableHaveRow(sqlite3* db, const char* table_name); | 353 bool DoesSqliteTableHaveRow(sqlite3* db, const char* table_name); |
| 347 | 354 |
| 348 #endif // CHROME_COMMON_SQLITEUTILS_H_ | 355 #endif // CHROME_COMMON_SQLITEUTILS_H_ |
| 349 | 356 |
| OLD | NEW |