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