| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef APP_SQL_CONNECTION_H_ | 5 #ifndef APP_SQL_CONNECTION_H_ |
| 6 #define APP_SQL_CONNECTION_H_ | 6 #define APP_SQL_CONNECTION_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 class Connection; | 70 class Connection; |
| 71 | 71 |
| 72 // ErrorDelegate defines the interface to implement error handling and recovery | 72 // ErrorDelegate defines the interface to implement error handling and recovery |
| 73 // for sqlite operations. This allows the rest of the classes to return true or | 73 // for sqlite operations. This allows the rest of the classes to return true or |
| 74 // false while the actual error code and causing statement are delivered using | 74 // false while the actual error code and causing statement are delivered using |
| 75 // the OnError() callback. | 75 // the OnError() callback. |
| 76 // The tipical usage is to centralize the code designed to handle database | 76 // The tipical usage is to centralize the code designed to handle database |
| 77 // corruption, low-level IO errors or locking violations. | 77 // corruption, low-level IO errors or locking violations. |
| 78 class ErrorDelegate : public base::RefCounted<ErrorDelegate> { | 78 class ErrorDelegate : public base::RefCounted<ErrorDelegate> { |
| 79 public: | 79 public: |
| 80 ErrorDelegate(); |
| 81 |
| 80 // |error| is an sqlite result code as seen in sqlite\preprocessed\sqlite3.h | 82 // |error| is an sqlite result code as seen in sqlite\preprocessed\sqlite3.h |
| 81 // |connection| is db connection where the error happened and |stmt| is | 83 // |connection| is db connection where the error happened and |stmt| is |
| 82 // our best guess at the statement that triggered the error. Do not store | 84 // our best guess at the statement that triggered the error. Do not store |
| 83 // these pointers. | 85 // these pointers. |
| 84 // | 86 // |
| 85 // |stmt| MAY BE NULL if there is no statement causing the problem (i.e. on | 87 // |stmt| MAY BE NULL if there is no statement causing the problem (i.e. on |
| 86 // initialization). | 88 // initialization). |
| 87 // | 89 // |
| 88 // If the error condition has been fixed an the original statement succesfuly | 90 // If the error condition has been fixed an the original statement succesfuly |
| 89 // re-tried then returning SQLITE_OK is appropiate; otherwise is recomended | 91 // re-tried then returning SQLITE_OK is appropiate; otherwise is recomended |
| 90 // that you return the original |error| or the appropiae error code. | 92 // that you return the original |error| or the appropiae error code. |
| 91 virtual int OnError(int error, Connection* connection, Statement* stmt) = 0; | 93 virtual int OnError(int error, Connection* connection, Statement* stmt) = 0; |
| 92 | 94 |
| 93 protected: | 95 protected: |
| 94 friend class base::RefCounted<ErrorDelegate>; | 96 friend class base::RefCounted<ErrorDelegate>; |
| 95 | 97 |
| 96 virtual ~ErrorDelegate() {} | 98 virtual ~ErrorDelegate(); |
| 97 }; | 99 }; |
| 98 | 100 |
| 99 class Connection { | 101 class Connection { |
| 100 private: | 102 private: |
| 101 class StatementRef; // Forward declaration, see real one below. | 103 class StatementRef; // Forward declaration, see real one below. |
| 102 | 104 |
| 103 public: | 105 public: |
| 104 // The database is opened by calling Open[InMemory](). Any uncommitted | 106 // The database is opened by calling Open[InMemory](). Any uncommitted |
| 105 // transactions will be rolled back when this object is deleted. | 107 // transactions will be rolled back when this object is deleted. |
| 106 Connection(); | 108 Connection(); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // This object handles errors resulting from all forms of executing sqlite | 374 // This object handles errors resulting from all forms of executing sqlite |
| 373 // commands or statements. It can be null which means default handling. | 375 // commands or statements. It can be null which means default handling. |
| 374 scoped_refptr<ErrorDelegate> error_delegate_; | 376 scoped_refptr<ErrorDelegate> error_delegate_; |
| 375 | 377 |
| 376 DISALLOW_COPY_AND_ASSIGN(Connection); | 378 DISALLOW_COPY_AND_ASSIGN(Connection); |
| 377 }; | 379 }; |
| 378 | 380 |
| 379 } // namespace sql | 381 } // namespace sql |
| 380 | 382 |
| 381 #endif // APP_SQL_CONNECTION_H_ | 383 #endif // APP_SQL_CONNECTION_H_ |
| OLD | NEW |