Mercurial > hg > orthanc-databases
annotate Framework/SQLite/SQLiteStatement.cpp @ 330:8f17f23c9af7
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Aug 2021 20:52:16 +0200 |
parents | 9d00e5e073e8 |
children | 16aac0287485 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
193
3236894320d6
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "SQLiteStatement.h" | |
23 | |
24 #include "../Common/BinaryStringValue.h" | |
245
9d00e5e073e8
rename FileValue as ResultFileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
25 #include "../Common/InputFileValue.h" |
0 | 26 #include "../Common/Integer64Value.h" |
27 #include "../Common/Query.h" | |
28 #include "../Common/Utf8StringValue.h" | |
29 #include "SQLiteResult.h" | |
30 | |
152 | 31 #include <OrthancException.h> |
0 | 32 |
33 namespace OrthancDatabases | |
34 { | |
35 SQLiteStatement::SQLiteStatement(SQLiteDatabase& database, | |
36 const Query& query) : | |
37 formatter_(Dialect_SQLite) | |
38 { | |
39 std::string sql; | |
40 query.Format(sql, formatter_); | |
41 | |
42 statement_.reset(new Orthanc::SQLite::Statement(database.GetObject(), sql)); | |
43 } | |
44 | |
45 | |
46 Orthanc::SQLite::Statement& SQLiteStatement::GetObject() | |
47 { | |
48 if (statement_.get() == NULL) | |
49 { | |
50 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
51 } | |
52 else | |
53 { | |
54 return *statement_; | |
55 } | |
56 } | |
57 | |
58 | |
59 void SQLiteStatement::BindParameters(const Dictionary& parameters) | |
60 { | |
61 statement_->Reset(); | |
62 | |
63 for (size_t i = 0; i < formatter_.GetParametersCount(); i++) | |
64 { | |
65 const std::string& name = formatter_.GetParameterName(i); | |
66 | |
67 switch (formatter_.GetParameterType(i)) | |
68 { | |
69 case ValueType_BinaryString: | |
70 { | |
71 const BinaryStringValue& blob = | |
72 dynamic_cast<const BinaryStringValue&>(parameters.GetValue(name)); | |
73 statement_->BindBlob(i, blob.GetBuffer(), blob.GetSize()); | |
74 break; | |
75 } | |
76 | |
245
9d00e5e073e8
rename FileValue as ResultFileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
77 case ValueType_InputFile: |
0 | 78 { |
245
9d00e5e073e8
rename FileValue as ResultFileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
79 const InputFileValue& blob = |
9d00e5e073e8
rename FileValue as ResultFileValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
80 dynamic_cast<const InputFileValue&>(parameters.GetValue(name)); |
0 | 81 statement_->BindBlob(i, blob.GetBuffer(), blob.GetSize()); |
82 break; | |
83 } | |
84 | |
85 case ValueType_Integer64: | |
86 statement_->BindInt64(i, dynamic_cast<const Integer64Value&> | |
87 (parameters.GetValue(name)).GetValue()); | |
88 break; | |
89 | |
90 case ValueType_Null: | |
91 statement_->BindNull(i); | |
92 break; | |
93 | |
94 case ValueType_Utf8String: | |
95 statement_->BindString(i, dynamic_cast<const Utf8StringValue&> | |
96 (parameters.GetValue(name)).GetContent()); | |
97 break; | |
98 | |
99 default: | |
100 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
101 } | |
102 } | |
103 } | |
104 | |
105 | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
106 IResult* SQLiteStatement::Execute(ITransaction& transaction, |
0 | 107 const Dictionary& parameters) |
108 { | |
109 BindParameters(parameters); | |
110 return new SQLiteResult(*this); | |
111 } | |
112 | |
113 | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
114 void SQLiteStatement::ExecuteWithoutResult(ITransaction& transaction, |
0 | 115 const Dictionary& parameters) |
116 { | |
117 BindParameters(parameters); | |
118 | |
119 if (!statement_->Run()) | |
120 { | |
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
122 } | |
123 } | |
124 } |