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

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.
1054 // TODO(shess): Allow specifying maximum results (default 100 lines). 1053 // TODO(shess): Allow specifying maximum results (default 100 lines).
1055 bool Connection::IntegrityCheck(std::vector<std::string>* messages) { 1054 bool Connection::IntegrityCheck(
1055 std::vector<std::string>* messages,
1056 bool quick) {
1056 messages->clear(); 1057 messages->clear();
1057 1058
1058 // This has the side effect of setting SQLITE_RecoveryMode, which 1059 // This has the side effect of setting SQLITE_RecoveryMode, which
1059 // allows SQLite to process through certain cases of corruption. 1060 // allows SQLite to process through certain cases of corruption.
1060 // Failing to set this pragma probably means that the database is 1061 // Failing to set this pragma probably means that the database is
1061 // beyond recovery. 1062 // beyond recovery.
1062 const char kWritableSchema[] = "PRAGMA writable_schema = ON"; 1063 const char kWritableSchema[] = "PRAGMA writable_schema = ON";
1063 if (!Execute(kWritableSchema)) 1064 if (!Execute(kWritableSchema))
1064 return false; 1065 return false;
1065 1066
1066 bool ret = false; 1067 bool ret = false;
1067 { 1068 {
1068 const char kSql[] = "PRAGMA integrity_check"; 1069 const char* kSql = quick ?
1070 "PRAGMA quick_check" : "PRAGMA integrity_check";
1069 sql::Statement stmt(GetUniqueStatement(kSql)); 1071 sql::Statement stmt(GetUniqueStatement(kSql));
1070 1072
1071 // The pragma appears to return all results (up to 100 by default) 1073 // 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, 1074 // as a single string. This doesn't appear to be an API contract,
1073 // it could return separate lines, so loop _and_ split. 1075 // it could return separate lines, so loop _and_ split.
1074 while (stmt.Step()) { 1076 while (stmt.Step()) {
1075 std::string result(stmt.ColumnString(0)); 1077 std::string result(stmt.ColumnString(0));
1076 base::SplitString(result, '\n', messages); 1078 base::SplitString(result, '\n', messages);
1077 } 1079 }
1078 ret = stmt.Succeeded(); 1080 ret = stmt.Succeeded();
1079 } 1081 }
1080 1082
1081 // Best effort to put things back as they were before. 1083 // Best effort to put things back as they were before.
1082 const char kNoWritableSchema[] = "PRAGMA writable_schema = OFF"; 1084 const char kNoWritableSchema[] = "PRAGMA writable_schema = OFF";
1083 ignore_result(Execute(kNoWritableSchema)); 1085 ignore_result(Execute(kNoWritableSchema));
1084 1086
1085 return ret; 1087 return ret;
1086 } 1088 }
1087 1089
1088 } // namespace sql 1090 } // namespace sql
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698