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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <map> | 10 #include <map> |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 namespace sql { | 33 namespace sql { |
34 | 34 |
35 class ConnectionMemoryDumpProvider; | 35 class ConnectionMemoryDumpProvider; |
36 class Recovery; | 36 class Recovery; |
37 class Statement; | 37 class Statement; |
38 | 38 |
39 // To allow some test classes to be friended. | 39 // To allow some test classes to be friended. |
40 namespace test { | 40 namespace test { |
41 class ScopedCommitHook; | 41 class ScopedCommitHook; |
| 42 class ScopedErrorExpecter; |
42 class ScopedScalarFunction; | 43 class ScopedScalarFunction; |
43 class ScopedMockTimeSource; | 44 class ScopedMockTimeSource; |
44 } | 45 } |
45 | 46 |
46 // Uniquely identifies a statement. There are two modes of operation: | 47 // Uniquely identifies a statement. There are two modes of operation: |
47 // | 48 // |
48 // - In the most common mode, you will use the source file and line number to | 49 // - In the most common mode, you will use the source file and line number to |
49 // identify your statement. This is a convienient way to get uniqueness for | 50 // identify your statement. This is a convienient way to get uniqueness for |
50 // a statement that is only used in one place. Use the SQL_FROM_HERE macro | 51 // a statement that is only used in one place. Use the SQL_FROM_HERE macro |
51 // to generate a StatementID. | 52 // to generate a StatementID. |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 468 |
468 // Returns a pointer to a statically allocated string associated with the | 469 // Returns a pointer to a statically allocated string associated with the |
469 // last sqlite operation. | 470 // last sqlite operation. |
470 const char* GetErrorMessage() const; | 471 const char* GetErrorMessage() const; |
471 | 472 |
472 // Return a reproducible representation of the schema equivalent to | 473 // Return a reproducible representation of the schema equivalent to |
473 // running the following statement at a sqlite3 command-line: | 474 // running the following statement at a sqlite3 command-line: |
474 // SELECT type, name, tbl_name, sql FROM sqlite_master ORDER BY 1, 2, 3, 4; | 475 // SELECT type, name, tbl_name, sql FROM sqlite_master ORDER BY 1, 2, 3, 4; |
475 std::string GetSchema() const; | 476 std::string GetSchema() const; |
476 | 477 |
477 // Clients which provide an error_callback don't see the | 478 // Returns |true| if there is an error expecter (see SetErrorExpecter), and |
478 // error-handling at the end of OnSqliteError(). Expose to allow | 479 // that expecter returns |true| when passed |error|. Clients which provide an |
479 // those clients to work appropriately with ScopedErrorIgnorer in | 480 // |error_callback| should use IsExpectedSqliteError() to check for unexpected |
480 // tests. | 481 // errors; if one is detected, DLOG(FATAL) is generally appropriate (see |
481 static bool ShouldIgnoreSqliteError(int error); | 482 // OnSqliteError implementation). |
| 483 static bool IsExpectedSqliteError(int error); |
482 | 484 |
483 // Collect various diagnostic information and post a crash dump to aid | 485 // Collect various diagnostic information and post a crash dump to aid |
484 // debugging. Dump rate per database is limited to prevent overwhelming the | 486 // debugging. Dump rate per database is limited to prevent overwhelming the |
485 // crash server. | 487 // crash server. |
486 void ReportDiagnosticInfo(int extended_error, Statement* stmt); | 488 void ReportDiagnosticInfo(int extended_error, Statement* stmt); |
487 | 489 |
488 private: | 490 private: |
489 // For recovery module. | 491 // For recovery module. |
490 friend class Recovery; | 492 friend class Recovery; |
491 | 493 |
492 // Allow test-support code to set/reset error ignorer. | 494 // Allow test-support code to set/reset error expecter. |
493 friend class ScopedErrorIgnorer; | 495 friend class test::ScopedErrorExpecter; |
494 | 496 |
495 // Statement accesses StatementRef which we don't want to expose to everybody | 497 // Statement accesses StatementRef which we don't want to expose to everybody |
496 // (they should go through Statement). | 498 // (they should go through Statement). |
497 friend class Statement; | 499 friend class Statement; |
498 | 500 |
499 friend class test::ScopedCommitHook; | 501 friend class test::ScopedCommitHook; |
500 friend class test::ScopedScalarFunction; | 502 friend class test::ScopedScalarFunction; |
501 friend class test::ScopedMockTimeSource; | 503 friend class test::ScopedMockTimeSource; |
502 | 504 |
503 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, CollectDiagnosticInfo); | 505 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, CollectDiagnosticInfo); |
(...skipping 21 matching lines...) Expand all Loading... |
525 // if database wasn't open in memory. Function is inlined to be a no-op in | 527 // if database wasn't open in memory. Function is inlined to be a no-op in |
526 // official build. | 528 // official build. |
527 void AssertIOAllowed() const { | 529 void AssertIOAllowed() const { |
528 if (!in_memory_) | 530 if (!in_memory_) |
529 base::ThreadRestrictions::AssertIOAllowed(); | 531 base::ThreadRestrictions::AssertIOAllowed(); |
530 } | 532 } |
531 | 533 |
532 // Internal helper for DoesTableExist and DoesIndexExist. | 534 // Internal helper for DoesTableExist and DoesIndexExist. |
533 bool DoesTableOrIndexExist(const char* name, const char* type) const; | 535 bool DoesTableOrIndexExist(const char* name, const char* type) const; |
534 | 536 |
535 // Accessors for global error-ignorer, for injecting behavior during tests. | 537 // Accessors for global error-expecter, for injecting behavior during tests. |
536 // See test/scoped_error_ignorer.h. | 538 // See test/scoped_error_expecter.h. |
537 typedef base::Callback<bool(int)> ErrorIgnorerCallback; | 539 typedef base::Callback<bool(int)> ErrorExpecterCallback; |
538 static ErrorIgnorerCallback* current_ignorer_cb_; | 540 static ErrorExpecterCallback* current_expecter_cb_; |
539 static void SetErrorIgnorer(ErrorIgnorerCallback* ignorer); | 541 static void SetErrorExpecter(ErrorExpecterCallback* expecter); |
540 static void ResetErrorIgnorer(); | 542 static void ResetErrorExpecter(); |
541 | 543 |
542 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. | 544 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. |
543 // Refcounting allows us to give these statements out to sql::Statement | 545 // Refcounting allows us to give these statements out to sql::Statement |
544 // objects while also optionally maintaining a cache of compiled statements | 546 // objects while also optionally maintaining a cache of compiled statements |
545 // by just keeping a refptr to these objects. | 547 // by just keeping a refptr to these objects. |
546 // | 548 // |
547 // A statement ref can be valid, in which case it can be used, or invalid to | 549 // A statement ref can be valid, in which case it can be used, or invalid to |
548 // indicate that the statement hasn't been created yet, has an error, or has | 550 // indicate that the statement hasn't been created yet, has an error, or has |
549 // been destroyed. | 551 // been destroyed. |
550 // | 552 // |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 | 797 |
796 // Stores the dump provider object when db is open. | 798 // Stores the dump provider object when db is open. |
797 std::unique_ptr<ConnectionMemoryDumpProvider> memory_dump_provider_; | 799 std::unique_ptr<ConnectionMemoryDumpProvider> memory_dump_provider_; |
798 | 800 |
799 DISALLOW_COPY_AND_ASSIGN(Connection); | 801 DISALLOW_COPY_AND_ASSIGN(Connection); |
800 }; | 802 }; |
801 | 803 |
802 } // namespace sql | 804 } // namespace sql |
803 | 805 |
804 #endif // SQL_CONNECTION_H_ | 806 #endif // SQL_CONNECTION_H_ |
OLD | NEW |