| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "sql/connection.h" | 5 #include "sql/connection.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "third_party/sqlite/src/ext/icu/sqliteicu.h" | 36 #include "third_party/sqlite/src/ext/icu/sqliteicu.h" |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 // Spin for up to a second waiting for the lock to clear when setting | 41 // Spin for up to a second waiting for the lock to clear when setting |
| 42 // up the database. | 42 // up the database. |
| 43 // TODO(shess): Better story on this. http://crbug.com/56559 | 43 // TODO(shess): Better story on this. http://crbug.com/56559 |
| 44 const int kBusyTimeoutSeconds = 1; | 44 const int kBusyTimeoutSeconds = 1; |
| 45 | 45 |
| 46 bool g_mmap_disabled_default = false; |
| 47 |
| 46 class ScopedBusyTimeout { | 48 class ScopedBusyTimeout { |
| 47 public: | 49 public: |
| 48 explicit ScopedBusyTimeout(sqlite3* db) | 50 explicit ScopedBusyTimeout(sqlite3* db) |
| 49 : db_(db) { | 51 : db_(db) { |
| 50 } | 52 } |
| 51 ~ScopedBusyTimeout() { | 53 ~ScopedBusyTimeout() { |
| 52 sqlite3_busy_timeout(db_, 0); | 54 sqlite3_busy_timeout(db_, 0); |
| 53 } | 55 } |
| 54 | 56 |
| 55 int SetTimeout(base::TimeDelta timeout) { | 57 int SetTimeout(base::TimeDelta timeout) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 int basic_error = error & 0xff; | 249 int basic_error = error & 0xff; |
| 248 | 250 |
| 249 // These errors relate more to the runtime context of the system than to | 251 // These errors relate more to the runtime context of the system than to |
| 250 // errors with a SQL statement or with the schema, so they aren't generally | 252 // errors with a SQL statement or with the schema, so they aren't generally |
| 251 // interesting to flag. This list is not comprehensive. | 253 // interesting to flag. This list is not comprehensive. |
| 252 return basic_error == SQLITE_BUSY || | 254 return basic_error == SQLITE_BUSY || |
| 253 basic_error == SQLITE_NOTADB || | 255 basic_error == SQLITE_NOTADB || |
| 254 basic_error == SQLITE_CORRUPT; | 256 basic_error == SQLITE_CORRUPT; |
| 255 } | 257 } |
| 256 | 258 |
| 259 // static |
| 260 void Connection::set_mmap_disabled_by_default() { |
| 261 g_mmap_disabled_default = true; |
| 262 } |
| 263 |
| 264 |
| 257 void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) { | 265 void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) { |
| 258 AssertIOAllowed(); | 266 AssertIOAllowed(); |
| 259 | 267 |
| 260 std::string debug_info; | 268 std::string debug_info; |
| 261 const int error = (extended_error & 0xFF); | 269 const int error = (extended_error & 0xFF); |
| 262 if (error == SQLITE_CORRUPT) { | 270 if (error == SQLITE_CORRUPT) { |
| 263 debug_info = CollectCorruptionInfo(); | 271 debug_info = CollectCorruptionInfo(); |
| 264 } else { | 272 } else { |
| 265 debug_info = CollectErrorInfo(extended_error, stmt); | 273 debug_info = CollectErrorInfo(extended_error, stmt); |
| 266 } | 274 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 Connection::Connection() | 340 Connection::Connection() |
| 333 : db_(NULL), | 341 : db_(NULL), |
| 334 page_size_(0), | 342 page_size_(0), |
| 335 cache_size_(0), | 343 cache_size_(0), |
| 336 exclusive_locking_(false), | 344 exclusive_locking_(false), |
| 337 restrict_to_user_(false), | 345 restrict_to_user_(false), |
| 338 transaction_nesting_(0), | 346 transaction_nesting_(0), |
| 339 needs_rollback_(false), | 347 needs_rollback_(false), |
| 340 in_memory_(false), | 348 in_memory_(false), |
| 341 poisoned_(false), | 349 poisoned_(false), |
| 342 mmap_disabled_(false), | 350 mmap_disabled_(g_mmap_disabled_default), |
| 343 mmap_enabled_(false), | 351 mmap_enabled_(false), |
| 344 total_changes_at_last_release_(0), | 352 total_changes_at_last_release_(0), |
| 345 stats_histogram_(NULL), | 353 stats_histogram_(NULL), |
| 346 commit_time_histogram_(NULL), | 354 commit_time_histogram_(NULL), |
| 347 autocommit_time_histogram_(NULL), | 355 autocommit_time_histogram_(NULL), |
| 348 update_time_histogram_(NULL), | 356 update_time_histogram_(NULL), |
| 349 query_time_histogram_(NULL), | 357 query_time_histogram_(NULL), |
| 350 clock_(new TimeSource()) { | 358 clock_(new TimeSource()) { |
| 351 } | 359 } |
| 352 | 360 |
| (...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1959 ignore_result(Execute(kNoWritableSchema)); | 1967 ignore_result(Execute(kNoWritableSchema)); |
| 1960 | 1968 |
| 1961 return ret; | 1969 return ret; |
| 1962 } | 1970 } |
| 1963 | 1971 |
| 1964 base::TimeTicks TimeSource::Now() { | 1972 base::TimeTicks TimeSource::Now() { |
| 1965 return base::TimeTicks::Now(); | 1973 return base::TimeTicks::Now(); |
| 1966 } | 1974 } |
| 1967 | 1975 |
| 1968 } // namespace sql | 1976 } // namespace sql |
| OLD | NEW |