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