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 #include "app/sql/statement.h" | 5 #include "app/sql/statement.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/sqlite/preprocessed/sqlite3.h" | 8 #include "third_party/sqlite/preprocessed/sqlite3.h" |
9 | 9 |
10 namespace sql { | 10 namespace sql { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 const char* str = reinterpret_cast<const char*>( | 163 const char* str = reinterpret_cast<const char*>( |
164 sqlite3_column_text(ref_->stmt(), col)); | 164 sqlite3_column_text(ref_->stmt(), col)); |
165 int len = sqlite3_column_bytes(ref_->stmt(), col); | 165 int len = sqlite3_column_bytes(ref_->stmt(), col); |
166 | 166 |
167 std::string result; | 167 std::string result; |
168 if (str && len > 0) | 168 if (str && len > 0) |
169 result.assign(str, len); | 169 result.assign(str, len); |
170 return result; | 170 return result; |
171 } | 171 } |
172 | 172 |
173 int Statement::ColumnByteLength(int col) { | 173 int Statement::ColumnByteLength(int col) const { |
174 if (!is_valid()) { | 174 if (!is_valid()) { |
175 NOTREACHED(); | 175 NOTREACHED(); |
176 return 0; | 176 return 0; |
177 } | 177 } |
178 return sqlite3_column_bytes(ref_->stmt(), col); | 178 return sqlite3_column_bytes(ref_->stmt(), col); |
179 } | 179 } |
180 | 180 |
181 const void* Statement::ColumnBlob(int col) { | 181 const void* Statement::ColumnBlob(int col) const { |
182 if (!is_valid()) { | 182 if (!is_valid()) { |
183 NOTREACHED(); | 183 NOTREACHED(); |
184 return NULL; | 184 return NULL; |
185 } | 185 } |
186 | 186 |
187 return sqlite3_column_blob(ref_->stmt(), col); | 187 return sqlite3_column_blob(ref_->stmt(), col); |
188 } | 188 } |
189 | 189 |
190 void Statement::ColumnBlobAsVector(int col, std::vector<char>* val) { | 190 void Statement::ColumnBlobAsVector(int col, std::vector<char>* val) const { |
191 val->clear(); | 191 val->clear(); |
192 if (!is_valid()) { | 192 if (!is_valid()) { |
193 NOTREACHED(); | 193 NOTREACHED(); |
194 return; | 194 return; |
195 } | 195 } |
196 | 196 |
197 const void* data = sqlite3_column_blob(ref_->stmt(), col); | 197 const void* data = sqlite3_column_blob(ref_->stmt(), col); |
198 int len = sqlite3_column_bytes(ref_->stmt(), col); | 198 int len = sqlite3_column_bytes(ref_->stmt(), col); |
199 if (data && len > 0) { | 199 if (data && len > 0) { |
200 val->resize(len); | 200 val->resize(len); |
201 memcpy(&(*val)[0], data, len); | 201 memcpy(&(*val)[0], data, len); |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
| 205 void Statement::ColumnBlobAsVector( |
| 206 int col, |
| 207 std::vector<unsigned char>* val) const { |
| 208 ColumnBlobAsVector(col, reinterpret_cast< std::vector<char>* >(val)); |
| 209 } |
| 210 |
205 int Statement::CheckError(int err) { | 211 int Statement::CheckError(int err) { |
206 succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); | 212 succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); |
207 | 213 |
208 // TODO(brettw) enhance this to process the error. | 214 // TODO(brettw) enhance this to process the error. |
209 return err; | 215 return err; |
210 } | 216 } |
211 | 217 |
212 } // namespace sql | 218 } // namespace sql |
OLD | NEW |