Mercurial > hg > orthanc
annotate OrthancFramework/UnitTestsSources/SQLiteTests.cpp @ 5319:f2e1ad71e49c
added "OrthancPluginLoadDicomInstance()" to load DICOM instances from the database
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 24 Jun 2023 12:18:58 +0200 |
parents | 0ea402b4d901 |
children | 48b8dae6dc77 |
rev | line source |
---|---|
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
1 /** |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
7 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
11 * the License, or (at your option) any later version. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
12 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
16 * Lesser General Public License for more details. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
21 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
22 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
23 |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
24 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1 |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
25 // Must be the first to be sure to use the Orthanc framework shared library |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3992
diff
changeset
|
26 # include <OrthancFramework.h> |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
27 #endif |
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
28 |
4062 | 29 #include <gtest/gtest.h> |
0 | 30 |
4045 | 31 #include "../Sources/SystemToolbox.h" |
32 #include "../Sources/SQLite/Connection.h" | |
33 #include "../Sources/SQLite/Statement.h" | |
34 #include "../Sources/SQLite/Transaction.h" | |
0 | 35 |
36 #include <sqlite3.h> | |
37 | |
63 | 38 using namespace Orthanc; |
0 | 39 |
40 | |
41 TEST(SQLite, Configuration) | |
42 { | |
1476 | 43 /** |
44 * The system-wide version of SQLite under OS X uses | |
45 * SQLITE_THREADSAFE==2 (SQLITE_CONFIG_SERIALIZED), whereas the | |
46 * static builds of Orthanc use SQLITE_THREADSAFE==1 | |
47 * (SQLITE_CONFIG_MULTITHREAD). In any case, we wish to ensure that | |
48 * SQLITE_THREADSAFE!=0 (SQLITE_CONFIG_SINGLETHREAD). | |
49 **/ | |
50 ASSERT_NE(0, sqlite3_threadsafe()); | |
0 | 51 } |
52 | |
53 | |
54 TEST(SQLite, Connection) | |
55 { | |
2140 | 56 SystemToolbox::RemoveFile("UnitTestsResults/coucou"); |
0 | 57 SQLite::Connection c; |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
724
diff
changeset
|
58 c.Open("UnitTestsResults/coucou"); |
0 | 59 c.Execute("CREATE TABLE c(k INTEGER PRIMARY KEY AUTOINCREMENT, v INTEGER)"); |
60 c.Execute("INSERT INTO c VALUES(NULL, 42);"); | |
61 } | |
62 | |
63 | |
64 TEST(SQLite, StatementReferenceBasic) | |
65 { | |
66 sqlite3* db; | |
67 sqlite3_open(":memory:", &db); | |
68 | |
69 { | |
70 SQLite::StatementReference r(db, "SELECT * FROM sqlite_master"); | |
71 ASSERT_EQ(0u, r.GetReferenceCount()); | |
72 | |
73 { | |
74 SQLite::StatementReference r1(r); | |
75 ASSERT_EQ(1u, r.GetReferenceCount()); | |
76 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
77 | |
78 { | |
79 SQLite::StatementReference r2(r); | |
80 ASSERT_EQ(2u, r.GetReferenceCount()); | |
81 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
82 ASSERT_EQ(0u, r2.GetReferenceCount()); | |
83 | |
84 SQLite::StatementReference r3(r2); | |
85 ASSERT_EQ(3u, r.GetReferenceCount()); | |
86 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
87 ASSERT_EQ(0u, r2.GetReferenceCount()); | |
88 ASSERT_EQ(0u, r3.GetReferenceCount()); | |
89 } | |
90 | |
91 ASSERT_EQ(1u, r.GetReferenceCount()); | |
92 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
93 | |
94 { | |
95 SQLite::StatementReference r2(r); | |
96 ASSERT_EQ(2u, r.GetReferenceCount()); | |
97 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
98 ASSERT_EQ(0u, r2.GetReferenceCount()); | |
99 } | |
100 | |
101 ASSERT_EQ(1u, r.GetReferenceCount()); | |
102 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
103 } | |
104 | |
105 ASSERT_EQ(0u, r.GetReferenceCount()); | |
106 } | |
107 | |
108 sqlite3_close(db); | |
109 } | |
110 | |
111 TEST(SQLite, StatementBasic) | |
112 { | |
113 SQLite::Connection c; | |
114 c.OpenInMemory(); | |
115 | |
116 SQLite::Statement s(c, "SELECT * from sqlite_master"); | |
117 s.Run(); | |
118 | |
119 for (unsigned int i = 0; i < 5; i++) | |
120 { | |
121 SQLite::Statement cs(c, SQLITE_FROM_HERE, "SELECT * from sqlite_master"); | |
122 cs.Step(); | |
123 } | |
124 } | |
125 | |
126 | |
127 namespace | |
128 { | |
129 static bool destroyed; | |
130 | |
131 class MyFunc : public SQLite::IScalarFunction | |
132 { | |
133 public: | |
134 MyFunc() | |
135 { | |
136 destroyed = false; | |
137 } | |
138 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
139 virtual ~MyFunc() ORTHANC_OVERRIDE |
0 | 140 { |
141 destroyed = true; | |
142 } | |
143 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
144 virtual const char* GetName() const ORTHANC_OVERRIDE |
0 | 145 { |
146 return "MYFUNC"; | |
147 } | |
148 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
149 virtual unsigned int GetCardinality() const ORTHANC_OVERRIDE |
0 | 150 { |
151 return 2; | |
152 } | |
153 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
154 virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE |
0 | 155 { |
156 context.SetIntResult(1000 + context.GetIntValue(0) * context.GetIntValue(1)); | |
157 } | |
158 }; | |
159 | |
160 class MyDelete : public SQLite::IScalarFunction | |
161 { | |
162 public: | |
163 std::set<int> deleted_; | |
164 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
165 virtual const char* GetName() const ORTHANC_OVERRIDE |
0 | 166 { |
167 return "MYDELETE"; | |
168 } | |
169 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
170 virtual unsigned int GetCardinality() const ORTHANC_OVERRIDE |
0 | 171 { |
172 return 1; | |
173 } | |
174 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
175 virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE |
0 | 176 { |
177 deleted_.insert(context.GetIntValue(0)); | |
178 context.SetNullResult(); | |
179 } | |
180 }; | |
181 } | |
182 | |
183 TEST(SQLite, ScalarFunction) | |
184 { | |
185 { | |
186 SQLite::Connection c; | |
187 c.OpenInMemory(); | |
188 c.Register(new MyFunc()); | |
189 c.Execute("CREATE TABLE t(id INTEGER PRIMARY KEY, v1 INTEGER, v2 INTEGER);"); | |
190 c.Execute("INSERT INTO t VALUES(NULL, 2, 3);"); | |
191 c.Execute("INSERT INTO t VALUES(NULL, 4, 4);"); | |
192 c.Execute("INSERT INTO t VALUES(NULL, 6, 5);"); | |
193 SQLite::Statement t(c, "SELECT MYFUNC(v1, v2), v1, v2 FROM t"); | |
194 int i = 0; | |
195 while (t.Step()) | |
196 { | |
197 ASSERT_EQ(t.ColumnInt(0), 1000 + t.ColumnInt(1) * t.ColumnInt(2)); | |
198 i++; | |
199 } | |
200 ASSERT_EQ(3, i); | |
201 ASSERT_FALSE(destroyed); | |
202 } | |
203 ASSERT_TRUE(destroyed); | |
204 } | |
205 | |
206 TEST(SQLite, CascadedDeleteCallback) | |
207 { | |
208 SQLite::Connection c; | |
209 c.OpenInMemory(); | |
210 MyDelete *func = new MyDelete(); | |
211 c.Register(func); | |
212 c.Execute("CREATE TABLE parent(id INTEGER PRIMARY KEY, dummy INTEGER);"); | |
213 c.Execute("CREATE TABLE child(" | |
214 " id INTEGER PRIMARY KEY, " | |
215 " parent INTEGER REFERENCES parent(id) ON DELETE CASCADE, " | |
216 " value INTEGER);"); | |
217 c.Execute("CREATE TRIGGER childRemoved " | |
218 "AFTER DELETE ON child " | |
219 "FOR EACH ROW BEGIN " | |
220 " SELECT MYDELETE(old.value); " | |
221 "END;"); | |
222 | |
223 c.Execute("INSERT INTO parent VALUES(42, 100);"); | |
224 c.Execute("INSERT INTO parent VALUES(43, 101);"); | |
225 | |
226 c.Execute("INSERT INTO child VALUES(NULL, 42, 4200);"); | |
227 c.Execute("INSERT INTO child VALUES(NULL, 42, 4201);"); | |
228 | |
229 c.Execute("INSERT INTO child VALUES(NULL, 43, 4300);"); | |
230 c.Execute("INSERT INTO child VALUES(NULL, 43, 4301);"); | |
231 | |
232 // The following command deletes "parent(43, 101)", then in turns | |
233 // "child(NULL, 43, 4300/4301)", then calls the MyDelete on 4300 and | |
234 // 4301 | |
235 c.Execute("DELETE FROM parent WHERE dummy=101"); | |
236 | |
237 ASSERT_EQ(2u, func->deleted_.size()); | |
238 ASSERT_TRUE(func->deleted_.find(4300) != func->deleted_.end()); | |
239 ASSERT_TRUE(func->deleted_.find(4301) != func->deleted_.end()); | |
240 } | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
241 |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
242 |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
243 TEST(SQLite, EmptyTransactions) |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
244 { |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
245 try |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
246 { |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
247 SQLite::Connection c; |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
248 c.OpenInMemory(); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
249 |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
250 c.Execute("CREATE TABLE a(id INTEGER PRIMARY KEY);"); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
251 c.Execute("INSERT INTO a VALUES(NULL)"); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
252 |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
253 { |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
254 SQLite::Transaction t(c); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
255 t.Begin(); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
256 { |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
257 SQLite::Statement s(c, SQLITE_FROM_HERE, "SELECT * FROM a"); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
258 s.Step(); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
259 } |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
260 //t.Commit(); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
261 } |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
262 |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
263 { |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
264 SQLite::Statement s(c, SQLITE_FROM_HERE, "SELECT * FROM a"); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
265 s.Step(); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
266 } |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
267 } |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
268 catch (OrthancException& e) |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
269 { |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
270 fprintf(stderr, "Exception: [%s]\n", e.What()); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
271 throw e; |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
272 } |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
273 } |
724 | 274 |
275 | |
276 TEST(SQLite, Types) | |
277 { | |
278 SQLite::Connection c; | |
279 c.OpenInMemory(); | |
280 c.Execute("CREATE TABLE a(id INTEGER PRIMARY KEY, value)"); | |
281 | |
282 { | |
283 SQLite::Statement s(c, std::string("SELECT * FROM a")); | |
284 ASSERT_EQ(2, s.ColumnCount()); | |
285 ASSERT_FALSE(s.Step()); | |
286 } | |
287 | |
288 { | |
289 SQLite::Statement s(c, SQLITE_FROM_HERE, std::string("SELECT * FROM a")); | |
290 ASSERT_FALSE(s.Step()); | |
291 ASSERT_EQ("SELECT * FROM a", s.GetOriginalSQLStatement()); | |
292 } | |
293 | |
294 { | |
295 SQLite::Statement s(c, SQLITE_FROM_HERE, "INSERT INTO a VALUES(NULL, ?);"); | |
296 s.BindNull(0); ASSERT_TRUE(s.Run()); s.Reset(); | |
297 s.BindBool(0, true); ASSERT_TRUE(s.Run()); s.Reset(); | |
298 s.BindInt(0, 42); ASSERT_TRUE(s.Run()); s.Reset(); | |
299 s.BindInt64(0, 42ll); ASSERT_TRUE(s.Run()); s.Reset(); | |
300 s.BindDouble(0, 42.5); ASSERT_TRUE(s.Run()); s.Reset(); | |
301 s.BindCString(0, "Hello"); ASSERT_TRUE(s.Run()); s.Reset(); | |
302 s.BindBlob(0, "Hello", 5); ASSERT_TRUE(s.Run()); s.Reset(); | |
303 } | |
304 | |
305 { | |
306 SQLite::Statement s(c, SQLITE_FROM_HERE, std::string("SELECT * FROM a")); | |
307 ASSERT_TRUE(s.Step()); | |
308 ASSERT_EQ(SQLite::COLUMN_TYPE_NULL, s.GetColumnType(1)); | |
309 ASSERT_TRUE(s.ColumnIsNull(1)); | |
310 ASSERT_TRUE(s.Step()); | |
311 ASSERT_EQ(SQLite::COLUMN_TYPE_INTEGER, s.GetColumnType(1)); | |
312 ASSERT_TRUE(s.ColumnBool(1)); | |
313 ASSERT_TRUE(s.Step()); | |
314 ASSERT_EQ(SQLite::COLUMN_TYPE_INTEGER, s.GetColumnType(1)); | |
315 ASSERT_EQ(42, s.ColumnInt(1)); | |
316 ASSERT_TRUE(s.Step()); | |
317 ASSERT_EQ(SQLite::COLUMN_TYPE_INTEGER, s.GetColumnType(1)); | |
318 ASSERT_EQ(42ll, s.ColumnInt64(1)); | |
319 ASSERT_TRUE(s.Step()); | |
320 ASSERT_EQ(SQLite::COLUMN_TYPE_FLOAT, s.GetColumnType(1)); | |
876 | 321 ASSERT_DOUBLE_EQ(42.5, s.ColumnDouble(1)); |
724 | 322 ASSERT_TRUE(s.Step()); |
323 ASSERT_EQ(SQLite::COLUMN_TYPE_TEXT, s.GetColumnType(1)); | |
324 ASSERT_EQ("Hello", s.ColumnString(1)); | |
325 ASSERT_TRUE(s.Step()); | |
326 ASSERT_EQ(SQLite::COLUMN_TYPE_BLOB, s.GetColumnType(1)); | |
327 ASSERT_EQ(5, s.ColumnByteLength(1)); | |
328 ASSERT_TRUE(!memcmp("Hello", s.ColumnBlob(1), 5)); | |
329 | |
330 std::string t; | |
331 ASSERT_TRUE(s.ColumnBlobAsString(1, &t)); | |
332 ASSERT_EQ("Hello", t); | |
333 | |
334 ASSERT_FALSE(s.Step()); | |
335 } | |
336 } |