Mercurial > hg > orthanc
annotate Core/SQLite/FunctionContext.cpp @ 893:f57802f8b4dc plugins
plugins for windows
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Jun 2014 16:14:56 +0200 |
parents | a811bdf8b8eb |
children | 9b9026560a5f |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
689 | 3 * Copyright (C) 2012-2014 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 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
694
diff
changeset
|
34 #include "../PrecompiledHeaders.h" |
0 | 35 #include "FunctionContext.h" |
36 | |
37 #include <sqlite3.h> | |
38 | |
59 | 39 namespace Orthanc |
0 | 40 { |
41 namespace SQLite | |
42 { | |
43 FunctionContext::FunctionContext(struct sqlite3_context* context, | |
44 int argc, | |
45 struct ::Mem** argv) | |
46 { | |
47 assert(context != NULL); | |
48 assert(argc >= 0); | |
49 assert(argv != NULL); | |
50 | |
51 context_ = context; | |
52 argc_ = static_cast<unsigned int>(argc); | |
53 argv_ = argv; | |
54 } | |
55 | |
56 void FunctionContext::CheckIndex(unsigned int index) const | |
57 { | |
58 if (index >= argc_) | |
59 { | |
59 | 60 throw OrthancException(ErrorCode_ParameterOutOfRange); |
0 | 61 } |
62 } | |
63 | |
64 ColumnType FunctionContext::GetColumnType(unsigned int index) const | |
65 { | |
66 CheckIndex(index); | |
67 return static_cast<SQLite::ColumnType>(sqlite3_value_type(argv_[index])); | |
68 } | |
69 | |
70 int FunctionContext::GetIntValue(unsigned int index) const | |
71 { | |
72 CheckIndex(index); | |
73 return sqlite3_value_int(argv_[index]); | |
74 } | |
75 | |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
76 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
|
77 { |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
78 CheckIndex(index); |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
79 return sqlite3_value_int64(argv_[index]); |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
80 } |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
81 |
0 | 82 double FunctionContext::GetDoubleValue(unsigned int index) const |
83 { | |
84 CheckIndex(index); | |
85 return sqlite3_value_double(argv_[index]); | |
86 } | |
87 | |
88 std::string FunctionContext::GetStringValue(unsigned int index) const | |
89 { | |
90 CheckIndex(index); | |
91 return std::string(reinterpret_cast<const char*>(sqlite3_value_text(argv_[index]))); | |
92 } | |
694
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
93 |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
94 bool FunctionContext::IsNullValue(unsigned int index) const |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
95 { |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
96 CheckIndex(index); |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
97 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
|
98 } |
0 | 99 |
100 void FunctionContext::SetNullResult() | |
101 { | |
102 sqlite3_result_null(context_); | |
103 } | |
104 | |
105 void FunctionContext::SetIntResult(int value) | |
106 { | |
107 sqlite3_result_int(context_, value); | |
108 } | |
109 | |
110 void FunctionContext::SetDoubleResult(double value) | |
111 { | |
112 sqlite3_result_double(context_, value); | |
113 } | |
114 | |
115 void FunctionContext::SetStringResult(const std::string& str) | |
116 { | |
117 sqlite3_result_text(context_, str.data(), str.size(), SQLITE_TRANSIENT); | |
118 } | |
119 } | |
120 } |