annotate OrthancFramework/UnitTestsSources/SQLiteTests.cpp @ 4795:22d5b611dea7

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