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 // Clients which provide an error_callback don't see the error-handling at the |
478 // error-handling at the end of OnSqliteError(). Expose to allow | 479 // end of OnSqliteError(). Expose to allow those clients to work for tests |
479 // those clients to work appropriately with ScopedErrorIgnorer in | 480 // using ScopedErrorExpecter. |true| if the error is expected. |
Mark P
2016/06/15 04:39:44
I still don't like this comment. I'd prefer somet
Scott Hess - ex-Googler
2016/06/21 00:18:26
Done.
| |
480 // tests. | 481 static bool IsExpectedSqliteError(int error); |
481 static bool ShouldIgnoreSqliteError(int error); | |
482 | 482 |
483 // Collect various diagnostic information and post a crash dump to aid | 483 // Collect various diagnostic information and post a crash dump to aid |
484 // debugging. Dump rate per database is limited to prevent overwhelming the | 484 // debugging. Dump rate per database is limited to prevent overwhelming the |
485 // crash server. | 485 // crash server. |
486 void ReportDiagnosticInfo(int extended_error, Statement* stmt); | 486 void ReportDiagnosticInfo(int extended_error, Statement* stmt); |
487 | 487 |
488 private: | 488 private: |
489 // For recovery module. | 489 // For recovery module. |
490 friend class Recovery; | 490 friend class Recovery; |
491 | 491 |
492 // Allow test-support code to set/reset error ignorer. | 492 // Allow test-support code to set/reset error expecter. |
493 friend class ScopedErrorIgnorer; | 493 friend class test::ScopedErrorExpecter; |
494 | 494 |
495 // Statement accesses StatementRef which we don't want to expose to everybody | 495 // Statement accesses StatementRef which we don't want to expose to everybody |
496 // (they should go through Statement). | 496 // (they should go through Statement). |
497 friend class Statement; | 497 friend class Statement; |
498 | 498 |
499 friend class test::ScopedCommitHook; | 499 friend class test::ScopedCommitHook; |
500 friend class test::ScopedScalarFunction; | 500 friend class test::ScopedScalarFunction; |
501 friend class test::ScopedMockTimeSource; | 501 friend class test::ScopedMockTimeSource; |
502 | 502 |
503 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, CollectDiagnosticInfo); | 503 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 | 525 // if database wasn't open in memory. Function is inlined to be a no-op in |
526 // official build. | 526 // official build. |
527 void AssertIOAllowed() const { | 527 void AssertIOAllowed() const { |
528 if (!in_memory_) | 528 if (!in_memory_) |
529 base::ThreadRestrictions::AssertIOAllowed(); | 529 base::ThreadRestrictions::AssertIOAllowed(); |
530 } | 530 } |
531 | 531 |
532 // Internal helper for DoesTableExist and DoesIndexExist. | 532 // Internal helper for DoesTableExist and DoesIndexExist. |
533 bool DoesTableOrIndexExist(const char* name, const char* type) const; | 533 bool DoesTableOrIndexExist(const char* name, const char* type) const; |
534 | 534 |
535 // Accessors for global error-ignorer, for injecting behavior during tests. | 535 // Accessors for global error-expecter, for injecting behavior during tests. |
536 // See test/scoped_error_ignorer.h. | 536 // See test/scoped_error_expecter.h. |
537 typedef base::Callback<bool(int)> ErrorIgnorerCallback; | 537 typedef base::Callback<bool(int)> ErrorExpecterCallback; |
538 static ErrorIgnorerCallback* current_ignorer_cb_; | 538 static ErrorExpecterCallback* current_expecter_cb_; |
539 static void SetErrorIgnorer(ErrorIgnorerCallback* ignorer); | 539 static void SetErrorExpecter(ErrorExpecterCallback* expecter); |
540 static void ResetErrorIgnorer(); | 540 static void ResetErrorExpecter(); |
541 | 541 |
542 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. | 542 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. |
543 // Refcounting allows us to give these statements out to sql::Statement | 543 // Refcounting allows us to give these statements out to sql::Statement |
544 // objects while also optionally maintaining a cache of compiled statements | 544 // objects while also optionally maintaining a cache of compiled statements |
545 // by just keeping a refptr to these objects. | 545 // by just keeping a refptr to these objects. |
546 // | 546 // |
547 // A statement ref can be valid, in which case it can be used, or invalid to | 547 // 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 | 548 // indicate that the statement hasn't been created yet, has an error, or has |
549 // been destroyed. | 549 // been destroyed. |
550 // | 550 // |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 | 795 |
796 // Stores the dump provider object when db is open. | 796 // Stores the dump provider object when db is open. |
797 std::unique_ptr<ConnectionMemoryDumpProvider> memory_dump_provider_; | 797 std::unique_ptr<ConnectionMemoryDumpProvider> memory_dump_provider_; |
798 | 798 |
799 DISALLOW_COPY_AND_ASSIGN(Connection); | 799 DISALLOW_COPY_AND_ASSIGN(Connection); |
800 }; | 800 }; |
801 | 801 |
802 } // namespace sql | 802 } // namespace sql |
803 | 803 |
804 #endif // SQL_CONNECTION_H_ | 804 #endif // SQL_CONNECTION_H_ |
OLD | NEW |