| 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 then generates |
| 180 // sql::Connection histograms based on the results. Timing and change count |
| 181 // are only recorded if |timer_flag| is true. The checked value from |
| 182 // sqlite3_step() is returned. |
| 183 int StepInternal(bool timer_flag); |
| 184 |
| 185 // sql::Connection uses cached statments for transactions, but tracks their |
| 186 // runtime independently. |
| 187 bool RunWithoutTimers(); |
| 188 |
| 177 // The actual sqlite statement. This may be unique to us, or it may be cached | 189 // 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 | 190 // by the connection, which is why it's refcounted. This pointer is |
| 179 // guaranteed non-NULL. | 191 // guaranteed non-NULL. |
| 180 scoped_refptr<Connection::StatementRef> ref_; | 192 scoped_refptr<Connection::StatementRef> ref_; |
| 181 | 193 |
| 182 // Set after Step() or Run() are called, reset by Reset(). Used to | 194 // Set after Step() or Run() are called, reset by Reset(). Used to |
| 183 // prevent accidental calls to API functions which would not work | 195 // prevent accidental calls to API functions which would not work |
| 184 // correctly after stepping has started. | 196 // correctly after stepping has started. |
| 185 bool stepped_; | 197 bool stepped_; |
| 186 | 198 |
| 187 // See Succeeded() for what this holds. | 199 // See Succeeded() for what this holds. |
| 188 bool succeeded_; | 200 bool succeeded_; |
| 189 | 201 |
| 190 DISALLOW_COPY_AND_ASSIGN(Statement); | 202 DISALLOW_COPY_AND_ASSIGN(Statement); |
| 191 }; | 203 }; |
| 192 | 204 |
| 193 } // namespace sql | 205 } // namespace sql |
| 194 | 206 |
| 195 #endif // SQL_STATEMENT_H_ | 207 #endif // SQL_STATEMENT_H_ |
| OLD | NEW |