Mercurial > hg > orthanc
comparison Core/SQLite/Statement.cpp @ 1220:9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 10 Nov 2014 16:33:51 +0100 |
parents | a811bdf8b8eb |
children | 2255e66da726 |
comparison
equal
deleted
inserted
replaced
1219:c4ae92753d57 | 1220:9b9026560a5f |
---|---|
1 /** | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, | 3 * |
4 * Belgium | 4 * Copyright (C) 2012-2014 Sebastien Jodogne <s.jodogne@gmail.com>, |
5 * Medical Physics Department, CHU of Liege, Belgium | |
5 * | 6 * |
6 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 7 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
7 * | 8 * |
8 * Redistribution and use in source and binary forms, with or without | 9 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions are | 10 * modification, are permitted provided that the following conditions are |
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 **/ | 35 **/ |
35 | 36 |
36 | 37 |
38 #if ORTHANC_SQLITE_STANDALONE != 1 | |
37 #include "../PrecompiledHeaders.h" | 39 #include "../PrecompiledHeaders.h" |
40 #include <glog/logging.h> | |
41 #endif | |
42 | |
38 #include "Statement.h" | 43 #include "Statement.h" |
39 | |
40 #include "Connection.h" | 44 #include "Connection.h" |
41 #include "../Toolbox.h" | |
42 | 45 |
43 #include <boost/lexical_cast.hpp> | 46 #include <boost/lexical_cast.hpp> |
44 #include <sqlite3.h> | 47 #include <sqlite3.h> |
45 #include <string.h> | 48 #include <string.h> |
46 #include <glog/logging.h> | |
47 | 49 |
48 namespace Orthanc | 50 namespace Orthanc |
49 { | 51 { |
50 namespace SQLite | 52 namespace SQLite |
51 { | 53 { |
52 int Statement::CheckError(int err) const | 54 int Statement::CheckError(int err) const |
53 { | 55 { |
54 bool succeeded = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); | 56 bool succeeded = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); |
55 if (!succeeded) | 57 if (!succeeded) |
56 { | 58 { |
57 throw OrthancException("SQLite error code " + boost::lexical_cast<std::string>(err)); | 59 throw OrthancSQLiteException("SQLite error code " + boost::lexical_cast<std::string>(err)); |
58 } | 60 } |
59 | 61 |
60 return err; | 62 return err; |
61 } | 63 } |
62 | 64 |
63 void Statement::CheckOk(int err) const | 65 void Statement::CheckOk(int err) const |
64 { | 66 { |
65 if (err == SQLITE_RANGE) | 67 if (err == SQLITE_RANGE) |
66 { | 68 { |
67 // Binding to a non-existent variable is evidence of a serious error. | 69 // Binding to a non-existent variable is evidence of a serious error. |
68 throw OrthancException("Bind value out of range"); | 70 throw OrthancSQLiteException("Bind value out of range"); |
69 } | 71 } |
70 else if (err != SQLITE_OK) | 72 else if (err != SQLITE_OK) |
71 { | 73 { |
72 throw OrthancException("SQLite error code " + boost::lexical_cast<std::string>(err)); | 74 throw OrthancSQLiteException("SQLite error code " + boost::lexical_cast<std::string>(err)); |
73 } | 75 } |
74 } | 76 } |
75 | 77 |
76 | 78 |
77 Statement::Statement(Connection& database, | 79 Statement::Statement(Connection& database, |
106 } | 108 } |
107 | 109 |
108 | 110 |
109 bool Statement::Run() | 111 bool Statement::Run() |
110 { | 112 { |
113 #if ORTHANC_SQLITE_STANDALONE != 1 | |
111 VLOG(1) << "SQLite::Statement::Run " << sqlite3_sql(GetStatement()); | 114 VLOG(1) << "SQLite::Statement::Run " << sqlite3_sql(GetStatement()); |
115 #endif | |
116 | |
112 return CheckError(sqlite3_step(GetStatement())) == SQLITE_DONE; | 117 return CheckError(sqlite3_step(GetStatement())) == SQLITE_DONE; |
113 } | 118 } |
114 | 119 |
115 bool Statement::Step() | 120 bool Statement::Step() |
116 { | 121 { |
122 #if ORTHANC_SQLITE_STANDALONE != 1 | |
117 VLOG(1) << "SQLite::Statement::Step " << sqlite3_sql(GetStatement()); | 123 VLOG(1) << "SQLite::Statement::Step " << sqlite3_sql(GetStatement()); |
124 #endif | |
125 | |
118 return CheckError(sqlite3_step(GetStatement())) == SQLITE_ROW; | 126 return CheckError(sqlite3_step(GetStatement())) == SQLITE_ROW; |
119 } | 127 } |
120 | 128 |
121 void Statement::Reset(bool clear_bound_vars) | 129 void Statement::Reset(bool clear_bound_vars) |
122 { | 130 { |
204 } | 212 } |
205 | 213 |
206 ColumnType Statement::GetDeclaredColumnType(int col) const | 214 ColumnType Statement::GetDeclaredColumnType(int col) const |
207 { | 215 { |
208 std::string column_type(sqlite3_column_decltype(GetStatement(), col)); | 216 std::string column_type(sqlite3_column_decltype(GetStatement(), col)); |
209 Toolbox::ToLowerCase(column_type); | 217 std::transform(column_type.begin(), column_type.end(), column_type.begin(), tolower); |
210 | 218 |
211 if (column_type == "integer") | 219 if (column_type == "integer") |
212 return COLUMN_TYPE_INTEGER; | 220 return COLUMN_TYPE_INTEGER; |
213 else if (column_type == "float") | 221 else if (column_type == "float") |
214 return COLUMN_TYPE_FLOAT; | 222 return COLUMN_TYPE_FLOAT; |