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

Side by Side Diff: sql/connection.cc

Issue 1434173003: [sql] Differentiate compile errors from regular errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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') | no next file » | 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 <string.h> 7 #include <string.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/dump_without_crashing.h" 10 #include "base/debug/dump_without_crashing.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // static 225 // static
226 Connection::ErrorIgnorerCallback* Connection::current_ignorer_cb_ = NULL; 226 Connection::ErrorIgnorerCallback* Connection::current_ignorer_cb_ = NULL;
227 227
228 // static 228 // static
229 bool Connection::ShouldIgnoreSqliteError(int error) { 229 bool Connection::ShouldIgnoreSqliteError(int error) {
230 if (!current_ignorer_cb_) 230 if (!current_ignorer_cb_)
231 return false; 231 return false;
232 return current_ignorer_cb_->Run(error); 232 return current_ignorer_cb_->Run(error);
233 } 233 }
234 234
235 // static
236 bool Connection::ShouldIgnoreSqliteCompileError(int error) {
237 // Put this first in case tests need to see that the check happened.
238 if (ShouldIgnoreSqliteError(error))
239 return true;
240
241 // Trim extended error codes.
242 int basic_error = error & 0xff;
243
244 // These errors relate more to the runtime context of the system than to
245 // errors with a SQL statement or with the schema, so they aren't generally
246 // interesting to flag. This list is not comprehensive.
247 return basic_error == SQLITE_BUSY ||
248 basic_error == SQLITE_NOTADB ||
249 basic_error == SQLITE_CORRUPT;
250 }
251
235 bool Connection::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 252 bool Connection::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
236 base::trace_event::ProcessMemoryDump* pmd) { 253 base::trace_event::ProcessMemoryDump* pmd) {
237 if (args.level_of_detail == 254 if (args.level_of_detail ==
238 base::trace_event::MemoryDumpLevelOfDetail::LIGHT || 255 base::trace_event::MemoryDumpLevelOfDetail::LIGHT ||
239 !db_) { 256 !db_) {
240 return true; 257 return true;
241 } 258 }
242 259
243 // The high water mark is not tracked for the following usages. 260 // The high water mark is not tracked for the following usages.
244 int cache_size, dummy_int; 261 int cache_size, dummy_int;
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 AssertIOAllowed(); 1349 AssertIOAllowed();
1333 1350
1334 // Return inactive statement. 1351 // Return inactive statement.
1335 if (!db_) 1352 if (!db_)
1336 return new StatementRef(NULL, NULL, poisoned_); 1353 return new StatementRef(NULL, NULL, poisoned_);
1337 1354
1338 sqlite3_stmt* stmt = NULL; 1355 sqlite3_stmt* stmt = NULL;
1339 int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, NULL); 1356 int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, NULL);
1340 if (rc != SQLITE_OK) { 1357 if (rc != SQLITE_OK) {
1341 // This is evidence of a syntax error in the incoming SQL. 1358 // This is evidence of a syntax error in the incoming SQL.
1342 if (!ShouldIgnoreSqliteError(rc)) 1359 if (!ShouldIgnoreSqliteCompileError(rc))
1343 DLOG(FATAL) << "SQL compile error " << GetErrorMessage(); 1360 DLOG(FATAL) << "SQL compile error " << GetErrorMessage();
1344 1361
1345 // It could also be database corruption. 1362 // It could also be database corruption.
1346 OnSqliteError(rc, NULL, sql); 1363 OnSqliteError(rc, NULL, sql);
1347 return new StatementRef(NULL, NULL, false); 1364 return new StatementRef(NULL, NULL, false);
1348 } 1365 }
1349 return new StatementRef(this, stmt, true); 1366 return new StatementRef(this, stmt, true);
1350 } 1367 }
1351 1368
1369 // TODO(shess): Unify this with GetUniqueStatement(). The only difference that
1370 // seems legitimate is not passing |this| to StatementRef.
1352 scoped_refptr<Connection::StatementRef> Connection::GetUntrackedStatement( 1371 scoped_refptr<Connection::StatementRef> Connection::GetUntrackedStatement(
1353 const char* sql) const { 1372 const char* sql) const {
1354 // Return inactive statement. 1373 // Return inactive statement.
1355 if (!db_) 1374 if (!db_)
1356 return new StatementRef(NULL, NULL, poisoned_); 1375 return new StatementRef(NULL, NULL, poisoned_);
1357 1376
1358 sqlite3_stmt* stmt = NULL; 1377 sqlite3_stmt* stmt = NULL;
1359 int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, NULL); 1378 int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, NULL);
1360 if (rc != SQLITE_OK) { 1379 if (rc != SQLITE_OK) {
1361 // This is evidence of a syntax error in the incoming SQL. 1380 // This is evidence of a syntax error in the incoming SQL.
1362 if (!ShouldIgnoreSqliteError(rc)) 1381 if (!ShouldIgnoreSqliteCompileError(rc))
1363 DLOG(FATAL) << "SQL compile error " << GetErrorMessage(); 1382 DLOG(FATAL) << "SQL compile error " << GetErrorMessage();
1364 return new StatementRef(NULL, NULL, false); 1383 return new StatementRef(NULL, NULL, false);
1365 } 1384 }
1366 return new StatementRef(NULL, stmt, true); 1385 return new StatementRef(NULL, stmt, true);
1367 } 1386 }
1368 1387
1369 std::string Connection::GetSchema() const { 1388 std::string Connection::GetSchema() const {
1370 // The ORDER BY should not be necessary, but relying on organic 1389 // The ORDER BY should not be necessary, but relying on organic
1371 // order for something like this is questionable. 1390 // order for something like this is questionable.
1372 const char* kSql = 1391 const char* kSql =
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 1778
1760 int Connection::OnSqliteError(int err, sql::Statement *stmt, const char* sql) { 1779 int Connection::OnSqliteError(int err, sql::Statement *stmt, const char* sql) {
1761 UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.Error", err); 1780 UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.Error", err);
1762 AddTaggedHistogram("Sqlite.Error", err); 1781 AddTaggedHistogram("Sqlite.Error", err);
1763 1782
1764 // Always log the error. 1783 // Always log the error.
1765 if (!sql && stmt) 1784 if (!sql && stmt)
1766 sql = stmt->GetSQLStatement(); 1785 sql = stmt->GetSQLStatement();
1767 if (!sql) 1786 if (!sql)
1768 sql = "-- unknown"; 1787 sql = "-- unknown";
1769 LOG(ERROR) << histogram_tag_ << " sqlite error " << err 1788
1789 std::string id = histogram_tag_;
1790 if (id.empty())
1791 id = DbPath().BaseName().AsUTF8Unsafe();
1792 LOG(ERROR) << id << " sqlite error " << err
1770 << ", errno " << GetLastErrno() 1793 << ", errno " << GetLastErrno()
1771 << ": " << GetErrorMessage() 1794 << ": " << GetErrorMessage()
1772 << ", sql: " << sql; 1795 << ", sql: " << sql;
1773 1796
1774 if (!error_callback_.is_null()) { 1797 if (!error_callback_.is_null()) {
1775 // Fire from a copy of the callback in case of reentry into 1798 // Fire from a copy of the callback in case of reentry into
1776 // re/set_error_callback(). 1799 // re/set_error_callback().
1777 // TODO(shess): <http://crbug.com/254584> 1800 // TODO(shess): <http://crbug.com/254584>
1778 ErrorCallback(error_callback_).Run(err, stmt); 1801 ErrorCallback(error_callback_).Run(err, stmt);
1779 return err; 1802 return err;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 ignore_result(Execute(kNoWritableSchema)); 1853 ignore_result(Execute(kNoWritableSchema));
1831 1854
1832 return ret; 1855 return ret;
1833 } 1856 }
1834 1857
1835 base::TimeTicks TimeSource::Now() { 1858 base::TimeTicks TimeSource::Now() {
1836 return base::TimeTicks::Now(); 1859 return base::TimeTicks::Now();
1837 } 1860 }
1838 1861
1839 } // namespace sql 1862 } // namespace sql
OLDNEW
« no previous file with comments | « sql/connection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698