| 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 #include "chrome/common/sqlite_utils.h" | 5 #include "chrome/common/sqlite_utils.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 | 9 |
| 10 int OpenSqliteDb(const FilePath& filepath, sqlite3** database) { |
| 11 #if defined(OS_WIN) |
| 12 return sqlite3_open16(filepath.value().c_str(), database); |
| 13 #elif defined(OS_POSIX) |
| 14 return sqlite3_open(filepath.value().c_str(), database); |
| 15 #endif |
| 16 } |
| 17 |
| 9 bool DoesSqliteTableExist(sqlite3* db, | 18 bool DoesSqliteTableExist(sqlite3* db, |
| 10 const char* db_name, | 19 const char* db_name, |
| 11 const char* table_name) { | 20 const char* table_name) { |
| 12 // sqlite doesn't allow binding parameters as table names, so we have to | 21 // sqlite doesn't allow binding parameters as table names, so we have to |
| 13 // manually construct the sql | 22 // manually construct the sql |
| 14 std::string sql("SELECT name FROM "); | 23 std::string sql("SELECT name FROM "); |
| 15 if (db_name && db_name[0]) { | 24 if (db_name && db_name[0]) { |
| 16 sql.append(db_name); | 25 sql.append(db_name); |
| 17 sql.push_back('.'); | 26 sql.push_back('.'); |
| 18 } | 27 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 std::string b; | 73 std::string b; |
| 65 b.append("SELECT * FROM "); | 74 b.append("SELECT * FROM "); |
| 66 b.append(table_name); | 75 b.append(table_name); |
| 67 | 76 |
| 68 if (s.prepare(db, b.c_str()) != SQLITE_OK) | 77 if (s.prepare(db, b.c_str()) != SQLITE_OK) |
| 69 return false; | 78 return false; |
| 70 | 79 |
| 71 return s.step() == SQLITE_ROW; | 80 return s.step() == SQLITE_ROW; |
| 72 } | 81 } |
| 73 | 82 |
| 74 | |
| 75 SQLTransaction::SQLTransaction(sqlite3* db) : db_(db), began_(false) { | 83 SQLTransaction::SQLTransaction(sqlite3* db) : db_(db), began_(false) { |
| 76 } | 84 } |
| 77 | 85 |
| 78 SQLTransaction::~SQLTransaction() { | 86 SQLTransaction::~SQLTransaction() { |
| 79 if (began_) { | 87 if (began_) { |
| 80 Rollback(); | 88 Rollback(); |
| 81 } | 89 } |
| 82 } | 90 } |
| 83 | 91 |
| 84 int SQLTransaction::BeginCommand(const char* command) { | 92 int SQLTransaction::BeginCommand(const char* command) { |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 str->assign(s ? s : std::wstring(L"")); | 408 str->assign(s ? s : std::wstring(L"")); |
| 401 return (s != NULL); | 409 return (s != NULL); |
| 402 } | 410 } |
| 403 | 411 |
| 404 std::wstring SQLStatement::column_string16(int index) { | 412 std::wstring SQLStatement::column_string16(int index) { |
| 405 std::wstring wstr; | 413 std::wstring wstr; |
| 406 column_string16(index, &wstr); | 414 column_string16(index, &wstr); |
| 407 return wstr; | 415 return wstr; |
| 408 } | 416 } |
| 409 | 417 |
| OLD | NEW |