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