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