Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: sql/connection.cc

Issue 1991503002: [sql] sql::ScopedErrorIgnorer rename to sql::test::ScopedErrorExpecter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sql/connection.h ('k') | sql/connection_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 #elif defined(OS_POSIX) 223 #elif defined(OS_POSIX)
224 return path.value(); 224 return path.value();
225 #endif 225 #endif
226 } 226 }
227 227
228 } // namespace 228 } // namespace
229 229
230 namespace sql { 230 namespace sql {
231 231
232 // static 232 // static
233 Connection::ErrorIgnorerCallback* Connection::current_ignorer_cb_ = NULL; 233 Connection::ErrorExpecterCallback* Connection::current_expecter_cb_ = NULL;
234 234
235 // static 235 // static
236 bool Connection::ShouldIgnoreSqliteError(int error) { 236 bool Connection::IsExpectedSqliteError(int error) {
237 if (!current_ignorer_cb_) 237 if (!current_expecter_cb_)
238 return false; 238 return false;
239 return current_ignorer_cb_->Run(error); 239 return current_expecter_cb_->Run(error);
240 } 240 }
241 241
242 void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) { 242 void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) {
243 AssertIOAllowed(); 243 AssertIOAllowed();
244 244
245 std::string debug_info; 245 std::string debug_info;
246 const int error = (extended_error & 0xFF); 246 const int error = (extended_error & 0xFF);
247 if (error == SQLITE_CORRUPT) { 247 if (error == SQLITE_CORRUPT) {
248 // CollectCorruptionInfo() is implemented in terms of sql::Connection, 248 // CollectCorruptionInfo() is implemented in terms of sql::Connection,
249 // prevent reentrant calls to the error callback. 249 // prevent reentrant calls to the error callback.
(...skipping 11 matching lines...) Expand all
261 if (!debug_info.empty() && RegisterIntentToUpload()) { 261 if (!debug_info.empty() && RegisterIntentToUpload()) {
262 char debug_buf[2000]; 262 char debug_buf[2000];
263 base::strlcpy(debug_buf, debug_info.c_str(), arraysize(debug_buf)); 263 base::strlcpy(debug_buf, debug_info.c_str(), arraysize(debug_buf));
264 base::debug::Alias(&debug_buf); 264 base::debug::Alias(&debug_buf);
265 265
266 base::debug::DumpWithoutCrashing(); 266 base::debug::DumpWithoutCrashing();
267 } 267 }
268 } 268 }
269 269
270 // static 270 // static
271 void Connection::SetErrorIgnorer(Connection::ErrorIgnorerCallback* cb) { 271 void Connection::SetErrorExpecter(Connection::ErrorExpecterCallback* cb) {
272 CHECK(current_ignorer_cb_ == NULL); 272 CHECK(current_expecter_cb_ == NULL);
273 current_ignorer_cb_ = cb; 273 current_expecter_cb_ = cb;
274 } 274 }
275 275
276 // static 276 // static
277 void Connection::ResetErrorIgnorer() { 277 void Connection::ResetErrorExpecter() {
278 CHECK(current_ignorer_cb_); 278 CHECK(current_expecter_cb_);
279 current_ignorer_cb_ = NULL; 279 current_expecter_cb_ = NULL;
280 } 280 }
281 281
282 bool StatementID::operator<(const StatementID& other) const { 282 bool StatementID::operator<(const StatementID& other) const {
283 if (number_ != other.number_) 283 if (number_ != other.number_)
284 return number_ < other.number_; 284 return number_ < other.number_;
285 return strcmp(str_, other.str_) < 0; 285 return strcmp(str_, other.str_) < 0;
286 } 286 }
287 287
288 Connection::StatementRef::StatementRef(Connection* connection, 288 Connection::StatementRef::StatementRef(Connection* connection,
289 sqlite3_stmt* stmt, 289 sqlite3_stmt* stmt,
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 bool Connection::DoesIndexExist(const char* index_name) const { 1522 bool Connection::DoesIndexExist(const char* index_name) const {
1523 return DoesTableOrIndexExist(index_name, "index"); 1523 return DoesTableOrIndexExist(index_name, "index");
1524 } 1524 }
1525 1525
1526 bool Connection::DoesTableOrIndexExist( 1526 bool Connection::DoesTableOrIndexExist(
1527 const char* name, const char* type) const { 1527 const char* name, const char* type) const {
1528 const char* kSql = 1528 const char* kSql =
1529 "SELECT name FROM sqlite_master WHERE type=? AND name=? COLLATE NOCASE"; 1529 "SELECT name FROM sqlite_master WHERE type=? AND name=? COLLATE NOCASE";
1530 Statement statement(GetUntrackedStatement(kSql)); 1530 Statement statement(GetUntrackedStatement(kSql));
1531 1531
1532 // This can happen if the database is corrupt and the error is being ignored 1532 // This can happen if the database is corrupt and the error is a test
1533 // for testing purposes. 1533 // expectation.
1534 if (!statement.is_valid()) 1534 if (!statement.is_valid())
1535 return false; 1535 return false;
1536 1536
1537 statement.BindString(0, type); 1537 statement.BindString(0, type);
1538 statement.BindString(1, name); 1538 statement.BindString(1, name);
1539 1539
1540 return statement.Step(); // Table exists if any row was returned. 1540 return statement.Step(); // Table exists if any row was returned.
1541 } 1541 }
1542 1542
1543 bool Connection::DoesColumnExist(const char* table_name, 1543 bool Connection::DoesColumnExist(const char* table_name,
1544 const char* column_name) const { 1544 const char* column_name) const {
1545 std::string sql("PRAGMA TABLE_INFO("); 1545 std::string sql("PRAGMA TABLE_INFO(");
1546 sql.append(table_name); 1546 sql.append(table_name);
1547 sql.append(")"); 1547 sql.append(")");
1548 1548
1549 Statement statement(GetUntrackedStatement(sql.c_str())); 1549 Statement statement(GetUntrackedStatement(sql.c_str()));
1550 1550
1551 // This can happen if the database is corrupt and the error is being ignored 1551 // This can happen if the database is corrupt and the error is a test
1552 // for testing purposes. 1552 // expectation.
1553 if (!statement.is_valid()) 1553 if (!statement.is_valid())
1554 return false; 1554 return false;
1555 1555
1556 while (statement.Step()) { 1556 while (statement.Step()) {
1557 if (base::EqualsCaseInsensitiveASCII(statement.ColumnString(1), 1557 if (base::EqualsCaseInsensitiveASCII(statement.ColumnString(1),
1558 column_name)) 1558 column_name))
1559 return true; 1559 return true;
1560 } 1560 }
1561 return false; 1561 return false;
1562 } 1562 }
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1895 1895
1896 if (!error_callback_.is_null()) { 1896 if (!error_callback_.is_null()) {
1897 // Fire from a copy of the callback in case of reentry into 1897 // Fire from a copy of the callback in case of reentry into
1898 // re/set_error_callback(). 1898 // re/set_error_callback().
1899 // TODO(shess): <http://crbug.com/254584> 1899 // TODO(shess): <http://crbug.com/254584>
1900 ErrorCallback(error_callback_).Run(err, stmt); 1900 ErrorCallback(error_callback_).Run(err, stmt);
1901 return err; 1901 return err;
1902 } 1902 }
1903 1903
1904 // The default handling is to assert on debug and to ignore on release. 1904 // The default handling is to assert on debug and to ignore on release.
1905 if (!ShouldIgnoreSqliteError(err)) 1905 if (!IsExpectedSqliteError(err))
1906 DLOG(FATAL) << GetErrorMessage(); 1906 DLOG(FATAL) << GetErrorMessage();
1907 return err; 1907 return err;
1908 } 1908 }
1909 1909
1910 bool Connection::FullIntegrityCheck(std::vector<std::string>* messages) { 1910 bool Connection::FullIntegrityCheck(std::vector<std::string>* messages) {
1911 return IntegrityCheckHelper("PRAGMA integrity_check", messages); 1911 return IntegrityCheckHelper("PRAGMA integrity_check", messages);
1912 } 1912 }
1913 1913
1914 bool Connection::QuickIntegrityCheck() { 1914 bool Connection::QuickIntegrityCheck() {
1915 std::vector<std::string> messages; 1915 std::vector<std::string> messages;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 ignore_result(Execute(kNoWritableSchema)); 1952 ignore_result(Execute(kNoWritableSchema));
1953 1953
1954 return ret; 1954 return ret;
1955 } 1955 }
1956 1956
1957 base::TimeTicks TimeSource::Now() { 1957 base::TimeTicks TimeSource::Now() {
1958 return base::TimeTicks::Now(); 1958 return base::TimeTicks::Now();
1959 } 1959 }
1960 1960
1961 } // namespace sql 1961 } // namespace sql
OLDNEW
« no previous file with comments | « sql/connection.h ('k') | sql/connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698