Mercurial > hg > orthanc
annotate Core/SQLite/FunctionContext.cpp @ 1397:704de8c30ff5
modularization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 01 Jun 2015 11:50:58 +0200 |
parents | 63d47b1fa239 |
children | f401dd90b35e |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
3 * |
1291
63d47b1fa239
upgrade to 2015 in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1220
diff
changeset
|
4 * Copyright (C) 2012-2015 Sebastien Jodogne <s.jodogne@gmail.com>, |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
5 * Medical Physics Department, CHU of Liege, Belgium |
0 | 6 * |
17 | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions are | |
9 * met: | |
0 | 10 * |
17 | 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. | |
0 | 32 **/ |
33 | |
34 | |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
35 #if ORTHANC_SQLITE_STANDALONE != 1 |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
694
diff
changeset
|
36 #include "../PrecompiledHeaders.h" |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
37 #endif |
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
38 |
0 | 39 #include "FunctionContext.h" |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
40 #include "OrthancSQLiteException.h" |
0 | 41 |
42 #include <sqlite3.h> | |
43 | |
59 | 44 namespace Orthanc |
0 | 45 { |
46 namespace SQLite | |
47 { | |
48 FunctionContext::FunctionContext(struct sqlite3_context* context, | |
49 int argc, | |
50 struct ::Mem** argv) | |
51 { | |
52 assert(context != NULL); | |
53 assert(argc >= 0); | |
54 assert(argv != NULL); | |
55 | |
56 context_ = context; | |
57 argc_ = static_cast<unsigned int>(argc); | |
58 argv_ = argv; | |
59 } | |
60 | |
61 void FunctionContext::CheckIndex(unsigned int index) const | |
62 { | |
63 if (index >= argc_) | |
64 { | |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
65 throw OrthancSQLiteException("Parameter out of range"); |
0 | 66 } |
67 } | |
68 | |
69 ColumnType FunctionContext::GetColumnType(unsigned int index) const | |
70 { | |
71 CheckIndex(index); | |
72 return static_cast<SQLite::ColumnType>(sqlite3_value_type(argv_[index])); | |
73 } | |
74 | |
75 int FunctionContext::GetIntValue(unsigned int index) const | |
76 { | |
77 CheckIndex(index); | |
78 return sqlite3_value_int(argv_[index]); | |
79 } | |
80 | |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
81 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
|
82 { |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
83 CheckIndex(index); |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
84 return sqlite3_value_int64(argv_[index]); |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
85 } |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
86 |
0 | 87 double FunctionContext::GetDoubleValue(unsigned int index) const |
88 { | |
89 CheckIndex(index); | |
90 return sqlite3_value_double(argv_[index]); | |
91 } | |
92 | |
93 std::string FunctionContext::GetStringValue(unsigned int index) const | |
94 { | |
95 CheckIndex(index); | |
96 return std::string(reinterpret_cast<const char*>(sqlite3_value_text(argv_[index]))); | |
97 } | |
694
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
98 |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
99 bool FunctionContext::IsNullValue(unsigned int index) const |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
100 { |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
101 CheckIndex(index); |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
102 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
|
103 } |
0 | 104 |
105 void FunctionContext::SetNullResult() | |
106 { | |
107 sqlite3_result_null(context_); | |
108 } | |
109 | |
110 void FunctionContext::SetIntResult(int value) | |
111 { | |
112 sqlite3_result_int(context_, value); | |
113 } | |
114 | |
115 void FunctionContext::SetDoubleResult(double value) | |
116 { | |
117 sqlite3_result_double(context_, value); | |
118 } | |
119 | |
120 void FunctionContext::SetStringResult(const std::string& str) | |
121 { | |
122 sqlite3_result_text(context_, str.data(), str.size(), SQLITE_TRANSIENT); | |
123 } | |
124 } | |
125 } |