Mercurial > hg > orthanc
annotate OrthancFramework/Sources/SQLite/Statement.cpp @ 4047:0327421506ad framework
fix paths in GenerateErrorCodes.py
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 11 Jun 2020 07:53:13 +0200 |
parents | d25f4c0fa160 |
children | 0ae2ca210077 |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
3 * |
3063 | 4 * Copyright (C) 2012-2016 Sebastien Jodogne <s.jodogne@orthanc-labs.com>, |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
5 * Medical Physics Department, CHU of Liege, Belgium |
0 | 6 * |
17 | 7 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
8 * | |
9 * Redistribution and use in source and binary forms, with or without | |
10 * modification, are permitted provided that the following conditions are | |
11 * met: | |
0 | 12 * |
17 | 13 * * Redistributions of source code must retain the above copyright |
14 * notice, this list of conditions and the following disclaimer. | |
15 * * Redistributions in binary form must reproduce the above | |
16 * copyright notice, this list of conditions and the following disclaimer | |
17 * in the documentation and/or other materials provided with the | |
18 * distribution. | |
19 * * Neither the name of Google Inc., the name of the CHU of Liege, | |
20 * nor the names of its contributors may be used to endorse or promote | |
21 * products derived from this software without specific prior written | |
22 * permission. | |
23 * | |
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
0 | 35 **/ |
36 | |
37 | |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
38 #if ORTHANC_SQLITE_STANDALONE != 1 |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
724
diff
changeset
|
39 #include "../PrecompiledHeaders.h" |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
40 #endif |
0 | 41 |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
42 #include "Statement.h" |
0 | 43 #include "Connection.h" |
44 | |
45 #include <string.h> | |
1221
2255e66da726
getting rid of the dependency against Boost in the SQLite C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1220
diff
changeset
|
46 #include <stdio.h> |
2255e66da726
getting rid of the dependency against Boost in the SQLite C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1220
diff
changeset
|
47 #include <algorithm> |
0 | 48 |
2588
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
49 #if (ORTHANC_SQLITE_STANDALONE == 1) |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
50 // Trace logging is disabled if this SQLite wrapper is used |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
51 // independently of Orthanc |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
52 # define LOG_CREATE(message); |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
53 # define LOG_APPLY(message); |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
54 #elif defined(NDEBUG) |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
55 // Trace logging is disabled in release builds |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
56 # include "../Logging.h" |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
57 # define LOG_CREATE(message); |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
58 # define LOG_APPLY(message); |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
59 #else |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
60 // Trace logging is enabled in debug builds |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
61 # include "../Logging.h" |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
62 # define LOG_CREATE(message) VLOG(1) << "SQLite::Statement create: " << message; |
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
63 # define LOG_APPLY(message); // VLOG(1) << "SQLite::Statement apply: " << message; |
1226 | 64 #endif |
65 | |
1474
3b68924ffb24
fix path to sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1291
diff
changeset
|
66 #include "sqlite3.h" |
3b68924ffb24
fix path to sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1291
diff
changeset
|
67 |
1222
410c27e04a23
fix visual studio buil
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1221
diff
changeset
|
68 #if defined(_MSC_VER) |
410c27e04a23
fix visual studio buil
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1221
diff
changeset
|
69 #define snprintf _snprintf |
410c27e04a23
fix visual studio buil
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1221
diff
changeset
|
70 #endif |
410c27e04a23
fix visual studio buil
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1221
diff
changeset
|
71 |
2588
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
72 |
59 | 73 namespace Orthanc |
0 | 74 { |
75 namespace SQLite | |
76 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
77 int Statement::CheckError(int err, ErrorCode code) const |
0 | 78 { |
79 bool succeeded = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); | |
80 if (!succeeded) | |
81 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
82 #if ORTHANC_SQLITE_STANDALONE != 1 |
1221
2255e66da726
getting rid of the dependency against Boost in the SQLite C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1220
diff
changeset
|
83 char buffer[128]; |
2255e66da726
getting rid of the dependency against Boost in the SQLite C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1220
diff
changeset
|
84 snprintf(buffer, sizeof(buffer) - 1, "SQLite error code %d", err); |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
85 LOG(ERROR) << buffer; |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
86 #endif |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
87 |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
88 throw OrthancSQLiteException(code); |
0 | 89 } |
90 | |
91 return err; | |
92 } | |
93 | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
94 void Statement::CheckOk(int err, ErrorCode code) const |
0 | 95 { |
96 if (err == SQLITE_RANGE) | |
97 { | |
98 // Binding to a non-existent variable is evidence of a serious error. | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
99 throw OrthancSQLiteException(ErrorCode_SQLiteBindOutOfRange); |
0 | 100 } |
101 else if (err != SQLITE_OK) | |
102 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
103 #if ORTHANC_SQLITE_STANDALONE != 1 |
1221
2255e66da726
getting rid of the dependency against Boost in the SQLite C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1220
diff
changeset
|
104 char buffer[128]; |
2255e66da726
getting rid of the dependency against Boost in the SQLite C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1220
diff
changeset
|
105 snprintf(buffer, sizeof(buffer) - 1, "SQLite error code %d", err); |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
106 LOG(ERROR) << buffer; |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
107 #endif |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
108 |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
109 throw OrthancSQLiteException(code); |
0 | 110 } |
111 } | |
112 | |
113 | |
114 Statement::Statement(Connection& database, | |
115 const StatementId& id, | |
116 const std::string& sql) : | |
117 reference_(database.GetCachedStatement(id, sql.c_str())) | |
118 { | |
119 Reset(true); | |
2588
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
120 LOG_CREATE(sql); |
0 | 121 } |
122 | |
123 | |
124 Statement::Statement(Connection& database, | |
125 const StatementId& id, | |
126 const char* sql) : | |
127 reference_(database.GetCachedStatement(id, sql)) | |
128 { | |
129 Reset(true); | |
2588
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
130 LOG_CREATE(sql); |
0 | 131 } |
132 | |
133 | |
134 Statement::Statement(Connection& database, | |
135 const std::string& sql) : | |
136 reference_(database.GetWrappedObject(), sql.c_str()) | |
137 { | |
2588
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
138 LOG_CREATE(sql); |
0 | 139 } |
140 | |
141 | |
142 Statement::Statement(Connection& database, | |
143 const char* sql) : | |
144 reference_(database.GetWrappedObject(), sql) | |
145 { | |
2588
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
146 LOG_CREATE(sql); |
0 | 147 } |
148 | |
149 | |
150 bool Statement::Run() | |
151 { | |
2588
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
152 LOG_APPLY(sqlite3_sql(GetStatement())); |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
153 |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
154 return CheckError(sqlite3_step(GetStatement()), ErrorCode_SQLiteCannotRun) == SQLITE_DONE; |
0 | 155 } |
156 | |
157 bool Statement::Step() | |
158 { | |
2588
1f7b459b247b
improved trace logging in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
159 LOG_APPLY(sqlite3_sql(GetStatement())); |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
160 |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
161 return CheckError(sqlite3_step(GetStatement()), ErrorCode_SQLiteCannotStep) == SQLITE_ROW; |
0 | 162 } |
163 | |
164 void Statement::Reset(bool clear_bound_vars) | |
165 { | |
166 // We don't call CheckError() here because sqlite3_reset() returns | |
167 // the last error that Step() caused thereby generating a second | |
168 // spurious error callback. | |
169 if (clear_bound_vars) | |
170 sqlite3_clear_bindings(GetStatement()); | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
171 //VLOG(1) << "SQLite::Statement::Reset"; |
0 | 172 sqlite3_reset(GetStatement()); |
173 } | |
174 | |
175 std::string Statement::GetOriginalSQLStatement() | |
176 { | |
177 return std::string(sqlite3_sql(GetStatement())); | |
178 } | |
179 | |
180 | |
181 void Statement::BindNull(int col) | |
182 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
183 CheckOk(sqlite3_bind_null(GetStatement(), col + 1), |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
184 ErrorCode_BadParameterType); |
0 | 185 } |
186 | |
187 void Statement::BindBool(int col, bool val) | |
188 { | |
189 BindInt(col, val ? 1 : 0); | |
190 } | |
191 | |
192 void Statement::BindInt(int col, int val) | |
193 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
194 CheckOk(sqlite3_bind_int(GetStatement(), col + 1, val), |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
195 ErrorCode_BadParameterType); |
0 | 196 } |
197 | |
198 void Statement::BindInt64(int col, int64_t val) | |
199 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
200 CheckOk(sqlite3_bind_int64(GetStatement(), col + 1, val), |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
201 ErrorCode_BadParameterType); |
0 | 202 } |
203 | |
204 void Statement::BindDouble(int col, double val) | |
205 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
206 CheckOk(sqlite3_bind_double(GetStatement(), col + 1, val), |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
207 ErrorCode_BadParameterType); |
0 | 208 } |
209 | |
210 void Statement::BindCString(int col, const char* val) | |
211 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
212 CheckOk(sqlite3_bind_text(GetStatement(), col + 1, val, -1, SQLITE_TRANSIENT), |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
213 ErrorCode_BadParameterType); |
0 | 214 } |
215 | |
216 void Statement::BindString(int col, const std::string& val) | |
217 { | |
218 CheckOk(sqlite3_bind_text(GetStatement(), | |
219 col + 1, | |
220 val.data(), | |
3585
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3063
diff
changeset
|
221 static_cast<int>(val.size()), |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
222 SQLITE_TRANSIENT), |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
223 ErrorCode_BadParameterType); |
0 | 224 } |
225 | |
226 /*void Statement::BindString16(int col, const string16& value) | |
227 { | |
228 BindString(col, UTF16ToUTF8(value)); | |
229 }*/ | |
230 | |
231 void Statement::BindBlob(int col, const void* val, int val_len) | |
232 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
233 CheckOk(sqlite3_bind_blob(GetStatement(), col + 1, val, val_len, SQLITE_TRANSIENT), |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
234 ErrorCode_BadParameterType); |
0 | 235 } |
236 | |
237 | |
238 int Statement::ColumnCount() const | |
239 { | |
240 return sqlite3_column_count(GetStatement()); | |
241 } | |
242 | |
243 | |
244 ColumnType Statement::GetColumnType(int col) const | |
245 { | |
246 // Verify that our enum matches sqlite's values. | |
247 assert(COLUMN_TYPE_INTEGER == SQLITE_INTEGER); | |
248 assert(COLUMN_TYPE_FLOAT == SQLITE_FLOAT); | |
249 assert(COLUMN_TYPE_TEXT == SQLITE_TEXT); | |
250 assert(COLUMN_TYPE_BLOB == SQLITE_BLOB); | |
251 assert(COLUMN_TYPE_NULL == SQLITE_NULL); | |
252 | |
253 return static_cast<ColumnType>(sqlite3_column_type(GetStatement(), col)); | |
254 } | |
255 | |
256 ColumnType Statement::GetDeclaredColumnType(int col) const | |
257 { | |
258 std::string column_type(sqlite3_column_decltype(GetStatement(), col)); | |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
259 std::transform(column_type.begin(), column_type.end(), column_type.begin(), tolower); |
0 | 260 |
261 if (column_type == "integer") | |
262 return COLUMN_TYPE_INTEGER; | |
263 else if (column_type == "float") | |
264 return COLUMN_TYPE_FLOAT; | |
265 else if (column_type == "text") | |
266 return COLUMN_TYPE_TEXT; | |
267 else if (column_type == "blob") | |
268 return COLUMN_TYPE_BLOB; | |
269 | |
270 return COLUMN_TYPE_NULL; | |
271 } | |
272 | |
80 | 273 bool Statement::ColumnIsNull(int col) const |
274 { | |
275 return sqlite3_column_type(GetStatement(), col) == SQLITE_NULL; | |
276 } | |
277 | |
0 | 278 bool Statement::ColumnBool(int col) const |
279 { | |
280 return !!ColumnInt(col); | |
281 } | |
282 | |
283 int Statement::ColumnInt(int col) const | |
284 { | |
285 return sqlite3_column_int(GetStatement(), col); | |
286 } | |
287 | |
288 int64_t Statement::ColumnInt64(int col) const | |
289 { | |
290 return sqlite3_column_int64(GetStatement(), col); | |
291 } | |
292 | |
293 double Statement::ColumnDouble(int col) const | |
294 { | |
295 return sqlite3_column_double(GetStatement(), col); | |
296 } | |
297 | |
298 std::string Statement::ColumnString(int col) const | |
299 { | |
300 const char* str = reinterpret_cast<const char*>( | |
301 sqlite3_column_text(GetStatement(), col)); | |
302 int len = sqlite3_column_bytes(GetStatement(), col); | |
303 | |
304 std::string result; | |
305 if (str && len > 0) | |
306 result.assign(str, len); | |
307 return result; | |
308 } | |
309 | |
310 /*string16 Statement::ColumnString16(int col) const | |
311 { | |
312 std::string s = ColumnString(col); | |
313 return !s.empty() ? UTF8ToUTF16(s) : string16(); | |
314 }*/ | |
315 | |
316 int Statement::ColumnByteLength(int col) const | |
317 { | |
318 return sqlite3_column_bytes(GetStatement(), col); | |
319 } | |
320 | |
321 const void* Statement::ColumnBlob(int col) const | |
322 { | |
323 return sqlite3_column_blob(GetStatement(), col); | |
324 } | |
325 | |
326 bool Statement::ColumnBlobAsString(int col, std::string* blob) | |
327 { | |
328 const void* p = ColumnBlob(col); | |
329 size_t len = ColumnByteLength(col); | |
330 blob->resize(len); | |
331 if (blob->size() != len) { | |
332 return false; | |
333 } | |
334 blob->assign(reinterpret_cast<const char*>(p), len); | |
335 return true; | |
336 } | |
337 | |
338 /*bool Statement::ColumnBlobAsString16(int col, string16* val) const | |
339 { | |
340 const void* data = ColumnBlob(col); | |
341 size_t len = ColumnByteLength(col) / sizeof(char16); | |
342 val->resize(len); | |
343 if (val->size() != len) | |
344 return false; | |
345 val->assign(reinterpret_cast<const char16*>(data), len); | |
346 return true; | |
347 }*/ | |
348 | |
724 | 349 /*bool Statement::ColumnBlobAsVector(int col, std::vector<char>* val) const |
0 | 350 { |
351 val->clear(); | |
352 | |
353 const void* data = sqlite3_column_blob(GetStatement(), col); | |
354 int len = sqlite3_column_bytes(GetStatement(), col); | |
355 if (data && len > 0) { | |
356 val->resize(len); | |
357 memcpy(&(*val)[0], data, len); | |
358 } | |
359 return true; | |
724 | 360 }*/ |
0 | 361 |
724 | 362 /*bool Statement::ColumnBlobAsVector( |
0 | 363 int col, |
364 std::vector<unsigned char>* val) const | |
365 { | |
366 return ColumnBlobAsVector(col, reinterpret_cast< std::vector<char>* >(val)); | |
724 | 367 }*/ |
0 | 368 |
369 } | |
370 } |