Mercurial > hg > orthanc
annotate OrthancFramework/Sources/SQLite/FunctionContext.cpp @ 4181:b416b6bf129b
clarification of sdk doc about deadlocks
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 08 Sep 2020 09:16:33 +0200 |
parents | d25f4c0fa160 |
children | 50b0c69b653a |
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 |
1464 | 42 #include <string> |
0 | 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 | 46 namespace Orthanc |
0 | 47 { |
48 namespace SQLite | |
49 { | |
50 FunctionContext::FunctionContext(struct sqlite3_context* context, | |
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 | 53 { |
54 assert(context != NULL); | |
55 assert(argc >= 0); | |
56 assert(argv != NULL); | |
57 | |
58 context_ = context; | |
59 argc_ = static_cast<unsigned int>(argc); | |
60 argv_ = argv; | |
61 } | |
62 | |
63 void FunctionContext::CheckIndex(unsigned int index) const | |
64 { | |
65 if (index >= argc_) | |
66 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1474
diff
changeset
|
67 throw OrthancSQLiteException(ErrorCode_ParameterOutOfRange); |
0 | 68 } |
69 } | |
70 | |
71 ColumnType FunctionContext::GetColumnType(unsigned int index) const | |
72 { | |
73 CheckIndex(index); | |
74 return static_cast<SQLite::ColumnType>(sqlite3_value_type(argv_[index])); | |
75 } | |
76 | |
77 int FunctionContext::GetIntValue(unsigned int index) const | |
78 { | |
79 CheckIndex(index); | |
80 return sqlite3_value_int(argv_[index]); | |
81 } | |
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 | 89 double FunctionContext::GetDoubleValue(unsigned int index) const |
90 { | |
91 CheckIndex(index); | |
92 return sqlite3_value_double(argv_[index]); | |
93 } | |
94 | |
95 std::string FunctionContext::GetStringValue(unsigned int index) const | |
96 { | |
97 CheckIndex(index); | |
98 return std::string(reinterpret_cast<const char*>(sqlite3_value_text(argv_[index]))); | |
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 | 106 |
107 void FunctionContext::SetNullResult() | |
108 { | |
109 sqlite3_result_null(context_); | |
110 } | |
111 | |
112 void FunctionContext::SetIntResult(int value) | |
113 { | |
114 sqlite3_result_int(context_, value); | |
115 } | |
116 | |
117 void FunctionContext::SetDoubleResult(double value) | |
118 { | |
119 sqlite3_result_double(context_, value); | |
120 } | |
121 | |
122 void FunctionContext::SetStringResult(const std::string& str) | |
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 | 125 } |
126 } | |
127 } |