| 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 <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 NOTREACHED() << "sqlite error " << error | 35 NOTREACHED() << "sqlite error " << error |
| 36 << " db " << static_cast<void*>(db); | 36 << " db " << static_cast<void*>(db); |
| 37 return error; | 37 return error; |
| 38 } | 38 } |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 class ReleaseSQLErrorHandler : public VanillaSQLErrorHandler { | 41 class ReleaseSQLErrorHandler : public VanillaSQLErrorHandler { |
| 42 public: | 42 public: |
| 43 virtual int HandleError(int error, sqlite3* db) { | 43 virtual int HandleError(int error, sqlite3* db) { |
| 44 error_ = error; | 44 error_ = error; |
| 45 // TODO(cpu): need to write to some place so we can trigger | 45 // TOD(cpu): Remove this code once it has a few days of air time. |
| 46 // the diagnostic-repair mode. | 46 if (error == SQLITE_INTERNAL || |
| 47 error == SQLITE_NOMEM || |
| 48 error == SQLITE_CORRUPT || |
| 49 error == SQLITE_IOERR || |
| 50 error == SQLITE_CONSTRAINT || |
| 51 error == SQLITE_NOTADB) |
| 52 CHECK(false) << "sqlite fatal error " << error; |
| 47 return error; | 53 return error; |
| 48 } | 54 } |
| 49 }; | 55 }; |
| 50 | 56 |
| 51 // The default error handler factory is also in charge of managing the | 57 // The default error handler factory is also in charge of managing the |
| 52 // lifetime of the error objects. This object is multi-thread safe. | 58 // lifetime of the error objects. This object is multi-thread safe. |
| 53 class DefaultSQLErrorHandlerFactory : public SQLErrorHandlerFactory { | 59 class DefaultSQLErrorHandlerFactory : public SQLErrorHandlerFactory { |
| 54 public: | 60 public: |
| 55 ~DefaultSQLErrorHandlerFactory() { | 61 ~DefaultSQLErrorHandlerFactory() { |
| 56 STLDeleteContainerPointers(errors_.begin(), errors_.end()); | 62 STLDeleteContainerPointers(errors_.begin(), errors_.end()); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 276 } |
| 271 began_ = false; | 277 began_ = false; |
| 272 return SQLITE_OK; | 278 return SQLITE_OK; |
| 273 } | 279 } |
| 274 } | 280 } |
| 275 | 281 |
| 276 int SQLStatement::prepare(sqlite3* db, const char* sql, int sql_len) { | 282 int SQLStatement::prepare(sqlite3* db, const char* sql, int sql_len) { |
| 277 DCHECK(!stmt_); | 283 DCHECK(!stmt_); |
| 278 int rv = sqlite3_prepare_v2(db, sql, sql_len, &stmt_, NULL); | 284 int rv = sqlite3_prepare_v2(db, sql, sql_len, &stmt_, NULL); |
| 279 if (rv != SQLITE_OK) { | 285 if (rv != SQLITE_OK) { |
| 280 DLOG(ERROR) << "SQLStatement.prepare_v2 failed: " << sqlite3_errmsg(db); | 286 SQLErrorHandler* error_handler = GetErrorHandlerFactory()->Make(); |
| 287 return error_handler->HandleError(rv, db_handle()); |
| 281 } | 288 } |
| 282 return rv; | 289 return rv; |
| 283 } | 290 } |
| 284 | 291 |
| 285 int SQLStatement::step() { | 292 int SQLStatement::step() { |
| 286 DCHECK(stmt_); | 293 DCHECK(stmt_); |
| 287 int status = sqlite3_step(stmt_); | 294 int status = sqlite3_step(stmt_); |
| 288 if ((status == SQLITE_ROW) || (status == SQLITE_DONE)) | 295 if ((status == SQLITE_ROW) || (status == SQLITE_DONE)) |
| 289 return status; | 296 return status; |
| 290 // We got a problem. | 297 // We got a problem. |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 return wstr; | 496 return wstr; |
| 490 } | 497 } |
| 491 | 498 |
| 492 #if defined(USE_SYSTEM_SQLITE) | 499 #if defined(USE_SYSTEM_SQLITE) |
| 493 // This function is a local change to sqlite3 which doesn't exist when one is | 500 // This function is a local change to sqlite3 which doesn't exist when one is |
| 494 // using the system sqlite library. Thus, we stub it out here. | 501 // using the system sqlite library. Thus, we stub it out here. |
| 495 int sqlite3Preload(sqlite3* db) { | 502 int sqlite3Preload(sqlite3* db) { |
| 496 return 0; | 503 return 0; |
| 497 } | 504 } |
| 498 #endif | 505 #endif |
| OLD | NEW |