Mercurial > hg > orthanc
annotate Core/SQLite/FunctionContext.cpp @ 823:da4c30a8bcdd templating
plustache
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 May 2014 16:21:48 +0200 |
parents | 72dc919a028c |
children | a811bdf8b8eb |
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 | |
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 } | |
694
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
92 |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
93 bool FunctionContext::IsNullValue(unsigned int index) const |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
94 { |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
95 CheckIndex(index); |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
96 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
|
97 } |
0 | 98 |
99 void FunctionContext::SetNullResult() | |
100 { | |
101 sqlite3_result_null(context_); | |
102 } | |
103 | |
104 void FunctionContext::SetIntResult(int value) | |
105 { | |
106 sqlite3_result_int(context_, value); | |
107 } | |
108 | |
109 void FunctionContext::SetDoubleResult(double value) | |
110 { | |
111 sqlite3_result_double(context_, value); | |
112 } | |
113 | |
114 void FunctionContext::SetStringResult(const std::string& str) | |
115 { | |
116 sqlite3_result_text(context_, str.data(), str.size(), SQLITE_TRANSIENT); | |
117 } | |
118 } | |
119 } |