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 #include "sql/connection.h" | 5 #include "sql/connection.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } // namespace | 67 } // namespace |
68 | 68 |
69 namespace sql { | 69 namespace sql { |
70 | 70 |
71 bool StatementID::operator<(const StatementID& other) const { | 71 bool StatementID::operator<(const StatementID& other) const { |
72 if (number_ != other.number_) | 72 if (number_ != other.number_) |
73 return number_ < other.number_; | 73 return number_ < other.number_; |
74 return strcmp(str_, other.str_) < 0; | 74 return strcmp(str_, other.str_) < 0; |
75 } | 75 } |
76 | 76 |
77 ErrorDelegate::~ErrorDelegate() { | |
78 } | |
79 | |
80 Connection::StatementRef::StatementRef(Connection* connection, | 77 Connection::StatementRef::StatementRef(Connection* connection, |
81 sqlite3_stmt* stmt, | 78 sqlite3_stmt* stmt, |
82 bool was_valid) | 79 bool was_valid) |
83 : connection_(connection), | 80 : connection_(connection), |
84 stmt_(stmt), | 81 stmt_(stmt), |
85 was_valid_(was_valid) { | 82 was_valid_(was_valid) { |
86 if (connection) | 83 if (connection) |
87 connection_->StatementRefCreated(this); | 84 connection_->StatementRefCreated(this); |
88 } | 85 } |
89 | 86 |
(...skipping 25 matching lines...) Expand all Loading... |
115 } | 112 } |
116 | 113 |
117 Connection::Connection() | 114 Connection::Connection() |
118 : db_(NULL), | 115 : db_(NULL), |
119 page_size_(0), | 116 page_size_(0), |
120 cache_size_(0), | 117 cache_size_(0), |
121 exclusive_locking_(false), | 118 exclusive_locking_(false), |
122 transaction_nesting_(0), | 119 transaction_nesting_(0), |
123 needs_rollback_(false), | 120 needs_rollback_(false), |
124 in_memory_(false), | 121 in_memory_(false), |
125 poisoned_(false), | 122 poisoned_(false) { |
126 error_delegate_(NULL) { | |
127 } | 123 } |
128 | 124 |
129 Connection::~Connection() { | 125 Connection::~Connection() { |
130 Close(); | 126 Close(); |
131 } | 127 } |
132 | 128 |
133 bool Connection::Open(const base::FilePath& path) { | 129 bool Connection::Open(const base::FilePath& path) { |
134 if (!histogram_tag_.empty()) { | 130 if (!histogram_tag_.empty()) { |
135 int64 size_64 = 0; | 131 int64 size_64 = 0; |
136 if (file_util::GetFileSize(path, &size_64)) { | 132 if (file_util::GetFileSize(path, &size_64)) { |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 // Always log the error. | 753 // Always log the error. |
758 LOG(ERROR) << "sqlite error " << err | 754 LOG(ERROR) << "sqlite error " << err |
759 << ", errno " << GetLastErrno() | 755 << ", errno " << GetLastErrno() |
760 << ": " << GetErrorMessage(); | 756 << ": " << GetErrorMessage(); |
761 | 757 |
762 if (!error_callback_.is_null()) { | 758 if (!error_callback_.is_null()) { |
763 error_callback_.Run(err, stmt); | 759 error_callback_.Run(err, stmt); |
764 return err; | 760 return err; |
765 } | 761 } |
766 | 762 |
767 // TODO(shess): Remove |error_delegate_| once everything is | |
768 // converted to |error_callback_|. | |
769 if (error_delegate_.get()) | |
770 return error_delegate_->OnError(err, this, stmt); | |
771 | |
772 // The default handling is to assert on debug and to ignore on release. | 763 // The default handling is to assert on debug and to ignore on release. |
773 DLOG(FATAL) << GetErrorMessage(); | 764 DLOG(FATAL) << GetErrorMessage(); |
774 return err; | 765 return err; |
775 } | 766 } |
776 | 767 |
777 // TODO(shess): Allow specifying integrity_check versus quick_check. | 768 // TODO(shess): Allow specifying integrity_check versus quick_check. |
778 // TODO(shess): Allow specifying maximum results (default 100 lines). | 769 // TODO(shess): Allow specifying maximum results (default 100 lines). |
779 bool Connection::IntegrityCheck(std::vector<std::string>* messages) { | 770 bool Connection::IntegrityCheck(std::vector<std::string>* messages) { |
780 messages->clear(); | 771 messages->clear(); |
781 | 772 |
(...skipping 21 matching lines...) Expand all Loading... |
803 } | 794 } |
804 | 795 |
805 // Best effort to put things back as they were before. | 796 // Best effort to put things back as they were before. |
806 const char kNoWritableSchema[] = "PRAGMA writable_schema = OFF"; | 797 const char kNoWritableSchema[] = "PRAGMA writable_schema = OFF"; |
807 ignore_result(Execute(kNoWritableSchema)); | 798 ignore_result(Execute(kNoWritableSchema)); |
808 | 799 |
809 return ret; | 800 return ret; |
810 } | 801 } |
811 | 802 |
812 } // namespace sql | 803 } // namespace sql |
OLD | NEW |