annotate OrthancFramework/Sources/SQLite/FunctionContext.cpp @ 4543:5b1b46f3fcca Orthanc-1.7.3

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