@@ -48,6 +48,10 @@ jobs:
|
||||
restore-keys: conan-${{ runner.os }}-
|
||||
- name: Configure native release
|
||||
run: python3 modulus.py configure --target x86_64_gcc12_release
|
||||
- name: Check code style
|
||||
run: |
|
||||
python3 -m pip install --no-cache-dir -r build/build_tools/docker/format-requirements.txt
|
||||
python3 modulus.py format --check
|
||||
- name: Build native release
|
||||
run: python3 modulus.py build --target x86_64_gcc12_release
|
||||
- name: Test native release
|
||||
|
||||
@@ -6,6 +6,8 @@ Noto uses Modulus for shared build tooling, Boost.JSON, and SQLite integration.
|
||||
|
||||
## Build
|
||||
|
||||
Code style is managed by Modulus: run `./modulus.py format` or `./modulus.py format --check`. The generated Neovim integration uses the same pinned container formatter for C++ and Python, including existing format-on-save toggles. Configure first to prepare tooling; customize `tooling.editor.clang_format` and `tooling.format.exclude` in `modulus.json`, not generated editor files. See the shared Modulus README for the compact layout and no-alias policy.
|
||||
|
||||
Configure, build, and test the default target:
|
||||
|
||||
```sh
|
||||
|
||||
@@ -41,15 +41,12 @@ class noto_conan(conan.ConanFile):
|
||||
"tests/*.cpp",
|
||||
"tests/*.hpp",
|
||||
)
|
||||
|
||||
def config_options(self):
|
||||
if self.settings.os == "Windows":
|
||||
del self.options.fPIC
|
||||
|
||||
def configure(self):
|
||||
if self.options.shared:
|
||||
del self.options.fPIC
|
||||
|
||||
def requirements(self):
|
||||
self.requires(
|
||||
"modulus/latest",
|
||||
@@ -59,7 +56,6 @@ class noto_conan(conan.ConanFile):
|
||||
"with_sqlite": True,
|
||||
},
|
||||
)
|
||||
|
||||
def generate(self):
|
||||
deps = conan.tools.cmake.CMakeDeps(self)
|
||||
deps.generate()
|
||||
@@ -69,14 +65,12 @@ class noto_conan(conan.ConanFile):
|
||||
toolchain.variables["BUILD_SHARED_LIBS"] = bool(self.options.shared)
|
||||
toolchain.variables["BUILD_TESTING"] = bool(self.options.with_tests)
|
||||
toolchain.generate()
|
||||
|
||||
def build(self):
|
||||
cmake = conan.tools.cmake.CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
if self.options.with_tests and conan.tools.build.can_run(self):
|
||||
cmake.test(target="check")
|
||||
|
||||
def package_id(self):
|
||||
self.info.options.rm_safe("with_tests")
|
||||
for requirement in (
|
||||
@@ -88,11 +82,9 @@ class noto_conan(conan.ConanFile):
|
||||
):
|
||||
if requirement in self.info.requires.pkg_names:
|
||||
self.info.requires.remove(requirement)
|
||||
|
||||
def package(self):
|
||||
cmake = conan.tools.cmake.CMake(self)
|
||||
cmake.install()
|
||||
|
||||
def package_info(self):
|
||||
self.cpp_info.set_property(
|
||||
"cmake_file_name",
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace noto {
|
||||
namespace detail {
|
||||
|
||||
struct statement_core;
|
||||
|
||||
struct connection_core;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <modulus.hpp>
|
||||
|
||||
|
||||
namespace noto::detail {
|
||||
|
||||
constexpr std::int32_t error_invalid_argument{1};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <modulus.hpp>
|
||||
|
||||
|
||||
namespace noto::detail {
|
||||
|
||||
auto quote_sql_literal(std::string_view value, std::string_view label, std::bool_t allow_empty = true) -> std::expected<std::string, modulus::error>;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <modulus.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
struct sqlite3;
|
||||
|
||||
namespace noto {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <modulus.hpp>
|
||||
|
||||
|
||||
namespace noto {
|
||||
|
||||
class trusted_sql_fragment {
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace noto {
|
||||
namespace detail {
|
||||
|
||||
struct connection_core;
|
||||
|
||||
struct transaction_state;
|
||||
|
||||
}
|
||||
|
||||
+6
-2
@@ -16,6 +16,7 @@ COMMANDS = (
|
||||
"package",
|
||||
"lsp",
|
||||
"clangd",
|
||||
"format",
|
||||
)
|
||||
COMMON_DIR = pathlib.Path("build") / "build_common"
|
||||
TOOLS_DIR = pathlib.Path("build") / "build_tools"
|
||||
@@ -60,6 +61,9 @@ def runtime_ready(root):
|
||||
and (root / TOOLS_DIR / "clangd.py").is_file()
|
||||
and (root / RUNTIME_DIR / "modulus" / "cli.py").is_file()
|
||||
and (root / RUNTIME_DIR / "modulus" / "export.py").is_file()
|
||||
and (root / TOOLS_DIR / "format.py").is_file()
|
||||
and (root / RUNTIME_DIR / "modulus" / "formatting.py").is_file()
|
||||
and (root / RUNTIME_DIR / "modulus" / "format_layout.py").is_file()
|
||||
)
|
||||
|
||||
def optional_credentials():
|
||||
@@ -340,9 +344,9 @@ def ensure_runtime(root):
|
||||
|
||||
def delegate(command, argv):
|
||||
root = repo_root()
|
||||
if command == "clangd":
|
||||
if command in {"clangd", "format"}:
|
||||
if not runtime_ready(root):
|
||||
print("Modulus clangd tooling is missing; run ./modulus.py configure first", file=sys.stderr)
|
||||
print(f"Modulus {command} tooling is missing; run ./modulus.py configure first", file=sys.stderr)
|
||||
return 1
|
||||
else:
|
||||
ensure_runtime(root)
|
||||
|
||||
+8
-5
@@ -19,13 +19,13 @@
|
||||
|
||||
#include <noto/detail/errors.hpp>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr auto json_options = modulus::json_config::options{
|
||||
.category = "noto",
|
||||
.invalid_argument_code = noto::detail::error_invalid_argument,
|
||||
.not_found_code = noto::detail::error_not_found
|
||||
};
|
||||
.not_found_code = noto::detail::error_not_found};
|
||||
|
||||
auto invalid(std::string message) -> std::expected<void, modulus::error> {
|
||||
return noto::detail::fail_void(noto::detail::error_invalid_argument, std::move(message));
|
||||
@@ -204,7 +204,8 @@ auto noto::parse_database_config(boost::json::value const& value) -> std::expect
|
||||
"busy_timeout_ms",
|
||||
"foreign_keys",
|
||||
"pragmas",
|
||||
}, "database", json_options);
|
||||
},
|
||||
"database", json_options);
|
||||
if (!unknown) {
|
||||
return noto::detail::fail<noto::connection_config>(unknown.error());
|
||||
}
|
||||
@@ -229,7 +230,8 @@ auto noto::parse_database_config(boost::json::value const& value) -> std::expect
|
||||
.name = "memory",
|
||||
.value = noto::open_mode::MEMORY,
|
||||
},
|
||||
}, "database mode must be read_only, read_write, read_write_create, or memory", json_options);
|
||||
},
|
||||
"database mode must be read_only, read_write, read_write_create, or memory", json_options);
|
||||
if (!mode) {
|
||||
return noto::detail::fail<noto::connection_config>(mode.error());
|
||||
}
|
||||
@@ -307,7 +309,8 @@ auto noto::load_database_configs(std::string const& path) -> std::expected<std::
|
||||
auto noto::to_json(std::variant<std::bool_t, std::int64_t, std::string> const &value) -> boost::json::value {
|
||||
return std::visit([](auto const &item) -> boost::json::value {
|
||||
return boost::json::value{item};
|
||||
}, value);
|
||||
},
|
||||
value);
|
||||
}
|
||||
|
||||
auto noto::to_json(noto::connection_config const &config) -> boost::json::value {
|
||||
|
||||
+25
-12
@@ -25,6 +25,7 @@
|
||||
#include <noto/schema.hpp>
|
||||
#include <noto/transaction.hpp>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
auto invalid_connection() -> std::expected<void, modulus::error> {
|
||||
@@ -70,7 +71,8 @@ auto pragma_value_sql(std::variant<std::bool_t, std::int64_t, std::string> const
|
||||
} else {
|
||||
return noto::detail::quote_sql_literal(current, "pragma value");
|
||||
}
|
||||
}, value);
|
||||
},
|
||||
value);
|
||||
}
|
||||
|
||||
auto first_int(noto::query_result const &result) -> std::expected<std::int64_t, modulus::error> {
|
||||
@@ -374,21 +376,29 @@ auto async_connection_wal_checkpoint(noto::connection connection, std::string mo
|
||||
|
||||
}
|
||||
|
||||
noto::sqlite_value::sqlite_value(std::nullptr_t) : value{std::monostate{}} {}
|
||||
noto::sqlite_value::sqlite_value(std::nullptr_t)
|
||||
: value{std::monostate{}} {}
|
||||
|
||||
noto::sqlite_value::sqlite_value(std::int32_t value) : value{static_cast<std::int64_t>(value)} {}
|
||||
noto::sqlite_value::sqlite_value(std::int32_t value)
|
||||
: value{static_cast<std::int64_t>(value)} {}
|
||||
|
||||
noto::sqlite_value::sqlite_value(std::int64_t current) : value{current} {}
|
||||
noto::sqlite_value::sqlite_value(std::int64_t current)
|
||||
: value{current} {}
|
||||
|
||||
noto::sqlite_value::sqlite_value(std::float64_t current) : value{current} {}
|
||||
noto::sqlite_value::sqlite_value(std::float64_t current)
|
||||
: value{current} {}
|
||||
|
||||
noto::sqlite_value::sqlite_value(std::char_t const* current) : value{std::string{current == nullptr ? "" : current}} {}
|
||||
noto::sqlite_value::sqlite_value(std::char_t const *current)
|
||||
: value{std::string{current == nullptr ? "" : current}} {}
|
||||
|
||||
noto::sqlite_value::sqlite_value(std::string current) : value{std::move(current)} {}
|
||||
noto::sqlite_value::sqlite_value(std::string current)
|
||||
: value{std::move(current)} {}
|
||||
|
||||
noto::sqlite_value::sqlite_value(std::string_view current) : value{std::string{current}} {}
|
||||
noto::sqlite_value::sqlite_value(std::string_view current)
|
||||
: value{std::string{current}} {}
|
||||
|
||||
noto::sqlite_value::sqlite_value(std::vector<std::byte> current) : value{std::move(current)} {}
|
||||
noto::sqlite_value::sqlite_value(std::vector<std::byte> current)
|
||||
: value{std::move(current)} {}
|
||||
|
||||
auto noto::sqlite_value::is_null() const -> std::bool_t {
|
||||
return std::holds_alternative<std::monostate>(value);
|
||||
@@ -424,9 +434,11 @@ auto noto::statement::async_finalize() -> boost::asio::awaitable<std::expected<v
|
||||
return async_statement_finalize(std::move(core));
|
||||
}
|
||||
|
||||
noto::statement::statement(std::shared_ptr<noto::detail::statement_core> core) : core_{std::move(core)} {}
|
||||
noto::statement::statement(std::shared_ptr<noto::detail::statement_core> core)
|
||||
: core_{std::move(core)} {}
|
||||
|
||||
noto::connection::connection(boost::asio::any_io_executor executor, noto::connection_config config) : core_{std::make_shared<noto::detail::connection_core>(std::move(executor), std::move(config))} {}
|
||||
noto::connection::connection(boost::asio::any_io_executor executor, noto::connection_config config)
|
||||
: core_{std::make_shared<noto::detail::connection_core>(std::move(executor), std::move(config))} {}
|
||||
|
||||
noto::connection::~connection() = default;
|
||||
|
||||
@@ -586,7 +598,8 @@ auto noto::connection::async_wal_checkpoint(std::string mode) -> boost::asio::aw
|
||||
return async_connection_wal_checkpoint(noto::connection{core_}, std::move(mode));
|
||||
}
|
||||
|
||||
noto::connection::connection(std::shared_ptr<noto::detail::connection_core> core) : core_{std::move(core)} {}
|
||||
noto::connection::connection(std::shared_ptr<noto::detail::connection_core> core)
|
||||
: core_{std::move(core)} {}
|
||||
|
||||
auto noto::connection::core() const -> std::shared_ptr<noto::detail::connection_core> {
|
||||
return core_;
|
||||
|
||||
+28
-27
@@ -56,6 +56,7 @@
|
||||
|
||||
#include <noto/detail/core.hpp>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
struct pending_statement_finalize {
|
||||
@@ -169,7 +170,8 @@ auto errno_status(std::string operation, std::int32_t code) -> std::expected<voi
|
||||
return noto::detail::fail_void(noto::detail::error_unavailable, std::move(operation) + ": " + std::error_code{
|
||||
code,
|
||||
std::generic_category(),
|
||||
}.message());
|
||||
}
|
||||
.message());
|
||||
}
|
||||
|
||||
auto filesystem_status(std::string operation, std::error_code const &code) -> std::expected<void, modulus::error> {
|
||||
@@ -421,7 +423,8 @@ auto pragma_value_sql(std::variant<std::bool_t, std::int64_t, std::string> const
|
||||
} else {
|
||||
return noto::detail::quote_sql_literal(current, "pragma value");
|
||||
}
|
||||
}, value);
|
||||
},
|
||||
value);
|
||||
}
|
||||
|
||||
auto set_pragma(sqlite3 *database, std::string const &name, std::variant<std::bool_t, std::int64_t, std::string> const &value) -> std::expected<void, modulus::error> {
|
||||
@@ -482,7 +485,6 @@ auto async_step_backup(noto::detail::connection_core& core, sqlite3_backup* back
|
||||
co_await boost::asio::post(core.strand, boost::asio::use_awaitable);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (now >= deadline) {
|
||||
co_return std::unexpected(timeout(std::string{operation} + " timed out while waiting for SQLite locks").error());
|
||||
@@ -527,7 +529,6 @@ auto async_copy_restore_source_to_file(noto::detail::connection_core& core, std:
|
||||
sqlite3_close(source);
|
||||
co_return status;
|
||||
}
|
||||
|
||||
auto *destination = static_cast<sqlite3 *>(nullptr);
|
||||
code = sqlite3_open_v2(temporary.c_str(), &destination, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, nullptr);
|
||||
if (code != SQLITE_OK) {
|
||||
@@ -544,7 +545,6 @@ auto async_copy_restore_source_to_file(noto::detail::connection_core& core, std:
|
||||
sqlite3_close(source);
|
||||
co_return status;
|
||||
}
|
||||
|
||||
auto *backup = sqlite3_backup_init(destination, "main", source, options.source_name.c_str());
|
||||
if (backup == nullptr) {
|
||||
status = noto::result_from(sqlite3_errcode(destination), destination, "initialize restore");
|
||||
@@ -609,7 +609,6 @@ auto untrack_statement(noto::detail::statement_core& statement) -> void {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
auto bind_value(sqlite3_stmt *statement, std::int32_t index, noto::sqlite_value const &value, sqlite3 *database) -> std::expected<void, modulus::error> {
|
||||
auto size = std::visit([](auto const ¤t) -> std::size_t {
|
||||
if constexpr (std::is_same_v<std::decay_t<decltype(current)>, std::string> || std::is_same_v<std::decay_t<decltype(current)>, std::vector<std::byte>>) {
|
||||
@@ -617,7 +616,8 @@ auto bind_value(sqlite3_stmt* statement, std::int32_t index, noto::sqlite_value
|
||||
} else {
|
||||
return std::size_t{};
|
||||
}
|
||||
}, value.value);
|
||||
},
|
||||
value.value);
|
||||
if (size > sqlite_int_max()) {
|
||||
return invalid("bound SQLite text/blob value is too large");
|
||||
}
|
||||
@@ -633,7 +633,8 @@ auto bind_value(sqlite3_stmt* statement, std::int32_t index, noto::sqlite_value
|
||||
} else {
|
||||
return sqlite3_bind_blob(statement, index, current.data(), static_cast<std::int32_t>(current.size()), SQLITE_TRANSIENT);
|
||||
}
|
||||
}, value.value);
|
||||
},
|
||||
value.value);
|
||||
return noto::result_from(code, database, "bind parameter");
|
||||
}
|
||||
|
||||
@@ -717,7 +718,8 @@ auto value_result_bytes(noto::sqlite_value const& value) -> std::size_t {
|
||||
} else {
|
||||
return current.size();
|
||||
}
|
||||
}, value.value);
|
||||
},
|
||||
value.value);
|
||||
}
|
||||
|
||||
auto add_result_bytes(std::size_t ¤t, std::size_t addition, noto::execute_options const &options) -> std::expected<void, modulus::error> {
|
||||
@@ -815,6 +817,7 @@ auto normalized_path(std::string const& path, std::string_view operation) -> std
|
||||
|
||||
auto identity_for_path(std::filesystem::path const &path, std::string_view operation) -> std::expected<std::optional<file_identity>, modulus::error> {
|
||||
struct stat data{};
|
||||
|
||||
auto text = path.string();
|
||||
if (::stat(text.c_str(), &data) == 0) {
|
||||
auto identity = file_identity{};
|
||||
@@ -999,7 +1002,8 @@ auto literal_sql(noto::sqlite_value const& value) -> std::expected<std::string,
|
||||
} else {
|
||||
return hex_literal(current.data(), current.size());
|
||||
}
|
||||
}, value.value);
|
||||
},
|
||||
value.value);
|
||||
}
|
||||
|
||||
auto write_limited(std::ostream &output, std::string_view text, noto::export_options const &options, std::size_t &written) -> std::expected<void, modulus::error> {
|
||||
@@ -1144,13 +1148,9 @@ auto exportable_columns(sqlite3* database, std::string const& table_name) -> std
|
||||
|
||||
auto collect_export_schema(sqlite3 *database) -> std::expected<export_schema, modulus::error> {
|
||||
auto *raw_statement = static_cast<sqlite3_stmt *>(nullptr);
|
||||
auto prepared = prepare_statement(
|
||||
database,
|
||||
"SELECT type, name, sql FROM sqlite_schema WHERE sql IS NOT NULL AND name NOT GLOB 'sqlite_*' "
|
||||
auto prepared = prepare_statement(database, "SELECT type, name, sql FROM sqlite_schema WHERE sql IS NOT NULL AND name NOT GLOB 'sqlite_*' "
|
||||
"ORDER BY CASE type WHEN 'table' THEN 0 WHEN 'index' THEN 1 WHEN 'trigger' THEN 2 WHEN 'view' THEN 3 ELSE 4 END, name",
|
||||
&raw_statement,
|
||||
"prepare export schema"
|
||||
);
|
||||
&raw_statement, "prepare export schema");
|
||||
if (!prepared) {
|
||||
return failure_from<export_schema>(prepared);
|
||||
}
|
||||
@@ -1358,7 +1358,8 @@ auto write_export(noto::detail::connection_core& core, std::function<std::expect
|
||||
co_return write("COMMIT;\nPRAGMA foreign_keys=ON;\n");
|
||||
}
|
||||
|
||||
pending_statement_finalize::pending_statement_finalize(std::shared_ptr<noto::detail::connection_core> owner_value, sqlite3_stmt* statement_value, std::bool_t counted_value) : owner{std::move(owner_value)}, statement{statement_value}, counted{counted_value} {}
|
||||
pending_statement_finalize::pending_statement_finalize(std::shared_ptr<noto::detail::connection_core> owner_value, sqlite3_stmt *statement_value, std::bool_t counted_value)
|
||||
: owner{std::move(owner_value)}, statement{statement_value}, counted{counted_value} {}
|
||||
|
||||
pending_statement_finalize::~pending_statement_finalize() {
|
||||
finish();
|
||||
@@ -1375,7 +1376,8 @@ auto pending_statement_finalize::finish() noexcept -> void {
|
||||
counted = false;
|
||||
}
|
||||
|
||||
pending_transaction_rollback::pending_transaction_rollback(std::shared_ptr<noto::detail::connection_core> owner_value) : owner{std::move(owner_value)} {}
|
||||
pending_transaction_rollback::pending_transaction_rollback(std::shared_ptr<noto::detail::connection_core> owner_value)
|
||||
: owner{std::move(owner_value)} {}
|
||||
|
||||
pending_transaction_rollback::~pending_transaction_rollback() {
|
||||
finish();
|
||||
@@ -1394,7 +1396,8 @@ auto pending_transaction_rollback::finish() noexcept -> void {
|
||||
|
||||
}
|
||||
|
||||
noto::detail::connection_core::connection_core(boost::asio::any_io_executor executor_value, noto::connection_config config_value) : executor{std::move(executor_value)}, strand{boost::asio::make_strand(executor)}, config{std::move(config_value)}, busy_timeout{config.busy_timeout} {}
|
||||
noto::detail::connection_core::connection_core(boost::asio::any_io_executor executor_value, noto::connection_config config_value)
|
||||
: executor{std::move(executor_value)}, strand{boost::asio::make_strand(executor)}, config{std::move(config_value)}, busy_timeout{config.busy_timeout} {}
|
||||
|
||||
noto::detail::connection_core::~connection_core() {
|
||||
if (database != nullptr) {
|
||||
@@ -1759,9 +1762,7 @@ auto noto::detail::connection_core::async_export_sql(noto::export_options option
|
||||
}
|
||||
auto output = std::ostringstream{};
|
||||
auto written = std::size_t{};
|
||||
auto status = co_await write_export(*this, [&output, &options, &written](std::string_view text) {
|
||||
return write_limited(output, text, options, written);
|
||||
}, options);
|
||||
auto status = co_await write_export(*this, [&output, &options, &written](std::string_view text) { return write_limited(output, text, options, written); }, options);
|
||||
if (!status) {
|
||||
status = finish_operation(*this, status);
|
||||
co_return std::unexpected(status.error());
|
||||
@@ -1802,9 +1803,7 @@ auto noto::detail::connection_core::async_export_sql_to_file(std::string path, n
|
||||
co_return finish_operation(*this, unavailable("failed to open export file"));
|
||||
}
|
||||
auto written = std::size_t{};
|
||||
auto status = co_await write_export(*this, [&output, &options, &written](std::string_view text) {
|
||||
return write_limited(output, text, options, written);
|
||||
}, options);
|
||||
auto status = co_await write_export(*this, [&output, &options, &written](std::string_view text) { return write_limited(output, text, options, written); }, options);
|
||||
if (status) {
|
||||
output.flush();
|
||||
if (!output) {
|
||||
@@ -1842,7 +1841,8 @@ auto noto::detail::connection_core::async_set_busy_timeout(std::chrono::millisec
|
||||
co_return finish_operation(*this, status);
|
||||
}
|
||||
|
||||
noto::detail::statement_core::statement_core(std::shared_ptr<noto::detail::connection_core> connection_value, sqlite3_stmt* statement_value) : connection{std::move(connection_value)}, statement{statement_value}, counted{statement_value != nullptr} {
|
||||
noto::detail::statement_core::statement_core(std::shared_ptr<noto::detail::connection_core> connection_value, sqlite3_stmt *statement_value)
|
||||
: connection{std::move(connection_value)}, statement{statement_value}, counted{statement_value != nullptr} {
|
||||
if (connection && counted) {
|
||||
connection->live_statements.fetch_add(1, std::memory_order_acq_rel);
|
||||
}
|
||||
@@ -2012,7 +2012,8 @@ auto noto::detail::statement_core::async_finalize() -> boost::asio::awaitable<st
|
||||
co_return finish_operation(*owner, status);
|
||||
}
|
||||
|
||||
noto::detail::transaction_state::transaction_state(std::shared_ptr<noto::detail::connection_core> core_value, std::function<void()> on_finish_value) : core{std::move(core_value)}, on_finish{std::move(on_finish_value)}, active{true} {}
|
||||
noto::detail::transaction_state::transaction_state(std::shared_ptr<noto::detail::connection_core> core_value, std::function<void()> on_finish_value)
|
||||
: core{std::move(core_value)}, on_finish{std::move(on_finish_value)}, active{true} {}
|
||||
|
||||
auto noto::detail::transaction_state::finish() noexcept -> void {
|
||||
if (!on_finish) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <modulus.hpp>
|
||||
|
||||
|
||||
auto noto::detail::make_error(std::int32_t code, std::string message, modulus::source_location location) -> modulus::error {
|
||||
return modulus::make_error("noto", code, std::move(message), location);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <noto/detail/errors.hpp>
|
||||
|
||||
|
||||
auto noto::detail::quote_sql_literal(std::string_view value, std::string_view label, std::bool_t allow_empty) -> std::expected<std::string, modulus::error> {
|
||||
if (value.empty() && !allow_empty) {
|
||||
return noto::detail::fail<std::string>(noto::detail::error_invalid_argument, std::string{label} + " must not be empty");
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <noto/detail/errors.hpp>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
auto code_from(std::int32_t code) -> std::int32_t {
|
||||
|
||||
+7
-2
@@ -23,6 +23,7 @@
|
||||
#include <noto/transaction.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
auto invalid(std::string message) -> std::expected<void, modulus::error> {
|
||||
@@ -57,7 +58,10 @@ auto migration_table_sql(noto::migration_options const& options) -> std::expecte
|
||||
if (!table) {
|
||||
return std::unexpected(table.error());
|
||||
}
|
||||
return "CREATE TABLE IF NOT EXISTS " + *table + " (\"id\" TEXT NOT NULL PRIMARY KEY, " "\"description\" TEXT NOT NULL, " "\"checksum\" TEXT NOT NULL, " "\"applied_at\" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP) STRICT";
|
||||
return "CREATE TABLE IF NOT EXISTS " + *table + " (\"id\" TEXT NOT NULL PRIMARY KEY, "
|
||||
"\"description\" TEXT NOT NULL, "
|
||||
"\"checksum\" TEXT NOT NULL, "
|
||||
"\"applied_at\" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP) STRICT";
|
||||
}
|
||||
|
||||
auto select_records_sql(noto::migration_options const &options) -> std::expected<std::string, modulus::error> {
|
||||
@@ -200,7 +204,8 @@ auto rollback_and_return(noto::transaction& transaction, modulus::error error) -
|
||||
|
||||
}
|
||||
|
||||
noto::migrator::migrator(noto::connection& connection, noto::migration_options options) : connection_{&connection}, options_{std::move(options)} {}
|
||||
noto::migrator::migrator(noto::connection &connection, noto::migration_options options)
|
||||
: connection_{&connection}, options_{std::move(options)} {}
|
||||
|
||||
auto noto::migrator::async_applied_migrations() -> boost::asio::awaitable<std::expected<std::vector<noto::migration_record>, modulus::error>> {
|
||||
if (connection_ == nullptr) {
|
||||
|
||||
+7
-3
@@ -15,6 +15,7 @@
|
||||
#include <noto/detail/errors.hpp>
|
||||
#include <noto/detail/sql.hpp>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
auto invalid_sql(std::string message) -> std::expected<std::string, modulus::error> {
|
||||
@@ -272,7 +273,8 @@ auto noto::trusted_sql_fragment::empty() const -> std::bool_t {
|
||||
return sql_.empty();
|
||||
}
|
||||
|
||||
noto::trusted_sql_fragment::trusted_sql_fragment(std::string sql) : sql_{std::move(sql)} {}
|
||||
noto::trusted_sql_fragment::trusted_sql_fragment(std::string sql)
|
||||
: sql_{std::move(sql)} {}
|
||||
|
||||
auto noto::column_type::integer() -> noto::column_type {
|
||||
return noto::column_type{"INTEGER"};
|
||||
@@ -331,7 +333,8 @@ auto noto::column_type::empty() const -> std::bool_t {
|
||||
return sql_.empty();
|
||||
}
|
||||
|
||||
noto::column_type::column_type(std::string sql) : sql_{std::move(sql)} {}
|
||||
noto::column_type::column_type(std::string sql)
|
||||
: sql_{std::move(sql)} {}
|
||||
|
||||
auto noto::default_value::null_value() -> noto::default_value {
|
||||
return noto::default_value{"NULL"};
|
||||
@@ -382,7 +385,8 @@ auto noto::default_value::empty() const -> std::bool_t {
|
||||
return sql_.empty();
|
||||
}
|
||||
|
||||
noto::default_value::default_value(std::string sql) : sql_{std::move(sql)} {}
|
||||
noto::default_value::default_value(std::string sql)
|
||||
: sql_{std::move(sql)} {}
|
||||
|
||||
auto noto::quote_identifier(std::string_view identifier) -> std::expected<std::string, modulus::error> {
|
||||
auto valid = validate_identifier(identifier);
|
||||
|
||||
+7
-3
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <noto/detail/core.hpp>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
auto inactive_transaction() -> std::expected<void, modulus::error> {
|
||||
@@ -76,7 +77,8 @@ auto async_rollback_impl(std::shared_ptr<noto::detail::transaction_state> state)
|
||||
|
||||
}
|
||||
|
||||
noto::transaction::transaction(noto::transaction&& other) noexcept : state_{std::move(other.state_)} {}
|
||||
noto::transaction::transaction(noto::transaction &&other) noexcept
|
||||
: state_{std::move(other.state_)} {}
|
||||
|
||||
noto::transaction::~transaction() {
|
||||
if (!state_) {
|
||||
@@ -106,6 +108,8 @@ auto noto::transaction::async_rollback() -> boost::asio::awaitable<std::expected
|
||||
return async_rollback_impl(state_);
|
||||
}
|
||||
|
||||
noto::transaction::transaction(std::shared_ptr<noto::detail::transaction_state> state) : state_{std::move(state)} {}
|
||||
noto::transaction::transaction(std::shared_ptr<noto::detail::transaction_state> state)
|
||||
: state_{std::move(state)} {}
|
||||
|
||||
noto::transaction::transaction(std::shared_ptr<noto::detail::connection_core> core, std::function<void()> on_finish) : state_{std::make_shared<noto::detail::transaction_state>(std::move(core), std::move(on_finish))} {}
|
||||
noto::transaction::transaction(std::shared_ptr<noto::detail::connection_core> core, std::function<void()> on_finish)
|
||||
: state_{std::make_shared<noto::detail::transaction_state>(std::move(core), std::move(on_finish))} {}
|
||||
|
||||
+5
-109
@@ -34,6 +34,7 @@
|
||||
#include <noto/schema.hpp>
|
||||
#include <noto/transaction.hpp>
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(noto_asserts_follow_build_type) {
|
||||
#if defined(NOTO_EXPECT_NDEBUG) && !defined(NDEBUG)
|
||||
BOOST_FAIL("release-style builds must define NDEBUG");
|
||||
@@ -43,7 +44,6 @@ BOOST_AUTO_TEST_CASE(noto_asserts_follow_build_type) {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename AWAITABLE>
|
||||
@@ -146,7 +146,6 @@ BOOST_AUTO_TEST_CASE(noto_status_defaults_to_ok) {
|
||||
BOOST_AUTO_TEST_CASE(noto_result_carries_failure_status) {
|
||||
auto ok = std::expected<void, modulus::error>{};
|
||||
BOOST_TEST(static_cast<std::bool_t>(ok.has_value()));
|
||||
|
||||
auto result = noto::detail::fail<std::int32_t>(noto::detail::error_invalid_argument, "bad value");
|
||||
BOOST_REQUIRE(!result);
|
||||
BOOST_TEST(static_cast<std::int32_t>(result.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
@@ -163,10 +162,8 @@ BOOST_AUTO_TEST_CASE(noto_status_maps_sqlite_errors) {
|
||||
BOOST_AUTO_TEST_CASE(noto_config_validates_and_parses_json) {
|
||||
auto config = noto::connection_config{};
|
||||
BOOST_TEST(static_cast<std::bool_t>(noto::validate(config)));
|
||||
|
||||
config.filename = "";
|
||||
BOOST_TEST(!static_cast<std::bool_t>(noto::validate(config)));
|
||||
|
||||
auto value = boost::json::parse(R"json({
|
||||
"databases": [
|
||||
{
|
||||
@@ -196,27 +193,19 @@ BOOST_AUTO_TEST_CASE(noto_config_validates_and_parses_json) {
|
||||
BOOST_TEST(round_trip->at(0).name == "main");
|
||||
BOOST_TEST(static_cast<std::int32_t>(round_trip->at(0).mode) == static_cast<std::int32_t>(noto::open_mode::MEMORY));
|
||||
BOOST_TEST(round_trip->at(0).pragmas.size() == 2U);
|
||||
|
||||
auto bad = noto::parse_database_configs(boost::json::parse(R"json({"databases":[{"name":"bad","filename":":memory:","mode":"server"}]})json"));
|
||||
BOOST_TEST(!static_cast<std::bool_t>(bad.has_value()));
|
||||
|
||||
auto missing_file = noto::parse_database_configs(boost::json::parse(R"json({"databases":[{"name":"bad"}]})json"));
|
||||
BOOST_TEST(!static_cast<std::bool_t>(missing_file.has_value()));
|
||||
|
||||
config.filename = ":memory:";
|
||||
config.busy_timeout = std::chrono::milliseconds{static_cast<std::int64_t>(std::numeric_limits<std::int32_t>::max()) + 1};
|
||||
BOOST_TEST(!static_cast<std::bool_t>(noto::validate(config)));
|
||||
|
||||
auto oversized_timeout_json = std::string{R"json({"databases":[{"name":"bad","filename":":memory:","busy_timeout_ms":)json"}
|
||||
+ std::to_string(static_cast<std::int64_t>(std::numeric_limits<std::int32_t>::max()) + 1)
|
||||
+ R"json(}]})json";
|
||||
auto oversized_timeout_json = std::string{R"json({"databases":[{"name":"bad","filename":":memory:","busy_timeout_ms":)json"} + std::to_string(static_cast<std::int64_t>(std::numeric_limits<std::int32_t>::max()) + 1) + R"json(}]})json";
|
||||
auto oversized_timeout = noto::parse_database_configs(boost::json::parse(oversized_timeout_json));
|
||||
BOOST_TEST(!static_cast<std::bool_t>(oversized_timeout.has_value()));
|
||||
|
||||
auto unknown_root = noto::parse_database_configs(boost::json::parse(R"json({"databases":[],"databasez":[]})json"));
|
||||
BOOST_REQUIRE(!unknown_root);
|
||||
BOOST_TEST(unknown_root.error().describe().find("config root has unknown key: databasez") != std::string::npos);
|
||||
|
||||
auto unknown_database = noto::parse_database_configs(boost::json::parse(R"json({"databases":[{"name":"bad","filename":":memory:","busy_timout_ms":250}]})json"));
|
||||
BOOST_REQUIRE(!unknown_database);
|
||||
BOOST_TEST(unknown_database.error().describe().find("database has unknown key: busy_timout_ms") != std::string::npos);
|
||||
@@ -226,7 +215,6 @@ BOOST_AUTO_TEST_CASE(noto_schema_quotes_identifiers_and_builds_sqlite_table_sql)
|
||||
auto quoted = noto::quote_identifier("with\"quote");
|
||||
BOOST_REQUIRE(quoted);
|
||||
BOOST_TEST(*quoted == "\"with\"\"quote\"");
|
||||
|
||||
auto email_type = noto::column_type::varchar(255);
|
||||
BOOST_REQUIRE(email_type);
|
||||
auto sql = noto::create_table_sql({
|
||||
@@ -257,7 +245,6 @@ BOOST_AUTO_TEST_CASE(noto_schema_quotes_identifiers_and_builds_sqlite_table_sql)
|
||||
.strict = true,
|
||||
},
|
||||
});
|
||||
|
||||
BOOST_REQUIRE(sql);
|
||||
BOOST_TEST(*sql == "CREATE TABLE IF NOT EXISTS \"users\" (\"id\" INTEGER PRIMARY KEY AUTOINCREMENT, \"email\" TEXT NOT NULL, \"created_at\" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP) STRICT");
|
||||
}
|
||||
@@ -335,7 +322,6 @@ BOOST_AUTO_TEST_CASE(noto_schema_builds_constraints_generated_columns_and_option
|
||||
.without_rowid = true,
|
||||
},
|
||||
});
|
||||
|
||||
BOOST_REQUIRE(sql);
|
||||
BOOST_TEST(*sql == "CREATE TABLE IF NOT EXISTS \"accounts\" (\"tenant_id\" INTEGER NOT NULL, \"id\" INTEGER NOT NULL, \"email\" TEXT NOT NULL, \"email_key\" TEXT GENERATED ALWAYS AS (lower(\"email\")) STORED NOT NULL, PRIMARY KEY (\"tenant_id\", \"id\"), CONSTRAINT \"uq_accounts_email\" UNIQUE (\"tenant_id\", \"email_key\"), CONSTRAINT \"ck_accounts_email\" CHECK (\"email\" <> ''), CONSTRAINT \"fk_accounts_tenant\" FOREIGN KEY (\"tenant_id\") REFERENCES \"tenants\" (\"id\") ON DELETE CASCADE) WITHOUT ROWID");
|
||||
}
|
||||
@@ -346,14 +332,11 @@ BOOST_AUTO_TEST_CASE(noto_connection_executes_queries_and_prepared_statements) {
|
||||
io.get_executor(),
|
||||
noto::memory_connection_config("test"),
|
||||
};
|
||||
|
||||
auto connected = run(io, connection.async_connect());
|
||||
BOOST_TEST(static_cast<std::bool_t>(connected));
|
||||
BOOST_TEST(static_cast<std::int32_t>(connection.state()) == static_cast<std::int32_t>(noto::connection_state::CONNECTED));
|
||||
|
||||
auto created = run(io, connection.async_execute("CREATE TABLE items(id INTEGER PRIMARY KEY, value TEXT NOT NULL)"));
|
||||
BOOST_REQUIRE(created);
|
||||
|
||||
auto statement = run(io, connection.async_prepare("INSERT INTO items(value) VALUES(?1)"));
|
||||
BOOST_REQUIRE(statement);
|
||||
auto inserted = run(io, statement->async_execute({
|
||||
@@ -361,14 +344,12 @@ BOOST_AUTO_TEST_CASE(noto_connection_executes_queries_and_prepared_statements) {
|
||||
}));
|
||||
BOOST_REQUIRE(inserted);
|
||||
BOOST_TEST(inserted->changes == 1);
|
||||
|
||||
auto selected = run(io, connection.async_execute("SELECT value FROM items WHERE id = ?1", {
|
||||
noto::sqlite_value{inserted->last_insert_rowid},
|
||||
}));
|
||||
BOOST_REQUIRE(selected);
|
||||
BOOST_REQUIRE(selected->rows.size() == 1U);
|
||||
BOOST_TEST(text_value(selected->rows.at(0).at(0)) == "alpha");
|
||||
|
||||
auto finalized = run(io, statement->async_finalize());
|
||||
BOOST_TEST(static_cast<std::bool_t>(finalized));
|
||||
auto closed = run(io, connection.async_close());
|
||||
@@ -382,14 +363,12 @@ BOOST_AUTO_TEST_CASE(noto_close_with_live_statement_is_recoverable) {
|
||||
noto::memory_connection_config("live_statement"),
|
||||
};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
|
||||
auto statement = run(io, connection.async_prepare("SELECT 1"));
|
||||
BOOST_REQUIRE(statement);
|
||||
auto blocked = run(io, connection.async_close());
|
||||
BOOST_TEST(!static_cast<std::bool_t>(blocked));
|
||||
BOOST_TEST(static_cast<std::int32_t>(blocked.error().code()) == static_cast<std::int32_t>(noto::detail::error_unavailable));
|
||||
BOOST_TEST(static_cast<std::int32_t>(connection.state()) == static_cast<std::int32_t>(noto::connection_state::CONNECTED));
|
||||
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, statement->async_finalize())));
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_close())));
|
||||
}
|
||||
@@ -403,14 +382,12 @@ BOOST_AUTO_TEST_CASE(noto_close_rolls_back_active_transaction) {
|
||||
};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE items(value TEXT NOT NULL)")));
|
||||
|
||||
{
|
||||
auto transaction = run(io, connection.async_begin_transaction());
|
||||
BOOST_REQUIRE(transaction);
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO items(value) VALUES('transient')")));
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_close())));
|
||||
}
|
||||
|
||||
auto reopened = noto::connection{
|
||||
io.get_executor(),
|
||||
noto::file_connection_config(path),
|
||||
@@ -425,33 +402,29 @@ BOOST_AUTO_TEST_CASE(noto_close_rolls_back_active_transaction) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(noto_async_methods_capture_state_from_temporary_wrappers) {
|
||||
auto io = boost::asio::io_context{};
|
||||
|
||||
auto connect_future = boost::asio::co_spawn(
|
||||
io,
|
||||
noto::connection{
|
||||
io.get_executor(),
|
||||
noto::memory_connection_config("temporary_connection"),
|
||||
}.async_connect(),
|
||||
boost::asio::use_future
|
||||
);
|
||||
}
|
||||
.async_connect(),
|
||||
boost::asio::use_future);
|
||||
io.run();
|
||||
io.restart();
|
||||
BOOST_TEST(static_cast<std::bool_t>(connect_future.get()));
|
||||
|
||||
auto connection = noto::connection{
|
||||
io.get_executor(),
|
||||
noto::memory_connection_config("temporary_wrappers"),
|
||||
};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE items(value TEXT NOT NULL)")));
|
||||
|
||||
auto statement = run(io, connection.async_prepare("SELECT 1"));
|
||||
BOOST_REQUIRE(statement);
|
||||
auto finalize_future = boost::asio::co_spawn(io, noto::statement{std::move(*statement)}.async_finalize(), boost::asio::use_future);
|
||||
io.run();
|
||||
io.restart();
|
||||
BOOST_TEST(static_cast<std::bool_t>(finalize_future.get()));
|
||||
|
||||
auto rolled_back = run(io, connection.async_begin_transaction());
|
||||
BOOST_REQUIRE(rolled_back);
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO items(value) VALUES('rolled back')")));
|
||||
@@ -459,7 +432,6 @@ BOOST_AUTO_TEST_CASE(noto_async_methods_capture_state_from_temporary_wrappers) {
|
||||
io.run();
|
||||
io.restart();
|
||||
BOOST_TEST(static_cast<std::bool_t>(rollback_future.get()));
|
||||
|
||||
auto committed = run(io, connection.async_begin_transaction());
|
||||
BOOST_REQUIRE(committed);
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO items(value) VALUES('committed')")));
|
||||
@@ -467,7 +439,6 @@ BOOST_AUTO_TEST_CASE(noto_async_methods_capture_state_from_temporary_wrappers) {
|
||||
io.run();
|
||||
io.restart();
|
||||
BOOST_TEST(static_cast<std::bool_t>(commit_future.get()));
|
||||
|
||||
auto count = run(io, connection.async_execute("SELECT COUNT(*) FROM items"));
|
||||
BOOST_REQUIRE(count);
|
||||
BOOST_TEST(int_value(count->rows.at(0).at(0)) == 1);
|
||||
@@ -483,22 +454,18 @@ BOOST_AUTO_TEST_CASE(noto_detached_transaction_rolls_back_when_commit_cannot_sta
|
||||
};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE items(value INTEGER NOT NULL)")));
|
||||
|
||||
auto transaction = run(io, connection.async_begin_transaction());
|
||||
BOOST_REQUIRE(transaction);
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO items(value) VALUES(1), (2), (3), (4), (5)")));
|
||||
|
||||
auto options = noto::export_options{};
|
||||
options.rows_per_yield = 1;
|
||||
auto export_future = boost::asio::co_spawn(io, connection.async_export_sql_to_file(export_path, options), boost::asio::use_future);
|
||||
auto commit_future = boost::asio::co_spawn(io, noto::transaction{std::move(*transaction)}.async_commit(), boost::asio::use_future);
|
||||
io.run();
|
||||
io.restart();
|
||||
|
||||
BOOST_TEST(static_cast<std::bool_t>(export_future.get()));
|
||||
auto commit = commit_future.get();
|
||||
BOOST_TEST(static_cast<std::int32_t>(commit.error().code()) == static_cast<std::int32_t>(noto::detail::error_unavailable));
|
||||
|
||||
auto count = run(io, connection.async_execute("SELECT COUNT(*) FROM items"));
|
||||
BOOST_REQUIRE(count);
|
||||
BOOST_TEST(int_value(count->rows.at(0).at(0)) == 0);
|
||||
@@ -513,12 +480,10 @@ BOOST_AUTO_TEST_CASE(noto_statement_destructor_cleanup_allows_close) {
|
||||
noto::memory_connection_config("statement_destructor"),
|
||||
};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
|
||||
{
|
||||
auto statement = run(io, connection.async_prepare("SELECT 1"));
|
||||
BOOST_REQUIRE(statement);
|
||||
}
|
||||
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_close())));
|
||||
}
|
||||
|
||||
@@ -530,7 +495,6 @@ BOOST_AUTO_TEST_CASE(noto_transactions_commit_and_rollback) {
|
||||
};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE items(value TEXT NOT NULL)")));
|
||||
|
||||
{
|
||||
auto transaction = run(io, connection.async_begin_transaction());
|
||||
BOOST_REQUIRE(transaction);
|
||||
@@ -540,7 +504,6 @@ BOOST_AUTO_TEST_CASE(noto_transactions_commit_and_rollback) {
|
||||
auto count = run(io, connection.async_execute("SELECT COUNT(*) FROM items"));
|
||||
BOOST_REQUIRE(count);
|
||||
BOOST_TEST(int_value(count->rows.at(0).at(0)) == 0);
|
||||
|
||||
{
|
||||
auto transaction = run(io, connection.async_begin_transaction());
|
||||
BOOST_REQUIRE(transaction);
|
||||
@@ -561,21 +524,17 @@ BOOST_AUTO_TEST_CASE(noto_failed_commit_remains_rollbackable) {
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE parents(id INTEGER PRIMARY KEY)")));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE children(parent_id INTEGER NOT NULL, FOREIGN KEY(parent_id) REFERENCES parents(id) DEFERRABLE INITIALLY DEFERRED)")));
|
||||
|
||||
auto transaction = run(io, connection.async_begin_transaction(noto::transaction_mode::DEFERRED));
|
||||
BOOST_REQUIRE(transaction);
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO children(parent_id) VALUES(42)")));
|
||||
|
||||
auto committed = run(io, transaction->async_commit());
|
||||
BOOST_TEST(!static_cast<std::bool_t>(committed));
|
||||
BOOST_TEST(static_cast<std::int32_t>(committed.error().code()) == static_cast<std::int32_t>(noto::detail::error_constraint_violation));
|
||||
BOOST_TEST(static_cast<std::bool_t>(transaction->active()));
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, transaction->async_rollback())));
|
||||
|
||||
auto count = run(io, connection.async_execute("SELECT COUNT(*) FROM children"));
|
||||
BOOST_REQUIRE(count);
|
||||
BOOST_TEST(int_value(count->rows.at(0).at(0)) == 0);
|
||||
|
||||
auto next = run(io, connection.async_begin_transaction());
|
||||
BOOST_REQUIRE(next);
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, next->async_rollback())));
|
||||
@@ -591,22 +550,18 @@ BOOST_AUTO_TEST_CASE(noto_detached_failed_commit_rolls_back) {
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE parents(id INTEGER PRIMARY KEY)")));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE children(parent_id INTEGER NOT NULL, FOREIGN KEY(parent_id) REFERENCES parents(id) DEFERRABLE INITIALLY DEFERRED)")));
|
||||
|
||||
auto transaction = run(io, connection.async_begin_transaction(noto::transaction_mode::DEFERRED));
|
||||
BOOST_REQUIRE(transaction);
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO children(parent_id) VALUES(42)")));
|
||||
|
||||
auto commit_future = boost::asio::co_spawn(io, noto::transaction{std::move(*transaction)}.async_commit(), boost::asio::use_future);
|
||||
io.run();
|
||||
io.restart();
|
||||
auto committed = commit_future.get();
|
||||
BOOST_TEST(!static_cast<std::bool_t>(committed));
|
||||
BOOST_TEST(static_cast<std::int32_t>(committed.error().code()) == static_cast<std::int32_t>(noto::detail::error_constraint_violation));
|
||||
|
||||
auto count = run(io, connection.async_execute("SELECT COUNT(*) FROM children"));
|
||||
BOOST_REQUIRE(count);
|
||||
BOOST_TEST(int_value(count->rows.at(0).at(0)) == 0);
|
||||
|
||||
auto next = run(io, connection.async_begin_transaction());
|
||||
BOOST_REQUIRE(next);
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, next->async_rollback())));
|
||||
@@ -621,13 +576,11 @@ BOOST_AUTO_TEST_CASE(noto_abandoned_transaction_rolls_back_before_next_operation
|
||||
};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE items(value TEXT NOT NULL)")));
|
||||
|
||||
{
|
||||
auto transaction = run(io, connection.async_begin_transaction());
|
||||
BOOST_REQUIRE(transaction);
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO items(value) VALUES('abandoned')")));
|
||||
}
|
||||
|
||||
auto count = run(io, connection.async_execute("SELECT COUNT(*) FROM items"));
|
||||
BOOST_REQUIRE(count);
|
||||
BOOST_TEST(int_value(count->rows.at(0).at(0)) == 0);
|
||||
@@ -642,7 +595,6 @@ BOOST_AUTO_TEST_CASE(noto_transaction_callback_exceptions_return_status_and_roll
|
||||
};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE items(value TEXT NOT NULL)")));
|
||||
|
||||
auto status = run(io, connection.async_with_transaction(noto::transaction_mode::IMMEDIATE, [](noto::connection &active) -> boost::asio::awaitable<std::expected<void, modulus::error>> {
|
||||
auto inserted = co_await active.async_execute("INSERT INTO items(value) VALUES('temporary')");
|
||||
if (!inserted) {
|
||||
@@ -652,7 +604,6 @@ BOOST_AUTO_TEST_CASE(noto_transaction_callback_exceptions_return_status_and_roll
|
||||
}));
|
||||
BOOST_TEST(!static_cast<std::bool_t>(status));
|
||||
BOOST_TEST(static_cast<std::int32_t>(status.error().code()) == static_cast<std::int32_t>(noto::detail::error_internal));
|
||||
|
||||
auto count = run(io, connection.async_execute("SELECT COUNT(*) FROM items"));
|
||||
BOOST_REQUIRE(count);
|
||||
BOOST_TEST(int_value(count->rows.at(0).at(0)) == 0);
|
||||
@@ -667,19 +618,16 @@ BOOST_AUTO_TEST_CASE(noto_execute_options_limit_collected_results) {
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE items(value TEXT NOT NULL)")));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO items(value) VALUES('one'), ('two')")));
|
||||
|
||||
auto row_options = noto::execute_options{};
|
||||
row_options.max_rows = 1;
|
||||
auto too_many_rows = run(io, connection.async_execute("SELECT value FROM items ORDER BY value", {}, row_options));
|
||||
BOOST_REQUIRE(!too_many_rows);
|
||||
BOOST_TEST(static_cast<std::int32_t>(too_many_rows.error().code()) == static_cast<std::int32_t>(noto::detail::error_resource_exhausted));
|
||||
|
||||
auto byte_options = noto::execute_options{};
|
||||
byte_options.max_result_bytes = 4;
|
||||
auto too_many_bytes = run(io, connection.async_execute("SELECT value FROM items WHERE value = 'one'", {}, byte_options));
|
||||
BOOST_REQUIRE(!too_many_bytes);
|
||||
BOOST_TEST(static_cast<std::int32_t>(too_many_bytes.error().code()) == static_cast<std::int32_t>(noto::detail::error_resource_exhausted));
|
||||
|
||||
auto statement = run(io, connection.async_prepare("SELECT value FROM items ORDER BY value"));
|
||||
BOOST_REQUIRE(statement);
|
||||
auto statement_options = noto::execute_options{};
|
||||
@@ -700,7 +648,6 @@ BOOST_AUTO_TEST_CASE(noto_migrations_apply_validate_and_rollback) {
|
||||
noto::memory_connection_config(),
|
||||
};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
|
||||
auto migrations = std::vector<noto::migration>{
|
||||
{
|
||||
.id = "001_create_table",
|
||||
@@ -717,18 +664,15 @@ BOOST_AUTO_TEST_CASE(noto_migrations_apply_validate_and_rollback) {
|
||||
auto migrator = noto::migrator{connection};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, migrator.async_migrate(migrations))));
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, migrator.async_migrate(migrations))));
|
||||
|
||||
auto changed = migrations;
|
||||
changed.at(0).checksum = "changed";
|
||||
auto mismatch = run(io, migrator.async_migrate(changed));
|
||||
BOOST_TEST(!static_cast<std::bool_t>(mismatch));
|
||||
BOOST_TEST(static_cast<std::int32_t>(mismatch.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
|
||||
auto records = run(io, migrator.async_applied_migrations());
|
||||
BOOST_REQUIRE(records);
|
||||
BOOST_TEST(records->size() == 1U);
|
||||
BOOST_TEST(records->at(0).id == "001_create_table");
|
||||
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, migrator.async_rollback(migrations))));
|
||||
auto missing = run(io, connection.async_execute("SELECT name FROM sqlite_schema WHERE type = 'table' AND name = 'items'"));
|
||||
BOOST_REQUIRE(missing);
|
||||
@@ -742,7 +686,6 @@ BOOST_AUTO_TEST_CASE(noto_backup_export_integrity_and_pragmas_work) {
|
||||
auto failed_backup_path = temp_database_path("failed_backup");
|
||||
auto oversized_retry_path = temp_database_path("oversized_retry");
|
||||
auto export_path = temp_database_path("export_sql");
|
||||
|
||||
auto connection = noto::connection{
|
||||
io.get_executor(),
|
||||
noto::file_connection_config(source_path),
|
||||
@@ -759,14 +702,12 @@ BOOST_AUTO_TEST_CASE(noto_backup_export_integrity_and_pragmas_work) {
|
||||
auto busy_timeout = run(io, connection.async_busy_timeout());
|
||||
BOOST_REQUIRE(busy_timeout);
|
||||
BOOST_TEST(*busy_timeout == std::chrono::milliseconds{37});
|
||||
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE items(id INTEGER PRIMARY KEY, value TEXT NOT NULL)")));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO items(value) VALUES('one'), ('two')")));
|
||||
auto integrity = run(io, connection.async_integrity_check());
|
||||
BOOST_REQUIRE(integrity);
|
||||
BOOST_REQUIRE(integrity->size() == 1U);
|
||||
BOOST_TEST(integrity->at(0) == "ok");
|
||||
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_backup_to_file(backup_path))));
|
||||
auto exported = run(io, connection.async_export_sql());
|
||||
BOOST_REQUIRE(exported);
|
||||
@@ -776,7 +717,6 @@ BOOST_AUTO_TEST_CASE(noto_backup_export_integrity_and_pragmas_work) {
|
||||
auto limited_export = run(io, connection.async_export_sql(limited_options));
|
||||
BOOST_REQUIRE(!limited_export);
|
||||
BOOST_TEST(static_cast<std::int32_t>(limited_export.error().code()) == static_cast<std::int32_t>(noto::detail::error_resource_exhausted));
|
||||
|
||||
auto *preserved = static_cast<sqlite3 *>(nullptr);
|
||||
BOOST_REQUIRE(sqlite3_open_v2(failed_backup_path.c_str(), &preserved, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, nullptr) == SQLITE_OK);
|
||||
BOOST_REQUIRE(sqlite_exec_ok(preserved, "CREATE TABLE preserved(value INTEGER); INSERT INTO preserved(value) VALUES(42)"));
|
||||
@@ -789,17 +729,14 @@ BOOST_AUTO_TEST_CASE(noto_backup_export_integrity_and_pragmas_work) {
|
||||
BOOST_REQUIRE(sqlite3_open_v2(failed_backup_path.c_str(), &preserved, SQLITE_OPEN_READONLY | SQLITE_OPEN_FULLMUTEX, nullptr) == SQLITE_OK);
|
||||
BOOST_TEST(sqlite_scalar_int64(preserved, "SELECT value FROM preserved") == 42);
|
||||
sqlite3_close(preserved);
|
||||
|
||||
auto oversized_retry = noto::backup_options{};
|
||||
oversized_retry.retry_delay = std::chrono::milliseconds{static_cast<std::int64_t>(std::numeric_limits<std::int32_t>::max()) + 1};
|
||||
auto failed_delay = run(io, connection.async_backup_to_file(oversized_retry_path, oversized_retry));
|
||||
BOOST_TEST(static_cast<std::int32_t>(failed_delay.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
|
||||
oversized_retry = noto::backup_options{};
|
||||
oversized_retry.retry_timeout = std::chrono::milliseconds{static_cast<std::int64_t>(std::numeric_limits<std::int32_t>::max()) + 1};
|
||||
auto failed_timeout = run(io, connection.async_backup_to_file(oversized_retry_path, oversized_retry));
|
||||
BOOST_TEST(static_cast<std::int32_t>(failed_timeout.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
|
||||
write_file(export_path, "preserved export");
|
||||
auto limited_file_options = noto::export_options{};
|
||||
limited_file_options.max_output_bytes = 16;
|
||||
@@ -807,11 +744,9 @@ BOOST_AUTO_TEST_CASE(noto_backup_export_integrity_and_pragmas_work) {
|
||||
BOOST_REQUIRE(!limited_file_export);
|
||||
BOOST_TEST(static_cast<std::int32_t>(limited_file_export.error().code()) == static_cast<std::int32_t>(noto::detail::error_resource_exhausted));
|
||||
BOOST_TEST(read_file(export_path) == "preserved export");
|
||||
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_export_sql_to_file(export_path))));
|
||||
BOOST_TEST(static_cast<std::bool_t>(std::filesystem::exists(export_path)));
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_close())));
|
||||
|
||||
auto restored = noto::connection{
|
||||
io.get_executor(),
|
||||
noto::file_connection_config(backup_path),
|
||||
@@ -821,7 +756,6 @@ BOOST_AUTO_TEST_CASE(noto_backup_export_integrity_and_pragmas_work) {
|
||||
BOOST_REQUIRE(count);
|
||||
BOOST_TEST(int_value(count->rows.at(0).at(0)) == 2);
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, restored.async_close())));
|
||||
|
||||
std::filesystem::remove(source_path);
|
||||
std::filesystem::remove(backup_path);
|
||||
std::filesystem::remove(failed_backup_path);
|
||||
@@ -840,19 +774,16 @@ BOOST_AUTO_TEST_CASE(noto_backup_and_export_reject_live_database_destinations) {
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE items(value TEXT NOT NULL)")));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO items(value) VALUES('safe')")));
|
||||
|
||||
auto self_backup = run(io, connection.async_backup_to_file(source_path));
|
||||
BOOST_TEST(static_cast<std::int32_t>(self_backup.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
auto self_export = run(io, connection.async_export_sql_to_file(source_path));
|
||||
BOOST_TEST(static_cast<std::int32_t>(self_export.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
|
||||
for (auto suffix : std::array<std::string_view, 3>{"-wal", "-shm", "-journal"}) {
|
||||
auto backup = run(io, connection.async_backup_to_file(source_path + std::string{suffix}));
|
||||
BOOST_TEST(static_cast<std::int32_t>(backup.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
auto exported = run(io, connection.async_export_sql_to_file(source_path + std::string{suffix}));
|
||||
BOOST_TEST(static_cast<std::int32_t>(exported.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
}
|
||||
|
||||
auto error = std::error_code{};
|
||||
std::filesystem::create_symlink(source_path, link_path, error);
|
||||
if (!error) {
|
||||
@@ -861,7 +792,6 @@ BOOST_AUTO_TEST_CASE(noto_backup_and_export_reject_live_database_destinations) {
|
||||
auto link_export = run(io, connection.async_export_sql_to_file(link_path));
|
||||
BOOST_TEST(static_cast<std::int32_t>(link_export.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
}
|
||||
|
||||
auto rows = run(io, connection.async_execute("SELECT value FROM items"));
|
||||
BOOST_REQUIRE(rows);
|
||||
BOOST_REQUIRE(rows->rows.size() == 1U);
|
||||
@@ -875,9 +805,7 @@ BOOST_AUTO_TEST_CASE(noto_restore_to_file_is_atomic_and_reopens_connection) {
|
||||
auto io = boost::asio::io_context{};
|
||||
auto source_path = temp_database_path("restore_source");
|
||||
auto target_path = temp_database_path("restore_target");
|
||||
|
||||
BOOST_REQUIRE(create_sqlite_database(source_path, "CREATE TABLE items(value TEXT NOT NULL); INSERT INTO items(value) VALUES('new')"));
|
||||
|
||||
auto connection = noto::connection{
|
||||
io.get_executor(),
|
||||
noto::file_connection_config(target_path),
|
||||
@@ -890,13 +818,11 @@ BOOST_AUTO_TEST_CASE(noto_restore_to_file_is_atomic_and_reopens_connection) {
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_set_busy_timeout(std::chrono::milliseconds{37}))));
|
||||
write_file(target_path + "-journal", "stale rollback journal");
|
||||
BOOST_TEST(static_cast<std::bool_t>(std::filesystem::exists(target_path + "-journal")));
|
||||
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_restore_from_file(source_path))));
|
||||
BOOST_TEST(static_cast<std::int32_t>(connection.state()) == static_cast<std::int32_t>(noto::connection_state::CONNECTED));
|
||||
auto timeout = run(io, connection.async_busy_timeout());
|
||||
BOOST_REQUIRE(timeout);
|
||||
BOOST_TEST(*timeout == std::chrono::milliseconds{37});
|
||||
|
||||
auto rows = run(io, connection.async_execute("SELECT value FROM items"));
|
||||
BOOST_REQUIRE(rows);
|
||||
BOOST_REQUIRE(rows->rows.size() == 1U);
|
||||
@@ -905,12 +831,10 @@ BOOST_AUTO_TEST_CASE(noto_restore_to_file_is_atomic_and_reopens_connection) {
|
||||
BOOST_TEST(!static_cast<std::bool_t>(std::filesystem::exists(target_path + "-wal")));
|
||||
BOOST_TEST(!static_cast<std::bool_t>(std::filesystem::exists(target_path + "-shm")));
|
||||
BOOST_TEST(!static_cast<std::bool_t>(std::filesystem::exists(target_path + "-journal")));
|
||||
|
||||
auto *restored = static_cast<sqlite3 *>(nullptr);
|
||||
BOOST_REQUIRE(sqlite3_open_v2(target_path.c_str(), &restored, SQLITE_OPEN_READONLY | SQLITE_OPEN_FULLMUTEX, nullptr) == SQLITE_OK);
|
||||
BOOST_TEST(sqlite_scalar_int64(restored, "SELECT COUNT(*) FROM items WHERE value = 'new'") == 1);
|
||||
sqlite3_close(restored);
|
||||
|
||||
remove_database_files(source_path);
|
||||
remove_database_files(target_path);
|
||||
}
|
||||
@@ -919,10 +843,8 @@ BOOST_AUTO_TEST_CASE(noto_failed_restore_leaves_existing_database_intact) {
|
||||
auto io = boost::asio::io_context{};
|
||||
auto source_path = temp_database_path("restore_failure_source");
|
||||
auto target_path = temp_database_path("restore_failure_target");
|
||||
|
||||
BOOST_REQUIRE(create_sqlite_database(source_path, "CREATE TABLE items(value TEXT NOT NULL); INSERT INTO items(value) VALUES('new')"));
|
||||
BOOST_REQUIRE(create_sqlite_database(target_path, "CREATE TABLE items(value TEXT NOT NULL); INSERT INTO items(value) VALUES('old')"));
|
||||
|
||||
auto connection = noto::connection{
|
||||
io.get_executor(),
|
||||
noto::file_connection_config(target_path),
|
||||
@@ -932,13 +854,11 @@ BOOST_AUTO_TEST_CASE(noto_failed_restore_leaves_existing_database_intact) {
|
||||
options.source_name = "missing";
|
||||
auto restored = run(io, connection.async_restore_from_file(source_path, options));
|
||||
BOOST_TEST(!static_cast<std::bool_t>(restored));
|
||||
|
||||
auto rows = run(io, connection.async_execute("SELECT value FROM items"));
|
||||
BOOST_REQUIRE(rows);
|
||||
BOOST_REQUIRE(rows->rows.size() == 1U);
|
||||
BOOST_TEST(text_value(rows->rows.at(0).at(0)) == "old");
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_close())));
|
||||
|
||||
remove_database_files(source_path);
|
||||
remove_database_files(target_path);
|
||||
}
|
||||
@@ -947,10 +867,8 @@ BOOST_AUTO_TEST_CASE(noto_restore_rejects_unsupported_targets_and_active_state)
|
||||
auto io = boost::asio::io_context{};
|
||||
auto source_path = temp_database_path("restore_reject_source");
|
||||
auto target_path = temp_database_path("restore_reject_target");
|
||||
|
||||
BOOST_REQUIRE(create_sqlite_database(source_path, "CREATE TABLE items(value TEXT NOT NULL); INSERT INTO items(value) VALUES('new')"));
|
||||
BOOST_REQUIRE(create_sqlite_database(target_path, "CREATE TABLE items(value TEXT NOT NULL); INSERT INTO items(value) VALUES('old')"));
|
||||
|
||||
auto memory = noto::connection{
|
||||
io.get_executor(),
|
||||
noto::memory_connection_config("restore_reject_memory"),
|
||||
@@ -959,31 +877,26 @@ BOOST_AUTO_TEST_CASE(noto_restore_rejects_unsupported_targets_and_active_state)
|
||||
auto memory_restore = run(io, memory.async_restore_from_file(source_path));
|
||||
BOOST_TEST(static_cast<std::int32_t>(memory_restore.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, memory.async_close())));
|
||||
|
||||
auto connection = noto::connection{
|
||||
io.get_executor(),
|
||||
noto::file_connection_config(target_path),
|
||||
};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
|
||||
auto options = noto::backup_options{};
|
||||
options.destination_name = "attached";
|
||||
auto non_main = run(io, connection.async_restore_from_file(source_path, options));
|
||||
BOOST_TEST(static_cast<std::int32_t>(non_main.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
|
||||
auto transaction = run(io, connection.async_begin_transaction());
|
||||
BOOST_REQUIRE(transaction);
|
||||
auto active_transaction = run(io, connection.async_restore_from_file(source_path));
|
||||
BOOST_TEST(static_cast<std::int32_t>(active_transaction.error().code()) == static_cast<std::int32_t>(noto::detail::error_unavailable));
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, transaction->async_rollback())));
|
||||
|
||||
auto statement = run(io, connection.async_prepare("SELECT value FROM items"));
|
||||
BOOST_REQUIRE(statement);
|
||||
auto live_statement = run(io, connection.async_restore_from_file(source_path));
|
||||
BOOST_TEST(static_cast<std::int32_t>(live_statement.error().code()) == static_cast<std::int32_t>(noto::detail::error_unavailable));
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, statement->async_finalize())));
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_close())));
|
||||
|
||||
remove_database_files(source_path);
|
||||
remove_database_files(target_path);
|
||||
}
|
||||
@@ -992,7 +905,6 @@ BOOST_AUTO_TEST_CASE(noto_backup_lock_timeout_and_statement_finalize_retry_work)
|
||||
auto io = boost::asio::io_context{};
|
||||
auto source_path = temp_database_path("locked_source");
|
||||
auto backup_path = temp_database_path("locked_backup");
|
||||
|
||||
auto connection = noto::connection{
|
||||
io.get_executor(),
|
||||
noto::file_connection_config(source_path),
|
||||
@@ -1002,25 +914,20 @@ BOOST_AUTO_TEST_CASE(noto_backup_lock_timeout_and_statement_finalize_retry_work)
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO items(value) VALUES('one')")));
|
||||
auto statement = run(io, connection.async_prepare("SELECT value FROM items"));
|
||||
BOOST_REQUIRE(statement);
|
||||
|
||||
auto *blocker = static_cast<sqlite3 *>(nullptr);
|
||||
BOOST_REQUIRE(sqlite3_open_v2(source_path.c_str(), &blocker, SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX, nullptr) == SQLITE_OK);
|
||||
BOOST_REQUIRE(sqlite_exec_ok(blocker, "BEGIN EXCLUSIVE"));
|
||||
|
||||
auto options = noto::backup_options{};
|
||||
options.pages_per_step = 1;
|
||||
options.retry_delay = std::chrono::milliseconds{1};
|
||||
options.retry_timeout = std::chrono::milliseconds{25};
|
||||
|
||||
auto backup_future = boost::asio::co_spawn(io, connection.async_backup_to_file(backup_path, options), boost::asio::use_future);
|
||||
auto finalize_future = boost::asio::co_spawn(io, statement->async_finalize(), boost::asio::use_future);
|
||||
io.run();
|
||||
io.restart();
|
||||
|
||||
auto backup = backup_future.get();
|
||||
auto finalized_while_busy = finalize_future.get();
|
||||
BOOST_TEST(static_cast<std::int32_t>(backup.error().code()) == static_cast<std::int32_t>(noto::detail::error_timeout));
|
||||
|
||||
BOOST_TEST(static_cast<std::bool_t>(sqlite_exec_ok(blocker, "ROLLBACK")));
|
||||
sqlite3_close(blocker);
|
||||
if (!finalized_while_busy) {
|
||||
@@ -1028,7 +935,6 @@ BOOST_AUTO_TEST_CASE(noto_backup_lock_timeout_and_statement_finalize_retry_work)
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, statement->async_finalize())));
|
||||
}
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_close())));
|
||||
|
||||
std::filesystem::remove(source_path);
|
||||
std::filesystem::remove(backup_path);
|
||||
}
|
||||
@@ -1044,7 +950,6 @@ BOOST_AUTO_TEST_CASE(noto_export_preserves_nul_text_and_defers_triggers_until_af
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO audit(count) VALUES(0)")));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE items(value TEXT NOT NULL)")));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TRIGGER items_ai AFTER INSERT ON items BEGIN UPDATE audit SET count = count + 1; END")));
|
||||
|
||||
auto insert = run(io, connection.async_prepare("INSERT INTO items(value) VALUES(?1)"));
|
||||
BOOST_REQUIRE(insert);
|
||||
auto embedded = std::string{
|
||||
@@ -1055,16 +960,13 @@ BOOST_AUTO_TEST_CASE(noto_export_preserves_nul_text_and_defers_triggers_until_af
|
||||
noto::sqlite_value{embedded},
|
||||
})));
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, insert->async_finalize())));
|
||||
|
||||
auto exported = run(io, connection.async_export_sql());
|
||||
BOOST_REQUIRE(exported);
|
||||
BOOST_TEST(exported->find("CAST(X'610062' AS TEXT)") != std::string::npos);
|
||||
BOOST_TEST(exported->find("INSERT INTO \"items\"") < exported->find("CREATE TRIGGER"));
|
||||
|
||||
auto *restored = static_cast<sqlite3 *>(nullptr);
|
||||
BOOST_REQUIRE(sqlite3_open(":memory:", &restored) == SQLITE_OK);
|
||||
BOOST_REQUIRE(sqlite_exec_ok(restored, *exported));
|
||||
|
||||
auto *statement = static_cast<sqlite3_stmt *>(nullptr);
|
||||
BOOST_REQUIRE(sqlite3_prepare_v2(restored, "SELECT value FROM items", -1, &statement, nullptr) == SQLITE_OK);
|
||||
BOOST_REQUIRE(sqlite3_step(statement) == SQLITE_ROW);
|
||||
@@ -1076,7 +978,6 @@ BOOST_AUTO_TEST_CASE(noto_export_preserves_nul_text_and_defers_triggers_until_af
|
||||
};
|
||||
sqlite3_finalize(statement);
|
||||
BOOST_TEST(restored_text == embedded);
|
||||
|
||||
statement = nullptr;
|
||||
BOOST_REQUIRE(sqlite3_prepare_v2(restored, "SELECT count FROM audit", -1, &statement, nullptr) == SQLITE_OK);
|
||||
BOOST_REQUIRE(sqlite3_step(statement) == SQLITE_ROW);
|
||||
@@ -1095,13 +996,11 @@ BOOST_AUTO_TEST_CASE(noto_export_preserves_autoincrement_sequence_and_generated_
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("CREATE TABLE items(id INTEGER PRIMARY KEY AUTOINCREMENT, value TEXT NOT NULL, value_size INTEGER GENERATED ALWAYS AS (length(value)) STORED)")));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("INSERT INTO items(value) VALUES('one'), ('two')")));
|
||||
BOOST_REQUIRE(run(io, connection.async_execute("DELETE FROM items WHERE value = 'two'")));
|
||||
|
||||
auto exported = run(io, connection.async_export_sql());
|
||||
BOOST_REQUIRE(exported);
|
||||
BOOST_TEST(exported->find("sqlite_sequence") != std::string::npos);
|
||||
BOOST_TEST(exported->find("value_size") != std::string::npos);
|
||||
BOOST_TEST(exported->find("INSERT INTO \"items\"(\"id\", \"value\")") != std::string::npos);
|
||||
|
||||
auto *restored = static_cast<sqlite3 *>(nullptr);
|
||||
BOOST_REQUIRE(sqlite3_open(":memory:", &restored) == SQLITE_OK);
|
||||
BOOST_REQUIRE(sqlite_exec_ok(restored, *exported));
|
||||
@@ -1122,7 +1021,6 @@ BOOST_AUTO_TEST_CASE(noto_export_rejects_virtual_tables) {
|
||||
if (!created) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto exported = run(io, connection.async_export_sql());
|
||||
BOOST_REQUIRE(!exported);
|
||||
BOOST_TEST(static_cast<std::int32_t>(exported.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
@@ -1135,7 +1033,6 @@ BOOST_AUTO_TEST_CASE(noto_file_helpers_reject_null_byte_paths) {
|
||||
noto::memory_connection_config("path_validation"),
|
||||
};
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_connect())));
|
||||
|
||||
auto bad_path = std::string{
|
||||
"bad\0path",
|
||||
8,
|
||||
@@ -1144,6 +1041,5 @@ BOOST_AUTO_TEST_CASE(noto_file_helpers_reject_null_byte_paths) {
|
||||
BOOST_TEST(static_cast<std::int32_t>(backup.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
auto exported = run(io, connection.async_export_sql_to_file(bad_path));
|
||||
BOOST_TEST(static_cast<std::int32_t>(exported.error().code()) == static_cast<std::int32_t>(noto::detail::error_invalid_argument));
|
||||
|
||||
BOOST_TEST(static_cast<std::bool_t>(run(io, connection.async_close())));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user