Skip to content

Commit 45260a2

Browse files
committed
remove boost support
1 parent b340ce1 commit 45260a2

File tree

5 files changed

+54
-197
lines changed

5 files changed

+54
-197
lines changed

CMakeLists.txt

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,7 @@ download_project(
2020

2121
set(CATCH_INCLUDE_DIR ${CMAKE_BINARY_DIR}/catch-src/single_include/)
2222
set(TEST_SOURCE_DIR ${CMAKE_SOURCE_DIR}/tests)
23-
#file(GLOB TEST_SOURCES ${TEST_SOURCE_DIR}/*.cc)
24-
set(TEST_SOURCES
25-
${TEST_SOURCE_DIR}/blob_example.cc
26-
${TEST_SOURCE_DIR}/error_log.cc
27-
${TEST_SOURCE_DIR}/exceptions.cc
28-
${TEST_SOURCE_DIR}/prepared_statment.cc
29-
${TEST_SOURCE_DIR}/lvalue_functor.cc
30-
${TEST_SOURCE_DIR}/functors.cc
31-
${TEST_SOURCE_DIR}/std_optional.cc
32-
${TEST_SOURCE_DIR}/flags.cc
33-
${TEST_SOURCE_DIR}/mov_ctor.cc
34-
${TEST_SOURCE_DIR}/shared_connection.cc
35-
${TEST_SOURCE_DIR}/trycatchblocks.cc
36-
${TEST_SOURCE_DIR}/readme_example.cc
37-
${TEST_SOURCE_DIR}/functions.cc
38-
${TEST_SOURCE_DIR}/nullptr_uniqueptr.cc
39-
${TEST_SOURCE_DIR}/simple_examples.cc
40-
${TEST_SOURCE_DIR}/variant.cc
41-
${TEST_SOURCE_DIR}/exception_dont_execute.cc
42-
${TEST_SOURCE_DIR}/exception_dont_execute_nested.cc
43-
)
23+
file(GLOB TEST_SOURCES ${TEST_SOURCE_DIR}/*.cc)
4424

4525
enable_testing()
4626

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,8 @@ int main() {
322322
};
323323
}
324324
```
325-
326-
If you do not have C++17 support, you can use boost optional instead by defining `_MODERN_SQLITE_BOOST_OPTIONAL_SUPPORT` before importing the `sqlite_modern_cpp` header.
327-
328325
If the optional library is not available, the experimental/optional one will be used instead.
329326
330-
**Note: boost support is deprecated and will be removed in future versions.**
331-
332327
Variant type support (C++17)
333328
----
334329
If your columns may have flexible types, you can use C++17's `std::variant` to extract the value.

hdr/sqlite_modern_cpp.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
#define MODERN_SQLITE_STD_OPTIONAL_SUPPORT
3535
#endif
3636

37-
#ifdef _MODERN_SQLITE_BOOST_OPTIONAL_SUPPORT
38-
#include <boost/optional.hpp>
39-
#endif
40-
4137
#include <sqlite3.h>
4238

4339
#include "sqlite_modern_cpp/errors.h"
@@ -254,11 +250,6 @@ namespace sqlite {
254250
template <typename OptionalT> friend void get_col_from_db(database_binder& db, int inx, optional<OptionalT>& o);
255251
#endif
256252

257-
#ifdef _MODERN_SQLITE_BOOST_OPTIONAL_SUPPORT
258-
template <typename BoostOptionalT> friend database_binder& operator <<(database_binder& db, const boost::optional<BoostOptionalT>& val);
259-
template <typename BoostOptionalT> friend void get_col_from_db(database_binder& db, int inx, boost::optional<BoostOptionalT>& o);
260-
#endif
261-
262253
public:
263254

264255
database_binder(std::shared_ptr<sqlite3> db, std::u16string const & sql):
@@ -840,42 +831,6 @@ namespace sqlite {
840831
}
841832
#endif
842833

843-
// boost::optional support for NULL values
844-
#ifdef _MODERN_SQLITE_BOOST_OPTIONAL_SUPPORT
845-
template <typename BoostOptionalT> inline database_binder& operator <<(database_binder& db, const boost::optional<BoostOptionalT>& val) {
846-
if(val) {
847-
return db << std::move(*val);
848-
} else {
849-
return db << nullptr;
850-
}
851-
}
852-
template <typename BoostOptionalT> inline void store_result_in_db(sqlite3_context* db, const boost::optional<BoostOptionalT>& val) {
853-
if(val) {
854-
store_result_in_db(db, *val);
855-
}
856-
sqlite3_result_null(db);
857-
}
858-
859-
template <typename BoostOptionalT> inline void get_col_from_db(database_binder& db, int inx, boost::optional<BoostOptionalT>& o) {
860-
if(sqlite3_column_type(db._stmt.get(), inx) == SQLITE_NULL) {
861-
o.reset();
862-
} else {
863-
BoostOptionalT v;
864-
get_col_from_db(db, inx, v);
865-
o = std::move(v);
866-
}
867-
}
868-
template <typename BoostOptionalT> inline void get_val_from_db(sqlite3_value *value, boost::optional<BoostOptionalT>& o) {
869-
if(sqlite3_value_type(value) == SQLITE_NULL) {
870-
o.reset();
871-
} else {
872-
BoostOptionalT v;
873-
get_val_from_db(value, v);
874-
o = std::move(v);
875-
}
876-
}
877-
#endif
878-
879834
#ifdef MODERN_SQLITE_STD_VARIANT_SUPPORT
880835
template <typename ...Args> inline database_binder& operator <<(database_binder& db, const std::variant<Args...>& val) {
881836
std::visit([&](auto &&opt) {db << std::forward<decltype(opt)>(opt);}, val);

tests/boost_optional.cc

Lines changed: 0 additions & 52 deletions
This file was deleted.

tests/sqlcipher.cc

Lines changed: 53 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,58 @@
1-
#ifdef ENABLE_SQLCIPHER_TESTS
21
#include <iostream>
32
#include <cstdio>
43
#include <cstdlib>
5-
#include <sqlite_modern_cpp/sqlcipher.h>
6-
using namespace sqlite;
7-
using namespace std;
8-
9-
struct TmpFile
10-
{
11-
string fname;
12-
13-
TmpFile(): fname("./sqlcipher.db") { }
14-
~TmpFile() { remove(fname.c_str()); }
15-
};
16-
17-
int main()
18-
{
19-
try
20-
{
21-
TmpFile file;
22-
sqlcipher_config config;
23-
{
24-
config.key = "DebugKey";
25-
sqlcipher_database db(file.fname, config);
26-
27-
db << "CREATE TABLE foo (a integer, b string);";
28-
db << "INSERT INTO foo VALUES (?, ?)" << 1 << "hello";
29-
db << "INSERT INTO foo VALUES (?, ?)" << 2 << "world";
4+
#include <catch.hpp>
305

31-
string str;
32-
db << "SELECT b from FOO where a=?;" << 2 >> str;
33-
34-
if(str != "world")
35-
{
36-
cout << "Bad result on line " << __LINE__ << endl;
37-
exit(EXIT_FAILURE);
38-
}
39-
}
40-
try {
41-
config.key = "DebugKey2";
42-
sqlcipher_database db(file.fname, config);
43-
db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail";
44-
45-
cout << "Can open with wrong key";
46-
exit(EXIT_FAILURE);
47-
} catch(errors::notadb) {
48-
// Expected, wrong key
49-
}
50-
{
51-
config.key = "DebugKey";
52-
sqlcipher_database db(file.fname, config);
53-
db.rekey("DebugKey2");
54-
}
55-
{
56-
config.key = "DebugKey2";
57-
sqlcipher_database db(file.fname, config);
58-
db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail";
59-
}
60-
}
61-
catch(sqlite_exception e)
62-
{
63-
cout << "Unexpected error " << e.what() << endl;
64-
exit(EXIT_FAILURE);
65-
}
66-
catch(...)
67-
{
68-
cout << "Unknown error\n";
69-
exit(EXIT_FAILURE);
70-
}
71-
72-
cout << "OK\n";
73-
exit(EXIT_SUCCESS);
74-
}
75-
#else
76-
int main() {
77-
return 42; //Skip test
78-
}
6+
#ifdef ENABLE_SQLCIPHER_TESTS
7+
#include <sqlite_modern_cpp/sqlcipher.h>
8+
using namespace sqlite;
9+
using namespace std;
10+
11+
struct TmpFile
12+
{
13+
string fname;
14+
15+
TmpFile(): fname("./sqlcipher.db") { }
16+
~TmpFile() { remove(fname.c_str()); }
17+
};
18+
19+
TEST_CASE("sqlcipher works", "[sqlcipher]") {
20+
TmpFile file;
21+
sqlcipher_config config;
22+
{
23+
config.key = "DebugKey";
24+
sqlcipher_database db(file.fname, config);
25+
26+
db << "CREATE TABLE foo (a integer, b string);";
27+
db << "INSERT INTO foo VALUES (?, ?)" << 1 << "hello";
28+
db << "INSERT INTO foo VALUES (?, ?)" << 2 << "world";
29+
30+
string str;
31+
db << "SELECT b from FOO where a=?;" << 2 >> str;
32+
33+
REQUIRE(str == "world");
34+
}
35+
36+
bool failed = false;
37+
try {
38+
config.key = "DebugKey2";
39+
sqlcipher_database db(file.fname, config);
40+
db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail";
41+
} catch(errors::notadb) {
42+
failed = true;
43+
// Expected, wrong key
44+
}
45+
REQUIRE(failed == true);
46+
47+
{
48+
config.key = "DebugKey";
49+
sqlcipher_database db(file.fname, config);
50+
db.rekey("DebugKey2");
51+
}
52+
{
53+
config.key = "DebugKey2";
54+
sqlcipher_database db(file.fname, config);
55+
db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail";
56+
}
57+
}
7958
#endif

0 commit comments

Comments
 (0)