Mercurial > hg > orthanc
annotate Core/SQLite/FunctionContext.cpp @ 2745:cd2d8dc9faca Orthanc-0.6.1
close old branch
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 09:39:20 +0200 |
parents | bdd72233b105 |
children | 2d0a347e8cfc |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
398 | 3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, |
0 | 4 * Belgium |
5 * | |
17 | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are | |
8 * met: | |
0 | 9 * |
17 | 10 * * Redistributions of source code must retain the above copyright |
11 * notice, this list of conditions and the following disclaimer. | |
12 * * Redistributions in binary form must reproduce the above | |
13 * copyright notice, this list of conditions and the following disclaimer | |
14 * in the documentation and/or other materials provided with the | |
15 * distribution. | |
16 * * Neither the name of the CHU of Liege, nor the names of its | |
17 * contributors may be used to endorse or promote products derived | |
18 * from this software without specific prior written permission. | |
19 * | |
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
0 | 31 **/ |
32 | |
33 | |
34 #include "FunctionContext.h" | |
35 | |
36 #include <sqlite3.h> | |
37 | |
59 | 38 namespace Orthanc |
0 | 39 { |
40 namespace SQLite | |
41 { | |
42 FunctionContext::FunctionContext(struct sqlite3_context* context, | |
43 int argc, | |
44 struct ::Mem** argv) | |
45 { | |
46 assert(context != NULL); | |
47 assert(argc >= 0); | |
48 assert(argv != NULL); | |
49 | |
50 context_ = context; | |
51 argc_ = static_cast<unsigned int>(argc); | |
52 argv_ = argv; | |
53 } | |
54 | |
55 void FunctionContext::CheckIndex(unsigned int index) const | |
56 { | |
57 if (index >= argc_) | |
58 { | |
59 | 59 throw OrthancException(ErrorCode_ParameterOutOfRange); |
0 | 60 } |
61 } | |
62 | |
63 ColumnType FunctionContext::GetColumnType(unsigned int index) const | |
64 { | |
65 CheckIndex(index); | |
66 return static_cast<SQLite::ColumnType>(sqlite3_value_type(argv_[index])); | |
67 } | |
68 | |
69 int FunctionContext::GetIntValue(unsigned int index) const | |
70 { | |
71 CheckIndex(index); | |
72 return sqlite3_value_int(argv_[index]); | |
73 } | |
74 | |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
75 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
|
76 { |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
77 CheckIndex(index); |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
78 return sqlite3_value_int64(argv_[index]); |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
79 } |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
80 |
0 | 81 double FunctionContext::GetDoubleValue(unsigned int index) const |
82 { | |
83 CheckIndex(index); | |
84 return sqlite3_value_double(argv_[index]); | |
85 } | |
86 | |
87 std::string FunctionContext::GetStringValue(unsigned int index) const | |
88 { | |
89 CheckIndex(index); | |
90 return std::string(reinterpret_cast<const char*>(sqlite3_value_text(argv_[index]))); | |
91 } | |
92 | |
93 void FunctionContext::SetNullResult() | |
94 { | |
95 sqlite3_result_null(context_); | |
96 } | |
97 | |
98 void FunctionContext::SetIntResult(int value) | |
99 { | |
100 sqlite3_result_int(context_, value); | |
101 } | |
102 | |
103 void FunctionContext::SetDoubleResult(double value) | |
104 { | |
105 sqlite3_result_double(context_, value); | |
106 } | |
107 | |
108 void FunctionContext::SetStringResult(const std::string& str) | |
109 { | |
110 sqlite3_result_text(context_, str.data(), str.size(), SQLITE_TRANSIENT); | |
111 } | |
112 } | |
113 } |