OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_STATEMENT_H_ | 5 #ifndef SQL_STATEMENT_H_ |
6 #define SQL_STATEMENT_H_ | 6 #define SQL_STATEMENT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 bool ColumnBlobAsString16(int col, base::string16* val) const; | 143 bool ColumnBlobAsString16(int col, base::string16* val) const; |
144 bool ColumnBlobAsVector(int col, std::vector<char>* val) const; | 144 bool ColumnBlobAsVector(int col, std::vector<char>* val) const; |
145 bool ColumnBlobAsVector(int col, std::vector<unsigned char>* val) const; | 145 bool ColumnBlobAsVector(int col, std::vector<unsigned char>* val) const; |
146 | 146 |
147 // Diagnostics -------------------------------------------------------------- | 147 // Diagnostics -------------------------------------------------------------- |
148 | 148 |
149 // Returns the original text of sql statement. Do not keep a pointer to it. | 149 // Returns the original text of sql statement. Do not keep a pointer to it. |
150 const char* GetSQLStatement(); | 150 const char* GetSQLStatement(); |
151 | 151 |
152 private: | 152 private: |
153 friend class Connection; | |
154 | |
153 // This is intended to check for serious errors and report them to the | 155 // This is intended to check for serious errors and report them to the |
154 // connection object. It takes a sqlite error code, and returns the same | 156 // connection object. It takes a sqlite error code, and returns the same |
155 // code. Currently this function just updates the succeeded flag, but will be | 157 // code. Currently this function just updates the succeeded flag, but will be |
156 // enhanced in the future to do the notification. | 158 // enhanced in the future to do the notification. |
157 int CheckError(int err); | 159 int CheckError(int err); |
158 | 160 |
159 // Contraction for checking an error code against SQLITE_OK. Does not set the | 161 // Contraction for checking an error code against SQLITE_OK. Does not set the |
160 // succeeded flag. | 162 // succeeded flag. |
161 bool CheckOk(int err) const; | 163 bool CheckOk(int err) const; |
162 | 164 |
163 // Should be called by all mutating methods to check that the statement is | 165 // Should be called by all mutating methods to check that the statement is |
164 // valid. Returns true if the statement is valid. DCHECKS and returns false | 166 // valid. Returns true if the statement is valid. DCHECKS and returns false |
165 // if it is not. | 167 // if it is not. |
166 // The reason for this is to handle two specific cases in which a Statement | 168 // The reason for this is to handle two specific cases in which a Statement |
167 // may be invalid. The first case is that the programmer made an SQL error. | 169 // may be invalid. The first case is that the programmer made an SQL error. |
168 // Those cases need to be DCHECKed so that we are guaranteed to find them | 170 // Those cases need to be DCHECKed so that we are guaranteed to find them |
169 // before release. The second case is that the computer has an error (probably | 171 // before release. The second case is that the computer has an error (probably |
170 // out of disk space) which is prohibiting the correct operation of the | 172 // out of disk space) which is prohibiting the correct operation of the |
171 // database. Our testing apparatus should not exhibit this defect, but release | 173 // database. Our testing apparatus should not exhibit this defect, but release |
172 // situations may. Therefore, the code is handling disjoint situations in | 174 // situations may. Therefore, the code is handling disjoint situations in |
173 // release and test. In test, we're ensuring correct SQL. In release, we're | 175 // release and test. In test, we're ensuring correct SQL. In release, we're |
174 // ensuring that contracts are honored in error edge cases. | 176 // ensuring that contracts are honored in error edge cases. |
175 bool CheckValid() const; | 177 bool CheckValid() const; |
176 | 178 |
179 // Helper for Run() and Step(), calls sqlite3_step() and histograms based on | |
180 // the results. The checked value from sqlite3_step() is returned. | |
rmcilroy
2015/05/21 22:54:48
"and histograms based on the results if |timer_fla
Scott Hess - ex-Googler
2015/05/21 23:42:37
Done, maybe, but in terms of "How would I use this
| |
181 int InnerStep(bool timer_flag); | |
rmcilroy
2015/05/21 22:54:48
Maybe call StepInternal would be clearer?
Scott Hess - ex-Googler
2015/05/21 23:42:37
Done.
| |
182 | |
183 // sql::Connection uses cached statments for transactions, but tracks their | |
184 // runtime independently. | |
185 bool RunWithoutTimers(); | |
186 | |
177 // The actual sqlite statement. This may be unique to us, or it may be cached | 187 // The actual sqlite statement. This may be unique to us, or it may be cached |
178 // by the connection, which is why it's refcounted. This pointer is | 188 // by the connection, which is why it's refcounted. This pointer is |
179 // guaranteed non-NULL. | 189 // guaranteed non-NULL. |
180 scoped_refptr<Connection::StatementRef> ref_; | 190 scoped_refptr<Connection::StatementRef> ref_; |
181 | 191 |
182 // Set after Step() or Run() are called, reset by Reset(). Used to | 192 // Set after Step() or Run() are called, reset by Reset(). Used to |
183 // prevent accidental calls to API functions which would not work | 193 // prevent accidental calls to API functions which would not work |
184 // correctly after stepping has started. | 194 // correctly after stepping has started. |
185 bool stepped_; | 195 bool stepped_; |
186 | 196 |
187 // See Succeeded() for what this holds. | 197 // See Succeeded() for what this holds. |
188 bool succeeded_; | 198 bool succeeded_; |
189 | 199 |
190 DISALLOW_COPY_AND_ASSIGN(Statement); | 200 DISALLOW_COPY_AND_ASSIGN(Statement); |
191 }; | 201 }; |
192 | 202 |
193 } // namespace sql | 203 } // namespace sql |
194 | 204 |
195 #endif // SQL_STATEMENT_H_ | 205 #endif // SQL_STATEMENT_H_ |
OLD | NEW |