Mercurial > hg > orthanc
annotate UnitTestsSources/SQLiteTests.cpp @ 3739:a35fb06514e7 storage-commitment
integration mainline->storage-commitment
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Mar 2020 20:54:33 +0100 |
parents | 94f4a18a79cc |
children | f9863630ec7f |
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 |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
6 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
10 * License, or (at your option) any later version. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
11 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
13 * program give permission to link the code of its release with the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
22 * in the program, then also delete it here. |
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 * 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
|
25 * 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
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
27 * General Public License for more details. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
28 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
31 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
32 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
33 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
827
diff
changeset
|
34 #include "PrecompiledHeadersUnitTests.h" |
0 | 35 #include "gtest/gtest.h" |
36 | |
2143
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
37 #include "../Core/SystemToolbox.h" |
0 | 38 #include "../Core/SQLite/Connection.h" |
39 #include "../Core/SQLite/Statement.h" | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
40 #include "../Core/SQLite/Transaction.h" |
0 | 41 |
42 #include <sqlite3.h> | |
43 | |
63 | 44 using namespace Orthanc; |
0 | 45 |
46 | |
47 TEST(SQLite, Configuration) | |
48 { | |
1476 | 49 /** |
50 * The system-wide version of SQLite under OS X uses | |
51 * SQLITE_THREADSAFE==2 (SQLITE_CONFIG_SERIALIZED), whereas the | |
52 * static builds of Orthanc use SQLITE_THREADSAFE==1 | |
53 * (SQLITE_CONFIG_MULTITHREAD). In any case, we wish to ensure that | |
54 * SQLITE_THREADSAFE!=0 (SQLITE_CONFIG_SINGLETHREAD). | |
55 **/ | |
56 ASSERT_NE(0, sqlite3_threadsafe()); | |
0 | 57 } |
58 | |
59 | |
60 TEST(SQLite, Connection) | |
61 { | |
2140 | 62 SystemToolbox::RemoveFile("UnitTestsResults/coucou"); |
0 | 63 SQLite::Connection c; |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
724
diff
changeset
|
64 c.Open("UnitTestsResults/coucou"); |
0 | 65 c.Execute("CREATE TABLE c(k INTEGER PRIMARY KEY AUTOINCREMENT, v INTEGER)"); |
66 c.Execute("INSERT INTO c VALUES(NULL, 42);"); | |
67 } | |
68 | |
69 | |
70 TEST(SQLite, StatementReferenceBasic) | |
71 { | |
72 sqlite3* db; | |
73 sqlite3_open(":memory:", &db); | |
74 | |
75 { | |
76 SQLite::StatementReference r(db, "SELECT * FROM sqlite_master"); | |
77 ASSERT_EQ(0u, r.GetReferenceCount()); | |
78 | |
79 { | |
80 SQLite::StatementReference r1(r); | |
81 ASSERT_EQ(1u, r.GetReferenceCount()); | |
82 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
83 | |
84 { | |
85 SQLite::StatementReference r2(r); | |
86 ASSERT_EQ(2u, r.GetReferenceCount()); | |
87 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
88 ASSERT_EQ(0u, r2.GetReferenceCount()); | |
89 | |
90 SQLite::StatementReference r3(r2); | |
91 ASSERT_EQ(3u, r.GetReferenceCount()); | |
92 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
93 ASSERT_EQ(0u, r2.GetReferenceCount()); | |
94 ASSERT_EQ(0u, r3.GetReferenceCount()); | |
95 } | |
96 | |
97 ASSERT_EQ(1u, r.GetReferenceCount()); | |
98 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
99 | |
100 { | |
101 SQLite::StatementReference r2(r); | |
102 ASSERT_EQ(2u, r.GetReferenceCount()); | |
103 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
104 ASSERT_EQ(0u, r2.GetReferenceCount()); | |
105 } | |
106 | |
107 ASSERT_EQ(1u, r.GetReferenceCount()); | |
108 ASSERT_EQ(0u, r1.GetReferenceCount()); | |
109 } | |
110 | |
111 ASSERT_EQ(0u, r.GetReferenceCount()); | |
112 } | |
113 | |
114 sqlite3_close(db); | |
115 } | |
116 | |
117 TEST(SQLite, StatementBasic) | |
118 { | |
119 SQLite::Connection c; | |
120 c.OpenInMemory(); | |
121 | |
122 SQLite::Statement s(c, "SELECT * from sqlite_master"); | |
123 s.Run(); | |
124 | |
125 for (unsigned int i = 0; i < 5; i++) | |
126 { | |
127 SQLite::Statement cs(c, SQLITE_FROM_HERE, "SELECT * from sqlite_master"); | |
128 cs.Step(); | |
129 } | |
130 } | |
131 | |
132 | |
133 namespace | |
134 { | |
135 static bool destroyed; | |
136 | |
137 class MyFunc : public SQLite::IScalarFunction | |
138 { | |
139 public: | |
140 MyFunc() | |
141 { | |
142 destroyed = false; | |
143 } | |
144 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
145 virtual ~MyFunc() ORTHANC_OVERRIDE |
0 | 146 { |
147 destroyed = true; | |
148 } | |
149 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
150 virtual const char* GetName() const ORTHANC_OVERRIDE |
0 | 151 { |
152 return "MYFUNC"; | |
153 } | |
154 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
155 virtual unsigned int GetCardinality() const ORTHANC_OVERRIDE |
0 | 156 { |
157 return 2; | |
158 } | |
159 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
160 virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE |
0 | 161 { |
162 context.SetIntResult(1000 + context.GetIntValue(0) * context.GetIntValue(1)); | |
163 } | |
164 }; | |
165 | |
166 class MyDelete : public SQLite::IScalarFunction | |
167 { | |
168 public: | |
169 std::set<int> deleted_; | |
170 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
171 virtual const char* GetName() const ORTHANC_OVERRIDE |
0 | 172 { |
173 return "MYDELETE"; | |
174 } | |
175 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
176 virtual unsigned int GetCardinality() const ORTHANC_OVERRIDE |
0 | 177 { |
178 return 1; | |
179 } | |
180 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
181 virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE |
0 | 182 { |
183 deleted_.insert(context.GetIntValue(0)); | |
184 context.SetNullResult(); | |
185 } | |
186 }; | |
187 } | |
188 | |
189 TEST(SQLite, ScalarFunction) | |
190 { | |
191 { | |
192 SQLite::Connection c; | |
193 c.OpenInMemory(); | |
194 c.Register(new MyFunc()); | |
195 c.Execute("CREATE TABLE t(id INTEGER PRIMARY KEY, v1 INTEGER, v2 INTEGER);"); | |
196 c.Execute("INSERT INTO t VALUES(NULL, 2, 3);"); | |
197 c.Execute("INSERT INTO t VALUES(NULL, 4, 4);"); | |
198 c.Execute("INSERT INTO t VALUES(NULL, 6, 5);"); | |
199 SQLite::Statement t(c, "SELECT MYFUNC(v1, v2), v1, v2 FROM t"); | |
200 int i = 0; | |
201 while (t.Step()) | |
202 { | |
203 ASSERT_EQ(t.ColumnInt(0), 1000 + t.ColumnInt(1) * t.ColumnInt(2)); | |
204 i++; | |
205 } | |
206 ASSERT_EQ(3, i); | |
207 ASSERT_FALSE(destroyed); | |
208 } | |
209 ASSERT_TRUE(destroyed); | |
210 } | |
211 | |
212 TEST(SQLite, CascadedDeleteCallback) | |
213 { | |
214 SQLite::Connection c; | |
215 c.OpenInMemory(); | |
216 MyDelete *func = new MyDelete(); | |
217 c.Register(func); | |
218 c.Execute("CREATE TABLE parent(id INTEGER PRIMARY KEY, dummy INTEGER);"); | |
219 c.Execute("CREATE TABLE child(" | |
220 " id INTEGER PRIMARY KEY, " | |
221 " parent INTEGER REFERENCES parent(id) ON DELETE CASCADE, " | |
222 " value INTEGER);"); | |
223 c.Execute("CREATE TRIGGER childRemoved " | |
224 "AFTER DELETE ON child " | |
225 "FOR EACH ROW BEGIN " | |
226 " SELECT MYDELETE(old.value); " | |
227 "END;"); | |
228 | |
229 c.Execute("INSERT INTO parent VALUES(42, 100);"); | |
230 c.Execute("INSERT INTO parent VALUES(43, 101);"); | |
231 | |
232 c.Execute("INSERT INTO child VALUES(NULL, 42, 4200);"); | |
233 c.Execute("INSERT INTO child VALUES(NULL, 42, 4201);"); | |
234 | |
235 c.Execute("INSERT INTO child VALUES(NULL, 43, 4300);"); | |
236 c.Execute("INSERT INTO child VALUES(NULL, 43, 4301);"); | |
237 | |
238 // The following command deletes "parent(43, 101)", then in turns | |
239 // "child(NULL, 43, 4300/4301)", then calls the MyDelete on 4300 and | |
240 // 4301 | |
241 c.Execute("DELETE FROM parent WHERE dummy=101"); | |
242 | |
243 ASSERT_EQ(2u, func->deleted_.size()); | |
244 ASSERT_TRUE(func->deleted_.find(4300) != func->deleted_.end()); | |
245 ASSERT_TRUE(func->deleted_.find(4301) != func->deleted_.end()); | |
246 } | |
137
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 |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
249 TEST(SQLite, EmptyTransactions) |
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 try |
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 SQLite::Connection c; |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
254 c.OpenInMemory(); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
255 |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
256 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
|
257 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
|
258 |
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 SQLite::Transaction t(c); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
261 t.Begin(); |
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 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
|
264 s.Step(); |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
265 } |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
266 //t.Commit(); |
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 { |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
270 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
|
271 s.Step(); |
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 } |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
274 catch (OrthancException& e) |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
275 { |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
276 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
|
277 throw e; |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
278 } |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
279 } |
724 | 280 |
281 | |
282 TEST(SQLite, Types) | |
283 { | |
284 SQLite::Connection c; | |
285 c.OpenInMemory(); | |
286 c.Execute("CREATE TABLE a(id INTEGER PRIMARY KEY, value)"); | |
287 | |
288 { | |
289 SQLite::Statement s(c, std::string("SELECT * FROM a")); | |
290 ASSERT_EQ(2, s.ColumnCount()); | |
291 ASSERT_FALSE(s.Step()); | |
292 } | |
293 | |
294 { | |
295 SQLite::Statement s(c, SQLITE_FROM_HERE, std::string("SELECT * FROM a")); | |
296 ASSERT_FALSE(s.Step()); | |
297 ASSERT_EQ("SELECT * FROM a", s.GetOriginalSQLStatement()); | |
298 } | |
299 | |
300 { | |
301 SQLite::Statement s(c, SQLITE_FROM_HERE, "INSERT INTO a VALUES(NULL, ?);"); | |
302 s.BindNull(0); ASSERT_TRUE(s.Run()); s.Reset(); | |
303 s.BindBool(0, true); ASSERT_TRUE(s.Run()); s.Reset(); | |
304 s.BindInt(0, 42); ASSERT_TRUE(s.Run()); s.Reset(); | |
305 s.BindInt64(0, 42ll); ASSERT_TRUE(s.Run()); s.Reset(); | |
306 s.BindDouble(0, 42.5); ASSERT_TRUE(s.Run()); s.Reset(); | |
307 s.BindCString(0, "Hello"); ASSERT_TRUE(s.Run()); s.Reset(); | |
308 s.BindBlob(0, "Hello", 5); ASSERT_TRUE(s.Run()); s.Reset(); | |
309 } | |
310 | |
311 { | |
312 SQLite::Statement s(c, SQLITE_FROM_HERE, std::string("SELECT * FROM a")); | |
313 ASSERT_TRUE(s.Step()); | |
314 ASSERT_EQ(SQLite::COLUMN_TYPE_NULL, s.GetColumnType(1)); | |
315 ASSERT_TRUE(s.ColumnIsNull(1)); | |
316 ASSERT_TRUE(s.Step()); | |
317 ASSERT_EQ(SQLite::COLUMN_TYPE_INTEGER, s.GetColumnType(1)); | |
318 ASSERT_TRUE(s.ColumnBool(1)); | |
319 ASSERT_TRUE(s.Step()); | |
320 ASSERT_EQ(SQLite::COLUMN_TYPE_INTEGER, s.GetColumnType(1)); | |
321 ASSERT_EQ(42, s.ColumnInt(1)); | |
322 ASSERT_TRUE(s.Step()); | |
323 ASSERT_EQ(SQLite::COLUMN_TYPE_INTEGER, s.GetColumnType(1)); | |
324 ASSERT_EQ(42ll, s.ColumnInt64(1)); | |
325 ASSERT_TRUE(s.Step()); | |
326 ASSERT_EQ(SQLite::COLUMN_TYPE_FLOAT, s.GetColumnType(1)); | |
876 | 327 ASSERT_DOUBLE_EQ(42.5, s.ColumnDouble(1)); |
724 | 328 ASSERT_TRUE(s.Step()); |
329 ASSERT_EQ(SQLite::COLUMN_TYPE_TEXT, s.GetColumnType(1)); | |
330 ASSERT_EQ("Hello", s.ColumnString(1)); | |
331 ASSERT_TRUE(s.Step()); | |
332 ASSERT_EQ(SQLite::COLUMN_TYPE_BLOB, s.GetColumnType(1)); | |
333 ASSERT_EQ(5, s.ColumnByteLength(1)); | |
334 ASSERT_TRUE(!memcmp("Hello", s.ColumnBlob(1), 5)); | |
335 | |
336 std::string t; | |
337 ASSERT_TRUE(s.ColumnBlobAsString(1, &t)); | |
338 ASSERT_EQ("Hello", t); | |
339 | |
340 ASSERT_FALSE(s.Step()); | |
341 } | |
342 } |