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

Side by Side Diff: sql/connection.cc

Issue 104593010: AppCache: Run a quick integrity check on the sqlite database when opening. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
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/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 ErrorCallback(error_callback_).Run(err, stmt); 1043 ErrorCallback(error_callback_).Run(err, stmt);
1044 return err; 1044 return err;
1045 } 1045 }
1046 1046
1047 // The default handling is to assert on debug and to ignore on release. 1047 // The default handling is to assert on debug and to ignore on release.
1048 if (!ShouldIgnoreSqliteError(err)) 1048 if (!ShouldIgnoreSqliteError(err))
1049 DLOG(FATAL) << GetErrorMessage(); 1049 DLOG(FATAL) << GetErrorMessage();
1050 return err; 1050 return err;
1051 } 1051 }
1052 1052
1053 // TODO(shess): Allow specifying integrity_check versus quick_check. 1053 bool Connection::FullIntegrityCheck(std::vector<std::string>* messages) {
1054 return IntegrityCheckHelper("PRAGMA integrity_check", messages);
1055 }
1056
1057 bool Connection::QuickIntegrityCheck(std::vector<std::string>* messages) {
1058 return IntegrityCheckHelper("PRAGMA quick_check", messages);
1059 }
1060
1054 // TODO(shess): Allow specifying maximum results (default 100 lines). 1061 // TODO(shess): Allow specifying maximum results (default 100 lines).
1055 bool Connection::IntegrityCheck(std::vector<std::string>* messages) { 1062 bool Connection::IntegrityCheckHelper(
1063 const char* pragma_sql,
1064 std::vector<std::string>* messages) {
1056 messages->clear(); 1065 messages->clear();
1057 1066
1058 // This has the side effect of setting SQLITE_RecoveryMode, which 1067 // This has the side effect of setting SQLITE_RecoveryMode, which
1059 // allows SQLite to process through certain cases of corruption. 1068 // allows SQLite to process through certain cases of corruption.
1060 // Failing to set this pragma probably means that the database is 1069 // Failing to set this pragma probably means that the database is
1061 // beyond recovery. 1070 // beyond recovery.
1062 const char kWritableSchema[] = "PRAGMA writable_schema = ON"; 1071 const char kWritableSchema[] = "PRAGMA writable_schema = ON";
1063 if (!Execute(kWritableSchema)) 1072 if (!Execute(kWritableSchema))
1064 return false; 1073 return false;
1065 1074
1066 bool ret = false; 1075 bool ret = false;
1067 { 1076 {
1068 const char kSql[] = "PRAGMA integrity_check"; 1077 sql::Statement stmt(GetUniqueStatement(pragma_sql));
1069 sql::Statement stmt(GetUniqueStatement(kSql));
1070 1078
1071 // The pragma appears to return all results (up to 100 by default) 1079 // The pragma appears to return all results (up to 100 by default)
1072 // as a single string. This doesn't appear to be an API contract, 1080 // as a single string. This doesn't appear to be an API contract,
1073 // it could return separate lines, so loop _and_ split. 1081 // it could return separate lines, so loop _and_ split.
1074 while (stmt.Step()) { 1082 while (stmt.Step()) {
1075 std::string result(stmt.ColumnString(0)); 1083 std::string result(stmt.ColumnString(0));
1076 base::SplitString(result, '\n', messages); 1084 base::SplitString(result, '\n', messages);
1077 } 1085 }
1078 ret = stmt.Succeeded(); 1086 ret = stmt.Succeeded();
1079 } 1087 }
1080 1088
1081 // Best effort to put things back as they were before. 1089 // Best effort to put things back as they were before.
1082 const char kNoWritableSchema[] = "PRAGMA writable_schema = OFF"; 1090 const char kNoWritableSchema[] = "PRAGMA writable_schema = OFF";
1083 ignore_result(Execute(kNoWritableSchema)); 1091 ignore_result(Execute(kNoWritableSchema));
1084 1092
1085 return ret; 1093 return ret;
1086 } 1094 }
1087 1095
1088 } // namespace sql 1096 } // namespace sql
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698