Mercurial > hg > orthanc
annotate OrthancFramework/Sources/SQLite/Statement.h @ 4829:c847b0dfd255
added missing copyright headers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Nov 2021 18:53:08 +0100 |
parents | 50b0c69b653a |
children | 7053502fbf97 |
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:
724
diff
changeset
|
3 * |
3063 | 4 * Copyright (C) 2012-2016 Sebastien Jodogne <s.jodogne@orthanc-labs.com>, |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
724
diff
changeset
|
5 * Medical Physics Department, CHU of Liege, Belgium |
4829
c847b0dfd255
added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
6 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 7 * |
17 | 8 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
9 * | |
10 * Redistribution and use in source and binary forms, with or without | |
11 * modification, are permitted provided that the following conditions are | |
12 * met: | |
0 | 13 * |
17 | 14 * * Redistributions of source code must retain the above copyright |
15 * notice, this list of conditions and the following disclaimer. | |
16 * * Redistributions in binary form must reproduce the above | |
17 * copyright notice, this list of conditions and the following disclaimer | |
18 * in the documentation and/or other materials provided with the | |
19 * distribution. | |
20 * * Neither the name of Google Inc., the name of the CHU of Liege, | |
21 * nor the names of its contributors may be used to endorse or promote | |
22 * products derived from this software without specific prior written | |
23 * permission. | |
24 * | |
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
0 | 36 **/ |
37 | |
38 | |
39 #pragma once | |
40 | |
1221
2255e66da726
getting rid of the dependency against Boost in the SQLite C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1220
diff
changeset
|
41 #include "NonCopyable.h" |
1220
9b9026560a5f
SQLite wrapper is now fully independent of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
724
diff
changeset
|
42 #include "OrthancSQLiteException.h" |
0 | 43 #include "StatementId.h" |
44 #include "StatementReference.h" | |
45 | |
46 #include <vector> | |
47 #include <stdint.h> | |
265 | 48 |
49 #if ORTHANC_BUILD_UNIT_TESTS == 1 | |
2388
50cde8246542
CMake to build the Orthanc framework without the Orthanc server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2302
diff
changeset
|
50 # include <gtest/gtest_prod.h> |
265 | 51 #endif |
0 | 52 |
53 | |
59 | 54 namespace Orthanc |
0 | 55 { |
56 namespace SQLite | |
57 { | |
58 class Connection; | |
59 | |
60 // Possible return values from ColumnType in a statement. These | |
61 // should match the values in sqlite3.h. | |
62 enum ColumnType | |
63 { | |
64 COLUMN_TYPE_INTEGER = 1, | |
65 COLUMN_TYPE_FLOAT = 2, | |
66 COLUMN_TYPE_TEXT = 3, | |
67 COLUMN_TYPE_BLOB = 4, | |
68 COLUMN_TYPE_NULL = 5 | |
69 }; | |
70 | |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3063
diff
changeset
|
71 class ORTHANC_PUBLIC Statement : public NonCopyable |
0 | 72 { |
73 friend class Connection; | |
265 | 74 |
75 #if ORTHANC_BUILD_UNIT_TESTS == 1 | |
138 | 76 FRIEND_TEST(SQLStatementTest, Run); |
77 FRIEND_TEST(SQLStatementTest, Reset); | |
265 | 78 #endif |
0 | 79 |
80 private: | |
81 StatementReference reference_; | |
82 | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1291
diff
changeset
|
83 int CheckError(int err, |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1291
diff
changeset
|
84 ErrorCode code) const; |
0 | 85 |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1291
diff
changeset
|
86 void CheckOk(int err, |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1291
diff
changeset
|
87 ErrorCode code) const; |
0 | 88 |
89 struct sqlite3_stmt* GetStatement() const | |
90 { | |
91 return reference_.GetWrappedObject(); | |
92 } | |
93 | |
94 public: | |
95 Statement(Connection& database, | |
96 const std::string& sql); | |
97 | |
98 Statement(Connection& database, | |
99 const StatementId& id, | |
100 const std::string& sql); | |
101 | |
102 Statement(Connection& database, | |
103 const char* sql); | |
104 | |
105 Statement(Connection& database, | |
106 const StatementId& id, | |
107 const char* sql); | |
108 | |
4304 | 109 ~Statement(); |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
110 |
0 | 111 bool Run(); |
112 | |
113 bool Step(); | |
114 | |
115 // Diagnostics -------------------------------------------------------------- | |
116 | |
117 std::string GetOriginalSQLStatement(); | |
118 | |
119 | |
120 // Binding ------------------------------------------------------------------- | |
121 | |
122 // These all take a 0-based argument index | |
123 void BindNull(int col); | |
124 void BindBool(int col, bool val); | |
125 void BindInt(int col, int val); | |
126 void BindInt64(int col, int64_t val); | |
127 void BindDouble(int col, double val); | |
128 void BindCString(int col, const char* val); | |
129 void BindString(int col, const std::string& val); | |
130 //void BindString16(int col, const string16& value); | |
131 void BindBlob(int col, const void* value, int value_len); | |
132 | |
133 | |
134 // Retrieving ---------------------------------------------------------------- | |
135 | |
136 // Returns the number of output columns in the result. | |
137 int ColumnCount() const; | |
138 | |
139 // Returns the type associated with the given column. | |
140 // | |
141 // Watch out: the type may be undefined if you've done something to cause a | |
142 // "type conversion." This means requesting the value of a column of a type | |
143 // where that type is not the native type. For safety, call ColumnType only | |
144 // on a column before getting the value out in any way. | |
145 ColumnType GetColumnType(int col) const; | |
146 ColumnType GetDeclaredColumnType(int col) const; | |
147 | |
148 // These all take a 0-based argument index. | |
80 | 149 bool ColumnIsNull(int col) const ; |
0 | 150 bool ColumnBool(int col) const; |
151 int ColumnInt(int col) const; | |
152 int64_t ColumnInt64(int col) const; | |
153 double ColumnDouble(int col) const; | |
154 std::string ColumnString(int col) const; | |
155 //string16 ColumnString16(int col) const; | |
156 | |
157 // When reading a blob, you can get a raw pointer to the underlying data, | |
158 // along with the length, or you can just ask us to copy the blob into a | |
159 // vector. Danger! ColumnBlob may return NULL if there is no data! | |
160 int ColumnByteLength(int col) const; | |
161 const void* ColumnBlob(int col) const; | |
162 bool ColumnBlobAsString(int col, std::string* blob); | |
163 //bool ColumnBlobAsString16(int col, string16* val) const; | |
724 | 164 //bool ColumnBlobAsVector(int col, std::vector<char>* val) const; |
165 //bool ColumnBlobAsVector(int col, std::vector<unsigned char>* val) const; | |
0 | 166 |
724 | 167 // Resets the statement to its initial condition. This includes any current |
168 // result row, and also the bound variables if the |clear_bound_vars| is true. | |
169 void Reset(bool clear_bound_vars = true); | |
0 | 170 }; |
171 } | |
172 } |