diff options
Diffstat (limited to 'chromium/sql/connection.cc')
-rw-r--r-- | chromium/sql/connection.cc | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/chromium/sql/connection.cc b/chromium/sql/connection.cc index 097edd7a1ea..0caa9edc5b5 100644 --- a/chromium/sql/connection.cc +++ b/chromium/sql/connection.cc @@ -133,7 +133,7 @@ namespace sql { Connection::ErrorIgnorerCallback* Connection::current_ignorer_cb_ = NULL; // static -bool Connection::ShouldIgnore(int error) { +bool Connection::ShouldIgnoreSqliteError(int error) { if (!current_ignorer_cb_) return false; return current_ignorer_cb_->Run(error); @@ -213,7 +213,7 @@ Connection::~Connection() { bool Connection::Open(const base::FilePath& path) { if (!histogram_tag_.empty()) { int64 size_64 = 0; - if (file_util::GetFileSize(path, &size_64)) { + if (base::GetFileSize(path, &size_64)) { size_t sample = static_cast<size_t>(size_64 / 1024); std::string full_histogram_name = "Sqlite.SizeKB." + histogram_tag_; base::HistogramBase* histogram = @@ -641,7 +641,7 @@ bool Connection::Execute(const char* sql) { int error = ExecuteAndReturnErrorCode(sql); if (error != SQLITE_OK) - error = OnSqliteError(error, NULL); + error = OnSqliteError(error, NULL, sql); // This needs to be a FATAL log because the error case of arriving here is // that there's a malformed SQL statement. This can arise in development if @@ -702,7 +702,7 @@ scoped_refptr<Connection::StatementRef> Connection::GetUniqueStatement( DLOG(FATAL) << "SQL compile error " << GetErrorMessage(); // It could also be database corruption. - OnSqliteError(rc, NULL); + OnSqliteError(rc, NULL, sql); return new StatementRef(NULL, NULL, false); } return new StatementRef(this, stmt, true); @@ -864,7 +864,7 @@ bool Connection::OpenInternal(const std::string& file_name, // purposes. UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.OpenFailure", err); - OnSqliteError(err, NULL); + OnSqliteError(err, NULL, "-- sqlite3_open()"); bool was_poisoned = poisoned_; Close(); @@ -881,9 +881,9 @@ bool Connection::OpenInternal(const std::string& file_name, int mode = 0; // TODO(shess): Arguably, failure to retrieve and change // permissions should be fatal if the file exists. - if (file_util::GetPosixFilePermissions(file_path, &mode)) { - mode &= file_util::FILE_PERMISSION_USER_MASK; - file_util::SetPosixFilePermissions(file_path, mode); + if (base::GetPosixFilePermissions(file_path, &mode)) { + mode &= base::FILE_PERMISSION_USER_MASK; + base::SetPosixFilePermissions(file_path, mode); // SQLite sets the permissions on these files from the main // database on create. Set them here in case they already exist @@ -891,8 +891,8 @@ bool Connection::OpenInternal(const std::string& file_name, // be fatal unless the file doesn't exist. base::FilePath journal_path(file_name + FILE_PATH_LITERAL("-journal")); base::FilePath wal_path(file_name + FILE_PATH_LITERAL("-wal")); - file_util::SetPosixFilePermissions(journal_path, mode); - file_util::SetPosixFilePermissions(wal_path, mode); + base::SetPosixFilePermissions(journal_path, mode); + base::SetPosixFilePermissions(wal_path, mode); } } #endif // defined(OS_POSIX) @@ -1022,14 +1022,19 @@ void Connection::AddTaggedHistogram(const std::string& name, histogram->Add(sample); } -int Connection::OnSqliteError(int err, sql::Statement *stmt) { +int Connection::OnSqliteError(int err, sql::Statement *stmt, const char* sql) { UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.Error", err); AddTaggedHistogram("Sqlite.Error", err); // Always log the error. - LOG(ERROR) << "sqlite error " << err + if (!sql && stmt) + sql = stmt->GetSQLStatement(); + if (!sql) + sql = "-- unknown"; + LOG(ERROR) << histogram_tag_ << " sqlite error " << err << ", errno " << GetLastErrno() - << ": " << GetErrorMessage(); + << ": " << GetErrorMessage() + << ", sql: " << sql; if (!error_callback_.is_null()) { // Fire from a copy of the callback in case of reentry into @@ -1040,14 +1045,26 @@ int Connection::OnSqliteError(int err, sql::Statement *stmt) { } // The default handling is to assert on debug and to ignore on release. - if (!ShouldIgnore(err)) + if (!ShouldIgnoreSqliteError(err)) DLOG(FATAL) << GetErrorMessage(); return err; } -// TODO(shess): Allow specifying integrity_check versus quick_check. +bool Connection::FullIntegrityCheck(std::vector<std::string>* messages) { + return IntegrityCheckHelper("PRAGMA integrity_check", messages); +} + +bool Connection::QuickIntegrityCheck() { + std::vector<std::string> messages; + if (!IntegrityCheckHelper("PRAGMA quick_check", &messages)) + return false; + return messages.size() == 1 && messages[0] == "ok"; +} + // TODO(shess): Allow specifying maximum results (default 100 lines). -bool Connection::IntegrityCheck(std::vector<std::string>* messages) { +bool Connection::IntegrityCheckHelper( + const char* pragma_sql, + std::vector<std::string>* messages) { messages->clear(); // This has the side effect of setting SQLITE_RecoveryMode, which @@ -1060,8 +1077,7 @@ bool Connection::IntegrityCheck(std::vector<std::string>* messages) { bool ret = false; { - const char kSql[] = "PRAGMA integrity_check"; - sql::Statement stmt(GetUniqueStatement(kSql)); + sql::Statement stmt(GetUniqueStatement(pragma_sql)); // The pragma appears to return all results (up to 100 by default) // as a single string. This doesn't appear to be an API contract, |