Mercurial > hg > orthanc-webviewer
comparison Orthanc/Core/SQLite/FunctionContext.cpp @ 78:d6da56f86e5a
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Sep 2015 11:29:17 +0200 |
parents | |
children | 3809121c3290 |
comparison
equal
deleted
inserted
replaced
77:f44ebb25691c | 78:d6da56f86e5a |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * | |
4 * Copyright (C) 2012-2015 Sebastien Jodogne <s.jodogne@gmail.com>, | |
5 * Medical Physics Department, CHU of Liege, Belgium | |
6 * | |
7 * Redistribution and use in source and binary forms, with or without | |
8 * modification, are permitted provided that the following conditions are | |
9 * met: | |
10 * | |
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. | |
32 **/ | |
33 | |
34 | |
35 #if ORTHANC_SQLITE_STANDALONE != 1 | |
36 #include "../PrecompiledHeaders.h" | |
37 #endif | |
38 | |
39 #include "FunctionContext.h" | |
40 #include "OrthancSQLiteException.h" | |
41 | |
42 #include <string> | |
43 | |
44 #include "sqlite3.h" | |
45 | |
46 namespace Orthanc | |
47 { | |
48 namespace SQLite | |
49 { | |
50 FunctionContext::FunctionContext(struct sqlite3_context* context, | |
51 int argc, | |
52 struct ::Mem** argv) | |
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 { | |
67 throw OrthancSQLiteException(ErrorCode_ParameterOutOfRange); | |
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 | |
83 int64_t FunctionContext::GetInt64Value(unsigned int index) const | |
84 { | |
85 CheckIndex(index); | |
86 return sqlite3_value_int64(argv_[index]); | |
87 } | |
88 | |
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 } | |
100 | |
101 bool FunctionContext::IsNullValue(unsigned int index) const | |
102 { | |
103 CheckIndex(index); | |
104 return sqlite3_value_type(argv_[index]) == SQLITE_NULL; | |
105 } | |
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 { | |
124 sqlite3_result_text(context_, str.data(), str.size(), SQLITE_TRANSIENT); | |
125 } | |
126 } | |
127 } |