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> |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 // This object handles errors resulting from all forms of executing sqlite | 532 // This object handles errors resulting from all forms of executing sqlite |
533 // commands or statements. It can be null which means default handling. | 533 // commands or statements. It can be null which means default handling. |
534 scoped_ptr<ErrorDelegate> error_delegate_; | 534 scoped_ptr<ErrorDelegate> error_delegate_; |
535 | 535 |
536 // Tag for auxiliary histograms. | 536 // Tag for auxiliary histograms. |
537 std::string histogram_tag_; | 537 std::string histogram_tag_; |
538 | 538 |
539 DISALLOW_COPY_AND_ASSIGN(Connection); | 539 DISALLOW_COPY_AND_ASSIGN(Connection); |
540 }; | 540 }; |
541 | 541 |
542 // Most errors are fatal in debug mode, because usually they indicate | |
543 // an inappropriate use of SQL. This makes it challenging to write | |
544 // tests for things like recovery from corruption. Use this scoper to | |
545 // ignore errors during the current test. This applies globally (to | |
546 // all connections). The scoper can be nested, but is not thread-safe. | |
547 // | |
548 // Specific errors must be ignores, and all ignored errors must be | |
erikwright (departed)
2013/06/11 18:54:19
Grammar problems to the point that I don't know wh
| |
549 // seen. | |
550 // | |
551 // TODO(shess): Wire things up so this can only be used from tests. | |
552 // NOTE(shess): This does not comprehensively suppress errors at this | |
553 // time. If your test is handling database errors and you're hitting | |
554 // a case not handled, contact me. | |
555 // NOTE(shess): If you use this in production code, I will revert you. | |
556 class SQL_EXPORT ScopedErrorIgnorer { | |
erikwright (departed)
2013/06/11 18:54:19
I'd have to scan sql/ to see what the local conven
| |
557 public: | |
558 ScopedErrorIgnorer(); | |
559 ~ScopedErrorIgnorer(); | |
560 | |
561 // Add an error to ignore. Extended error codes can be ignored | |
562 // specifically, or the base can be ignored as a group | |
563 // (SQLITE_IOERR_* versus SQLITE_IOERR). | |
564 void IgnoreError(int err); | |
565 | |
566 // Allow containing test to check if the errors were encountered. | |
567 // Test is REQUIRED to call this before destruction. | |
568 // TODO(shess): How to handle ASSERT_X() cases which cause early | |
569 // return in tests? | |
570 bool CheckIgnoredErrors(); | |
571 | |
572 // Check if the error should be ignored. | |
573 static bool ShouldIgnoreError(int err); | |
574 | |
575 private: | |
576 // Record whether CheckIgnoredErrors() has been called. | |
577 bool checked_; | |
578 | |
579 // Errors to ignore. | |
580 std::set<int> ignore_errors_; | |
581 | |
582 // Errors which have been ignored. | |
583 std::set<int> errors_ignored_; | |
584 | |
585 ScopedErrorIgnorer* next_; | |
586 | |
587 DISALLOW_COPY_AND_ASSIGN(ScopedErrorIgnorer); | |
588 }; | |
589 | |
542 } // namespace sql | 590 } // namespace sql |
543 | 591 |
544 #endif // SQL_CONNECTION_H_ | 592 #endif // SQL_CONNECTION_H_ |
OLD | NEW |