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/05/23 19:53:27
I'm having trouble understanding this comment. I
Scott Hess - ex-Googler
2016/06/03 00:02:11
This is the same concern you had elsewhere about d
| |
480 // tests. | 481 static bool IsExpectedSqliteError(int error); |
481 static bool ShouldIgnoreSqliteError(int error); | |
482 | 482 |
483 // Additionally ignores errors which are unlikely to be caused by problems | 483 // Return |true| in cases where Extend IsExpectedSqliteError() returns |true|, |
Mark P
2016/05/23 19:53:27
Extend?
Is this an errant word? If so, delete it.
Scott Hess - ex-Googler
2016/06/03 00:02:11
Done. Errant word.
| |
484 // with the syntax of a SQL statement, or problems with the database schema. | 484 // and also in cases which are likely to be caused by the state of the |
485 static bool ShouldIgnoreSqliteCompileError(int error); | 485 // database, rather than the statement being compiled. |
Mark P
2016/05/23 19:53:27
This comment is confusing. It's imply that this r
Scott Hess - ex-Googler
2016/06/03 00:02:11
I dug back into the history of this a bit. It loo
| |
486 static bool IsExpectedSqliteCompileError(int error); | |
486 | 487 |
487 // Collect various diagnostic information and post a crash dump to aid | 488 // Collect various diagnostic information and post a crash dump to aid |
488 // debugging. Dump rate per database is limited to prevent overwhelming the | 489 // debugging. Dump rate per database is limited to prevent overwhelming the |
489 // crash server. | 490 // crash server. |
490 void ReportDiagnosticInfo(int extended_error, Statement* stmt); | 491 void ReportDiagnosticInfo(int extended_error, Statement* stmt); |
491 | 492 |
492 private: | 493 private: |
493 // For recovery module. | 494 // For recovery module. |
494 friend class Recovery; | 495 friend class Recovery; |
495 | 496 |
496 // Allow test-support code to set/reset error ignorer. | 497 // Allow test-support code to set/reset error expecter. |
497 friend class ScopedErrorIgnorer; | 498 friend class test::ScopedErrorExpecter; |
498 | 499 |
499 // Statement accesses StatementRef which we don't want to expose to everybody | 500 // Statement accesses StatementRef which we don't want to expose to everybody |
500 // (they should go through Statement). | 501 // (they should go through Statement). |
501 friend class Statement; | 502 friend class Statement; |
502 | 503 |
503 friend class test::ScopedCommitHook; | 504 friend class test::ScopedCommitHook; |
504 friend class test::ScopedScalarFunction; | 505 friend class test::ScopedScalarFunction; |
505 friend class test::ScopedMockTimeSource; | 506 friend class test::ScopedMockTimeSource; |
506 | 507 |
507 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, CollectDiagnosticInfo); | 508 FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, CollectDiagnosticInfo); |
(...skipping 21 matching lines...) Expand all Loading... | |
529 // if database wasn't open in memory. Function is inlined to be a no-op in | 530 // if database wasn't open in memory. Function is inlined to be a no-op in |
530 // official build. | 531 // official build. |
531 void AssertIOAllowed() const { | 532 void AssertIOAllowed() const { |
532 if (!in_memory_) | 533 if (!in_memory_) |
533 base::ThreadRestrictions::AssertIOAllowed(); | 534 base::ThreadRestrictions::AssertIOAllowed(); |
534 } | 535 } |
535 | 536 |
536 // Internal helper for DoesTableExist and DoesIndexExist. | 537 // Internal helper for DoesTableExist and DoesIndexExist. |
537 bool DoesTableOrIndexExist(const char* name, const char* type) const; | 538 bool DoesTableOrIndexExist(const char* name, const char* type) const; |
538 | 539 |
539 // Accessors for global error-ignorer, for injecting behavior during tests. | 540 // Accessors for global error-expecter, for injecting behavior during tests. |
540 // See test/scoped_error_ignorer.h. | 541 // See test/scoped_error_expecter.h. |
541 typedef base::Callback<bool(int)> ErrorIgnorerCallback; | 542 typedef base::Callback<bool(int)> ErrorExpecterCallback; |
542 static ErrorIgnorerCallback* current_ignorer_cb_; | 543 static ErrorExpecterCallback* current_expecter_cb_; |
543 static void SetErrorIgnorer(ErrorIgnorerCallback* ignorer); | 544 static void SetErrorExpecter(ErrorExpecterCallback* expecter); |
544 static void ResetErrorIgnorer(); | 545 static void ResetErrorExpecter(); |
545 | 546 |
546 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. | 547 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. |
547 // Refcounting allows us to give these statements out to sql::Statement | 548 // Refcounting allows us to give these statements out to sql::Statement |
548 // objects while also optionally maintaining a cache of compiled statements | 549 // objects while also optionally maintaining a cache of compiled statements |
549 // by just keeping a refptr to these objects. | 550 // by just keeping a refptr to these objects. |
550 // | 551 // |
551 // A statement ref can be valid, in which case it can be used, or invalid to | 552 // A statement ref can be valid, in which case it can be used, or invalid to |
552 // indicate that the statement hasn't been created yet, has an error, or has | 553 // indicate that the statement hasn't been created yet, has an error, or has |
553 // been destroyed. | 554 // been destroyed. |
554 // | 555 // |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 | 794 |
794 // Stores the dump provider object when db is open. | 795 // Stores the dump provider object when db is open. |
795 std::unique_ptr<ConnectionMemoryDumpProvider> memory_dump_provider_; | 796 std::unique_ptr<ConnectionMemoryDumpProvider> memory_dump_provider_; |
796 | 797 |
797 DISALLOW_COPY_AND_ASSIGN(Connection); | 798 DISALLOW_COPY_AND_ASSIGN(Connection); |
798 }; | 799 }; |
799 | 800 |
800 } // namespace sql | 801 } // namespace sql |
801 | 802 |
802 #endif // SQL_CONNECTION_H_ | 803 #endif // SQL_CONNECTION_H_ |
OLD | NEW |