summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-02 20:39:15 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-02 20:39:15 +0100
commitb1c99b0c3b0a8d65f237f507ad238ce441233b3f (patch)
treef493704fac3177d0b2a37e1e189117fe6dc705ce
parent992a1b3d2653ed527c2a301f80140bc35d84e832 (diff)
Fix dependency, added test for CompiledSQL
-rw-r--r--compiledsql.h2
-rw-r--r--debian/control2
-rw-r--r--tests/test-compiledsql.cpp34
3 files changed, 25 insertions, 13 deletions
diff --git a/compiledsql.h b/compiledsql.h
index 923be83..7510408 100644
--- a/compiledsql.h
+++ b/compiledsql.h
@@ -13,6 +13,7 @@ public:
void init(const std::string& stmt);
+ // index 1-based as in SQLite
template<typename T>
void bind(int index, T value)
{
@@ -21,6 +22,7 @@ public:
bool execute();
+ // index 0-based as in SQLite
template<typename T>
T getColumn(const int index)
{
diff --git a/debian/control b/debian/control
index aecfa97..6b0db0e 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,7 @@ Source: whiteboard
Section: web
Priority: optional
Maintainer: Roland Reichwein <mail@reichwein.it>
-Build-Depends: debhelper (>= 12), libboost-all-dev | libboost1.71-all-dev, clang | g++-9, llvm | g++-9, lld | g++-9, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libfcgi-dev, libqrcodegencpp-dev, libmagick++-dev, pkg-config, libfmt-dev, libsqlitecpp-dev, googletest, gcovr, webserver, libreichwein-dev
+Build-Depends: debhelper (>= 12), libboost-all-dev | libboost1.71-all-dev, clang | g++-9, llvm | g++-9, lld | g++-9, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libfcgi-dev, libqrcodegencpp-dev, libgraphicsmagick++-dev, pkg-config, libfmt-dev, libsqlitecpp-dev, googletest, gcovr, webserver, libreichwein-dev
Standards-Version: 4.5.0
Homepage: http://www.reichwein.it/whiteboard/
diff --git a/tests/test-compiledsql.cpp b/tests/test-compiledsql.cpp
index 4fe29e0..00a8221 100644
--- a/tests/test-compiledsql.cpp
+++ b/tests/test-compiledsql.cpp
@@ -14,7 +14,6 @@
namespace fs = std::filesystem;
namespace {
- const std::string testConfigFilename{"./test.conf"};
const std::string testDbFilename{"./whiteboard.db3"};
}
@@ -29,29 +28,40 @@ protected:
void SetUp() override
{
- File::setFile(testConfigFilename, R"CONFIG(
-<config>
- <datapath>.</datapath>
- <maxage>2592000</maxage>
-</config>
-)CONFIG");
std::error_code ec;
fs::remove(testDbFilename, ec);
-
- m_config = std::make_shared<Config>(testConfigFilename);
}
void TearDown() override
{
std::error_code ec;
fs::remove(testDbFilename, ec);
- fs::remove(testConfigFilename, ec);
}
- std::shared_ptr<Config> m_config;
};
-TEST_F(CompiledSQLTest, connection)
+TEST_F(CompiledSQLTest, create)
{
+ SQLite::Database db{testDbFilename, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE};
+
+ CompiledSQL stmt1{db};
+ stmt1.init("CREATE TABLE documents (id VARCHAR(16) PRIMARY KEY)");
+ stmt1.execute();
+
+ CompiledSQL stmt2{db};
+ stmt2.init("INSERT INTO documents (id) values (?)");
+ stmt2.bind(1, "abc");
+ ASSERT_TRUE(stmt2.execute());
+
+ CompiledSQL stmt3{db};
+ stmt3.init("SELECT id FROM documents WHERE id = ?");
+ stmt3.bind(1, "abc");
+ ASSERT_TRUE(stmt3.execute());
+ EXPECT_EQ(stmt3.getColumn<std::string>(0), "abc");
+ stmt3.init("SELECT id FROM documents WHERE id = ?");
+ stmt3.bind(1, "def");
+ ASSERT_FALSE(stmt3.execute());
+
+ EXPECT_TRUE(fs::exists(testDbFilename));
}