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