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 #ifndef SQL_CONNECTION_H_ | 5 #ifndef SQL_CONNECTION_H_ |
6 #define SQL_CONNECTION_H_ | 6 #define SQL_CONNECTION_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/lazy_instance.h" |
16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
19 #include "base/time.h" | 20 #include "base/time.h" |
20 #include "sql/sql_export.h" | 21 #include "sql/sql_export.h" |
21 | 22 |
22 struct sqlite3; | 23 struct sqlite3; |
23 struct sqlite3_stmt; | 24 struct sqlite3_stmt; |
24 | 25 |
25 namespace base { | 26 namespace base { |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 370 |
370 // Returns the errno associated with GetErrorCode(). See | 371 // Returns the errno associated with GetErrorCode(). See |
371 // SQLITE_LAST_ERRNO in SQLite documentation. | 372 // SQLITE_LAST_ERRNO in SQLite documentation. |
372 int GetLastErrno() const; | 373 int GetLastErrno() const; |
373 | 374 |
374 // Returns a pointer to a statically allocated string associated with the | 375 // Returns a pointer to a statically allocated string associated with the |
375 // last sqlite operation. | 376 // last sqlite operation. |
376 const char* GetErrorMessage() const; | 377 const char* GetErrorMessage() const; |
377 | 378 |
378 private: | 379 private: |
| 380 // Allow test-support code to set/reset error ignorer. |
| 381 friend class ScopedErrorIgnorer; |
| 382 |
379 // Statement accesses StatementRef which we don't want to expose to everybody | 383 // Statement accesses StatementRef which we don't want to expose to everybody |
380 // (they should go through Statement). | 384 // (they should go through Statement). |
381 friend class Statement; | 385 friend class Statement; |
382 | 386 |
383 // Internal initialize function used by both Init and InitInMemory. The file | 387 // Internal initialize function used by both Init and InitInMemory. The file |
384 // name is always 8 bits since we want to use the 8-bit version of | 388 // name is always 8 bits since we want to use the 8-bit version of |
385 // sqlite3_open. The string can also be sqlite's special ":memory:" string. | 389 // sqlite3_open. The string can also be sqlite's special ":memory:" string. |
386 bool OpenInternal(const std::string& file_name); | 390 bool OpenInternal(const std::string& file_name); |
387 | 391 |
388 // Internal close function used by Close() and RazeAndClose(). | 392 // Internal close function used by Close() and RazeAndClose(). |
389 // |forced| indicates that orderly-shutdown checks should not apply. | 393 // |forced| indicates that orderly-shutdown checks should not apply. |
390 void CloseInternal(bool forced); | 394 void CloseInternal(bool forced); |
391 | 395 |
392 // Check whether the current thread is allowed to make IO calls, but only | 396 // Check whether the current thread is allowed to make IO calls, but only |
393 // if database wasn't open in memory. Function is inlined to be a no-op in | 397 // if database wasn't open in memory. Function is inlined to be a no-op in |
394 // official build. | 398 // official build. |
395 void AssertIOAllowed() { | 399 void AssertIOAllowed() { |
396 if (!in_memory_) | 400 if (!in_memory_) |
397 base::ThreadRestrictions::AssertIOAllowed(); | 401 base::ThreadRestrictions::AssertIOAllowed(); |
398 } | 402 } |
399 | 403 |
400 // Internal helper for DoesTableExist and DoesIndexExist. | 404 // Internal helper for DoesTableExist and DoesIndexExist. |
401 bool DoesTableOrIndexExist(const char* name, const char* type) const; | 405 bool DoesTableOrIndexExist(const char* name, const char* type) const; |
402 | 406 |
| 407 // Accessors for global error-ignorer, for injecting behavior during tests. |
| 408 // See test/scoped_error_ignorer.h. |
| 409 typedef base::Callback<bool(int)> ErrorIgnorerCallback; |
| 410 static base::LazyInstance<ErrorIgnorerCallback> current_ignorer_cb_; |
| 411 static bool ShouldIgnore(int error); |
| 412 static void SetErrorIgnorer(const ErrorIgnorerCallback& ignorer); |
| 413 static void ResetErrorIgnorer(); |
| 414 |
403 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. | 415 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. |
404 // Refcounting allows us to give these statements out to sql::Statement | 416 // Refcounting allows us to give these statements out to sql::Statement |
405 // objects while also optionally maintaining a cache of compiled statements | 417 // objects while also optionally maintaining a cache of compiled statements |
406 // by just keeping a refptr to these objects. | 418 // by just keeping a refptr to these objects. |
407 // | 419 // |
408 // A statement ref can be valid, in which case it can be used, or invalid to | 420 // A statement ref can be valid, in which case it can be used, or invalid to |
409 // indicate that the statement hasn't been created yet, has an error, or has | 421 // indicate that the statement hasn't been created yet, has an error, or has |
410 // been destroyed. | 422 // been destroyed. |
411 // | 423 // |
412 // The Connection may revoke a StatementRef in some error cases, so callers | 424 // The Connection may revoke a StatementRef in some error cases, so callers |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 | 547 |
536 // Tag for auxiliary histograms. | 548 // Tag for auxiliary histograms. |
537 std::string histogram_tag_; | 549 std::string histogram_tag_; |
538 | 550 |
539 DISALLOW_COPY_AND_ASSIGN(Connection); | 551 DISALLOW_COPY_AND_ASSIGN(Connection); |
540 }; | 552 }; |
541 | 553 |
542 } // namespace sql | 554 } // namespace sql |
543 | 555 |
544 #endif // SQL_CONNECTION_H_ | 556 #endif // SQL_CONNECTION_H_ |
OLD | NEW |