summaryrefslogtreecommitdiffstats
path: root/app/sql
diff options
context:
space:
mode:
Diffstat (limited to 'app/sql')
-rw-r--r--app/sql/connection.cc11
-rw-r--r--app/sql/connection.h4
-rw-r--r--app/sql/diagnostic_error_delegate.h5
3 files changed, 18 insertions, 2 deletions
diff --git a/app/sql/connection.cc b/app/sql/connection.cc
index 0b9021f..d227468 100644
--- a/app/sql/connection.cc
+++ b/app/sql/connection.cc
@@ -258,6 +258,17 @@ int Connection::GetErrorCode() const {
return sqlite3_errcode(db_);
}
+int Connection::GetLastErrno() const {
+ if (!db_)
+ return -1;
+
+ int err = 0;
+ if (SQLITE_OK != sqlite3_file_control(db_, NULL, SQLITE_LAST_ERRNO, &err))
+ return -2;
+
+ return err;
+}
+
const char* Connection::GetErrorMessage() const {
if (!db_)
return "sql::Connection has no connection.";
diff --git a/app/sql/connection.h b/app/sql/connection.h
index b89fb1a..0bd28ca 100644
--- a/app/sql/connection.h
+++ b/app/sql/connection.h
@@ -261,6 +261,10 @@ class Connection {
// Returns the error code associated with the last sqlite operation.
int GetErrorCode() const;
+ // Returns the errno associated with GetErrorCode(). See
+ // SQLITE_LAST_ERRNO in SQLite documentation.
+ int GetLastErrno() const;
+
// Returns a pointer to a statically allocated string associated with the
// last sqlite operation.
const char* GetErrorMessage() const;
diff --git a/app/sql/diagnostic_error_delegate.h b/app/sql/diagnostic_error_delegate.h
index c9de8ee..1c2d6e9 100644
--- a/app/sql/diagnostic_error_delegate.h
+++ b/app/sql/diagnostic_error_delegate.h
@@ -27,8 +27,9 @@ class DiagnosticErrorDelegate : public ErrorDelegate {
virtual int OnError(int error, Connection* connection,
Statement* stmt) {
- NOTREACHED() << "sqlite error " << error << ": " <<
- connection->GetErrorMessage();
+ NOTREACHED() << "sqlite error " << error
+ << ", errno " << connection->GetLastErrno()
+ << ": " << connection->GetErrorMessage();
RecordErrorInHistogram(error);
return error;
}