0
|
1 /**
|
|
2 * Palantir - A Lightweight, RESTful DICOM Store
|
|
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
|
|
4 * Belgium
|
|
5 *
|
|
6 * This program is free software: you can redistribute it and/or
|
|
7 * modify it under the terms of the GNU General Public License as
|
|
8 * published by the Free Software Foundation, either version 3 of the
|
|
9 * License, or (at your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful, but
|
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 * General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18 **/
|
|
19
|
|
20
|
|
21 #include "FunctionContext.h"
|
|
22
|
|
23 #include <sqlite3.h>
|
|
24
|
|
25 namespace Palantir
|
|
26 {
|
|
27 namespace SQLite
|
|
28 {
|
|
29 FunctionContext::FunctionContext(struct sqlite3_context* context,
|
|
30 int argc,
|
|
31 struct ::Mem** argv)
|
|
32 {
|
|
33 assert(context != NULL);
|
|
34 assert(argc >= 0);
|
|
35 assert(argv != NULL);
|
|
36
|
|
37 context_ = context;
|
|
38 argc_ = static_cast<unsigned int>(argc);
|
|
39 argv_ = argv;
|
|
40 }
|
|
41
|
|
42 void FunctionContext::CheckIndex(unsigned int index) const
|
|
43 {
|
|
44 if (index >= argc_)
|
|
45 {
|
|
46 throw PalantirException(ErrorCode_ParameterOutOfRange);
|
|
47 }
|
|
48 }
|
|
49
|
|
50 ColumnType FunctionContext::GetColumnType(unsigned int index) const
|
|
51 {
|
|
52 CheckIndex(index);
|
|
53 return static_cast<SQLite::ColumnType>(sqlite3_value_type(argv_[index]));
|
|
54 }
|
|
55
|
|
56 int FunctionContext::GetIntValue(unsigned int index) const
|
|
57 {
|
|
58 CheckIndex(index);
|
|
59 return sqlite3_value_int(argv_[index]);
|
|
60 }
|
|
61
|
|
62 double FunctionContext::GetDoubleValue(unsigned int index) const
|
|
63 {
|
|
64 CheckIndex(index);
|
|
65 return sqlite3_value_double(argv_[index]);
|
|
66 }
|
|
67
|
|
68 std::string FunctionContext::GetStringValue(unsigned int index) const
|
|
69 {
|
|
70 CheckIndex(index);
|
|
71 return std::string(reinterpret_cast<const char*>(sqlite3_value_text(argv_[index])));
|
|
72 }
|
|
73
|
|
74 void FunctionContext::SetNullResult()
|
|
75 {
|
|
76 sqlite3_result_null(context_);
|
|
77 }
|
|
78
|
|
79 void FunctionContext::SetIntResult(int value)
|
|
80 {
|
|
81 sqlite3_result_int(context_, value);
|
|
82 }
|
|
83
|
|
84 void FunctionContext::SetDoubleResult(double value)
|
|
85 {
|
|
86 sqlite3_result_double(context_, value);
|
|
87 }
|
|
88
|
|
89 void FunctionContext::SetStringResult(const std::string& str)
|
|
90 {
|
|
91 sqlite3_result_text(context_, str.data(), str.size(), SQLITE_TRANSIENT);
|
|
92 }
|
|
93 }
|
|
94 }
|