OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 SQL_CONNECTION_H_ | 5 #ifndef SQL_CONNECTION_H_ |
6 #define SQL_CONNECTION_H_ | 6 #define SQL_CONNECTION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "sql/sql_export.h" |
16 | 17 |
17 class FilePath; | 18 class FilePath; |
18 struct sqlite3; | 19 struct sqlite3; |
19 struct sqlite3_stmt; | 20 struct sqlite3_stmt; |
20 | 21 |
21 namespace sql { | 22 namespace sql { |
22 | 23 |
23 class Statement; | 24 class Statement; |
24 | 25 |
25 // Uniquely identifies a statement. There are two modes of operation: | 26 // Uniquely identifies a statement. There are two modes of operation: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #define SQL_FROM_HERE sql::StatementID(__FILE__, __LINE__) | 70 #define SQL_FROM_HERE sql::StatementID(__FILE__, __LINE__) |
70 | 71 |
71 class Connection; | 72 class Connection; |
72 | 73 |
73 // ErrorDelegate defines the interface to implement error handling and recovery | 74 // ErrorDelegate defines the interface to implement error handling and recovery |
74 // for sqlite operations. This allows the rest of the classes to return true or | 75 // for sqlite operations. This allows the rest of the classes to return true or |
75 // false while the actual error code and causing statement are delivered using | 76 // false while the actual error code and causing statement are delivered using |
76 // the OnError() callback. | 77 // the OnError() callback. |
77 // The tipical usage is to centralize the code designed to handle database | 78 // The tipical usage is to centralize the code designed to handle database |
78 // corruption, low-level IO errors or locking violations. | 79 // corruption, low-level IO errors or locking violations. |
79 class ErrorDelegate : public base::RefCounted<ErrorDelegate> { | 80 class SQL_EXPORT ErrorDelegate : public base::RefCounted<ErrorDelegate> { |
80 public: | 81 public: |
81 ErrorDelegate(); | 82 ErrorDelegate(); |
82 | 83 |
83 // |error| is an sqlite result code as seen in sqlite\preprocessed\sqlite3.h | 84 // |error| is an sqlite result code as seen in sqlite\preprocessed\sqlite3.h |
84 // |connection| is db connection where the error happened and |stmt| is | 85 // |connection| is db connection where the error happened and |stmt| is |
85 // our best guess at the statement that triggered the error. Do not store | 86 // our best guess at the statement that triggered the error. Do not store |
86 // these pointers. | 87 // these pointers. |
87 // | 88 // |
88 // |stmt| MAY BE NULL if there is no statement causing the problem (i.e. on | 89 // |stmt| MAY BE NULL if there is no statement causing the problem (i.e. on |
89 // initialization). | 90 // initialization). |
90 // | 91 // |
91 // If the error condition has been fixed an the original statement succesfuly | 92 // If the error condition has been fixed an the original statement succesfuly |
92 // re-tried then returning SQLITE_OK is appropiate; otherwise is recomended | 93 // re-tried then returning SQLITE_OK is appropiate; otherwise is recomended |
93 // that you return the original |error| or the appropiae error code. | 94 // that you return the original |error| or the appropiae error code. |
94 virtual int OnError(int error, Connection* connection, Statement* stmt) = 0; | 95 virtual int OnError(int error, Connection* connection, Statement* stmt) = 0; |
95 | 96 |
96 protected: | 97 protected: |
97 friend class base::RefCounted<ErrorDelegate>; | 98 friend class base::RefCounted<ErrorDelegate>; |
98 | 99 |
99 virtual ~ErrorDelegate(); | 100 virtual ~ErrorDelegate(); |
100 }; | 101 }; |
101 | 102 |
102 class Connection { | 103 class SQL_EXPORT Connection { |
103 private: | 104 private: |
104 class StatementRef; // Forward declaration, see real one below. | 105 class StatementRef; // Forward declaration, see real one below. |
105 | 106 |
106 public: | 107 public: |
107 // The database is opened by calling Open[InMemory](). Any uncommitted | 108 // The database is opened by calling Open[InMemory](). Any uncommitted |
108 // transactions will be rolled back when this object is deleted. | 109 // transactions will be rolled back when this object is deleted. |
109 Connection(); | 110 Connection(); |
110 ~Connection(); | 111 ~Connection(); |
111 | 112 |
112 // Pre-init configuration ---------------------------------------------------- | 113 // Pre-init configuration ---------------------------------------------------- |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 // This object handles errors resulting from all forms of executing sqlite | 379 // This object handles errors resulting from all forms of executing sqlite |
379 // commands or statements. It can be null which means default handling. | 380 // commands or statements. It can be null which means default handling. |
380 scoped_refptr<ErrorDelegate> error_delegate_; | 381 scoped_refptr<ErrorDelegate> error_delegate_; |
381 | 382 |
382 DISALLOW_COPY_AND_ASSIGN(Connection); | 383 DISALLOW_COPY_AND_ASSIGN(Connection); |
383 }; | 384 }; |
384 | 385 |
385 } // namespace sql | 386 } // namespace sql |
386 | 387 |
387 #endif // SQL_CONNECTION_H_ | 388 #endif // SQL_CONNECTION_H_ |
OLD | NEW |