0
|
1 /**
|
|
2 * Palantir - A Lightweight, RESTful DICOM Store
|
|
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
|
|
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
|
|
38 namespace Palantir
|
|
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 throw PalantirException(ErrorCode_ParameterOutOfRange);
|
|
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
|
|
75 double FunctionContext::GetDoubleValue(unsigned int index) const
|
|
76 {
|
|
77 CheckIndex(index);
|
|
78 return sqlite3_value_double(argv_[index]);
|
|
79 }
|
|
80
|
|
81 std::string FunctionContext::GetStringValue(unsigned int index) const
|
|
82 {
|
|
83 CheckIndex(index);
|
|
84 return std::string(reinterpret_cast<const char*>(sqlite3_value_text(argv_[index])));
|
|
85 }
|
|
86
|
|
87 void FunctionContext::SetNullResult()
|
|
88 {
|
|
89 sqlite3_result_null(context_);
|
|
90 }
|
|
91
|
|
92 void FunctionContext::SetIntResult(int value)
|
|
93 {
|
|
94 sqlite3_result_int(context_, value);
|
|
95 }
|
|
96
|
|
97 void FunctionContext::SetDoubleResult(double value)
|
|
98 {
|
|
99 sqlite3_result_double(context_, value);
|
|
100 }
|
|
101
|
|
102 void FunctionContext::SetStringResult(const std::string& str)
|
|
103 {
|
|
104 sqlite3_result_text(context_, str.data(), str.size(), SQLITE_TRANSIENT);
|
|
105 }
|
|
106 }
|
|
107 }
|