Mercurial > hg > orthanc
annotate OrthancFramework/Sources/SQLite/FunctionContext.cpp @ 5115:0a9d36187a91
merge
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 02 Dec 2022 15:05:33 +0100 |
parents | 43e613a7756b |
children | 0ea402b4d901 |
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 |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
7 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 8 * |
17 | 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 the CHU of Liege, nor the names of its | |
20 * contributors may be used to endorse or promote products derived | |
21 * from this software without specific prior written permission. | |
22 * | |
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
32 * (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. | |
0 | 34 **/ |
35 | |
36 | |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
37 #if ORTHANC_SQLITE_STANDALONE != 1 |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
694
diff
changeset
|
38 #include "../PrecompiledHeaders.h" |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
39 #endif |
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
40 |
0 | 41 #include "FunctionContext.h" |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
42 #include "OrthancSQLiteException.h" |
0 | 43 |
4304 | 44 #include <cassert> |
1464 | 45 #include <string> |
0 | 46 |
1474
3b68924ffb24
fix path to sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1464
diff
changeset
|
47 #include "sqlite3.h" |
3b68924ffb24
fix path to sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1464
diff
changeset
|
48 |
59 | 49 namespace Orthanc |
0 | 50 { |
51 namespace SQLite | |
52 { | |
53 FunctionContext::FunctionContext(struct sqlite3_context* context, | |
54 int argc, | |
2302
f31dfb131dee
fix backward compatibility with SQLite < 3.19.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2301
diff
changeset
|
55 Internals::SQLiteValue** argv) |
0 | 56 { |
57 assert(context != NULL); | |
58 assert(argc >= 0); | |
59 assert(argv != NULL); | |
60 | |
61 context_ = context; | |
62 argc_ = static_cast<unsigned int>(argc); | |
63 argv_ = argv; | |
64 } | |
65 | |
66 void FunctionContext::CheckIndex(unsigned int index) const | |
67 { | |
68 if (index >= argc_) | |
69 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1474
diff
changeset
|
70 throw OrthancSQLiteException(ErrorCode_ParameterOutOfRange); |
0 | 71 } |
72 } | |
73 | |
74 ColumnType FunctionContext::GetColumnType(unsigned int index) const | |
75 { | |
76 CheckIndex(index); | |
77 return static_cast<SQLite::ColumnType>(sqlite3_value_type(argv_[index])); | |
78 } | |
79 | |
4304 | 80 unsigned int FunctionContext::GetParameterCount() const |
81 { | |
82 return argc_; | |
83 } | |
84 | |
0 | 85 int FunctionContext::GetIntValue(unsigned int index) const |
86 { | |
87 CheckIndex(index); | |
88 return sqlite3_value_int(argv_[index]); | |
89 } | |
90 | |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
91 int64_t FunctionContext::GetInt64Value(unsigned int index) const |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
92 { |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
93 CheckIndex(index); |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
94 return sqlite3_value_int64(argv_[index]); |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
95 } |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
96 |
0 | 97 double FunctionContext::GetDoubleValue(unsigned int index) const |
98 { | |
99 CheckIndex(index); | |
100 return sqlite3_value_double(argv_[index]); | |
101 } | |
102 | |
103 std::string FunctionContext::GetStringValue(unsigned int index) const | |
104 { | |
105 CheckIndex(index); | |
106 return std::string(reinterpret_cast<const char*>(sqlite3_value_text(argv_[index]))); | |
107 } | |
694
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
108 |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
109 bool FunctionContext::IsNullValue(unsigned int index) const |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
110 { |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
111 CheckIndex(index); |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
112 return sqlite3_value_type(argv_[index]) == SQLITE_NULL; |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
113 } |
0 | 114 |
115 void FunctionContext::SetNullResult() | |
116 { | |
117 sqlite3_result_null(context_); | |
118 } | |
119 | |
120 void FunctionContext::SetIntResult(int value) | |
121 { | |
122 sqlite3_result_int(context_, value); | |
123 } | |
124 | |
125 void FunctionContext::SetDoubleResult(double value) | |
126 { | |
127 sqlite3_result_double(context_, value); | |
128 } | |
129 | |
130 void FunctionContext::SetStringResult(const std::string& str) | |
131 { | |
3585
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3063
diff
changeset
|
132 sqlite3_result_text(context_, str.data(), static_cast<int>(str.size()), SQLITE_TRANSIENT); |
0 | 133 } |
134 } | |
135 } |