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
3 // found in the LICENSE file.
5 #ifndef SQL_ERROR_DELEGATE_UTIL_H_
6 #define SQL_ERROR_DELEGATE_UTIL_H_
8 #include "base/metrics/histogram.h"
9 #include "sql/connection.h"
10 #include "sql/sql_export.h"
14 // Returns true if it is highly unlikely that the database can recover from
16 SQL_EXPORT
bool IsErrorCatastrophic(int error
);
18 // Log error in console in debug mode and generate a UMA histogram in release
19 // mode for |error| for |UniqueT::name()|.
20 // This function is templated because histograms need to be singletons. That is
21 // why they are always static at the function scope. The template parameter
22 // makes the compiler create unique functions that don't share the same static
24 template <class UniqueT
>
25 void LogAndRecordErrorInHistogram(int error
,
26 sql::Connection
* connection
) {
27 LOG(ERROR
) << "sqlite error " << error
28 << ", errno " << connection
->GetLastErrno()
29 << ": " << connection
->GetErrorMessage();
31 // Trim off the extended error codes.
34 // The histogram values from sqlite result codes currently go from 1 to 26
35 // but 50 gives them room to grow.
36 UMA_HISTOGRAM_ENUMERATION(UniqueT::name(), error
, 50);
41 #endif // SQL_ERROR_DELEGATE_UTIL_H_