Index: sql/connection.h |
diff --git a/sql/connection.h b/sql/connection.h |
index 65020a04ebb86e0842f1048d119e2d88185b4fbf..2744f61bc36cb7d3bd546e871ca3ba376e56849d 100644 |
--- a/sql/connection.h |
+++ b/sql/connection.h |
@@ -8,6 +8,7 @@ |
#include <map> |
#include <set> |
#include <string> |
+#include <vector> |
#include "base/basictypes.h" |
#include "base/compiler_specific.h" |
@@ -139,11 +140,34 @@ class SQL_EXPORT Connection { |
// This must be called before Open() to have an effect. |
void set_exclusive_locking() { exclusive_locking_ = true; } |
- // Sets the object that will handle errors. Recomended that it should be set |
- // before calling Open(). If not set, the default is to ignore errors on |
- // release and assert on debug builds. |
+ // Setup objects to handle errors. SQLite errors can occur as early |
+ // as Open() and as late as Close(). If no handlers are set, errors |
+ // are ignored in release builds and crash in debug builds (in |
+ // development, SQLite errors almost always mean an error in code). |
+ // Returning SQLITE_OK from a delegate terminates error delegation. |
+ void add_error_delegate(ErrorDelegate* delegate) { |
+ error_delegates_.push_back(delegate); |
+ } |
+ void remove_error_delegate(ErrorDelegate* delegate) { |
+ std::vector<scoped_refptr<ErrorDelegate> >::iterator iter = |
+ error_delegates_.begin(); |
+ while (iter != error_delegates_.end()) { |
+ if (*iter == delegate) { |
+ iter = error_delegates_.erase(iter); |
+ } else { |
+ ++iter; |
+ } |
+ } |
+ } |
+ void clear_error_delegates() { |
+ error_delegates_.clear(); |
+ } |
+ |
+ // Previously there could only be one delegate. Retain this for |
+ // compatibility. |
void set_error_delegate(ErrorDelegate* delegate) { |
- error_delegate_ = delegate; |
+ clear_error_delegates(); |
+ add_error_delegate(delegate); |
} |
// Initialization ------------------------------------------------------------ |
@@ -443,9 +467,9 @@ class SQL_EXPORT Connection { |
// with Open(). |
bool in_memory_; |
- // This object handles errors resulting from all forms of executing sqlite |
- // commands or statements. It can be null which means default handling. |
- scoped_refptr<ErrorDelegate> error_delegate_; |
+ // These objects handle errors resulting from all forms of executing sqlite |
+ // commands or statements. It can be empty which means default handling. |
+ std::vector<scoped_refptr<ErrorDelegate> > error_delegates_; |
DISALLOW_COPY_AND_ASSIGN(Connection); |
}; |