Pull in full sqlite_modern_cpp repo for the license as it is not attached to source files

This commit is contained in:
Saood Karim
2025-08-17 08:25:37 -05:00
parent a3b174b69a
commit ed9504bd92
41 changed files with 2654 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
#include <iostream>
#include <iomanip>
#include <string>
#include <memory>
#include <stdexcept>
#include <sqlite_modern_cpp.h>
#include <catch2/catch.hpp>
using namespace sqlite;
using namespace std;
TEST_CASE("exceptions are thrown", "[exceptions]") {
database db(":memory:");
db << "CREATE TABLE person (id integer primary key not null, name TEXT);";
bool expception_thrown = false;
std::string get_sql_result;
#if SQLITE_VERSION_NUMBER >= 3014000
std::string expedted_sql = "INSERT INTO person (id,name) VALUES (1,'jack')";
#else
std::string expedted_sql = "INSERT INTO person (id,name) VALUES (?,?)";
#endif
SECTION("Parent exception works") {
try {
db << "INSERT INTO person (id,name) VALUES (?,?)" << 1 << "jack";
// inserting again to produce error
db << "INSERT INTO person (id,name) VALUES (?,?)" << 1 << "jack";
} catch (errors::constraint& e) {
expception_thrown = true;
get_sql_result = e.get_sql();
}
REQUIRE(expception_thrown == true);
REQUIRE(get_sql_result == expedted_sql);
}
SECTION("Extended exception works") {
try {
db << "INSERT INTO person (id,name) VALUES (?,?)" << 1 << "jack";
// inserting again to produce error
db << "INSERT INTO person (id,name) VALUES (?,?)" << 1 << "jack";
} catch (errors::constraint_primarykey& e) {
expception_thrown = true;
get_sql_result = e.get_sql();
}
REQUIRE(expception_thrown == true);
REQUIRE(get_sql_result == expedted_sql);
}
}