updated build system
This commit is contained in:
@ -24,11 +24,6 @@
|
||||
#if defined(PROJECT_ENABLE_SQLITE)
|
||||
|
||||
namespace repertory::utils::db::sqlite {
|
||||
void db_delete::context::clear() {
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
|
||||
auto db_delete::context::db_delete_op_t::dump() const -> std::string {
|
||||
return db_delete{ctx}.dump();
|
||||
}
|
||||
@ -41,9 +36,9 @@ auto db_delete::dump() const -> std::string {
|
||||
std::stringstream query;
|
||||
query << "DELETE FROM \"" << context_->table_name << "\"";
|
||||
|
||||
if (context_->where.has_value()) {
|
||||
if (context_->where_data) {
|
||||
std::int32_t idx{};
|
||||
query << " WHERE " << context_->where->dump(idx);
|
||||
query << " WHERE " << context_->where_data->base.dump(idx);
|
||||
}
|
||||
|
||||
query << ';';
|
||||
@ -65,8 +60,13 @@ auto db_delete::go() const -> db_result<context> {
|
||||
return {context_, res};
|
||||
}
|
||||
|
||||
if (not context_->where_data) {
|
||||
return {context_, res};
|
||||
}
|
||||
|
||||
for (std::int32_t idx = 0;
|
||||
idx < static_cast<std::int32_t>(context_->where_values.size()); idx++) {
|
||||
idx < static_cast<std::int32_t>(context_->where_data->values.size());
|
||||
idx++) {
|
||||
res = std::visit(
|
||||
overloaded{
|
||||
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||
@ -77,7 +77,7 @@ auto db_delete::go() const -> db_result<context> {
|
||||
data.c_str(), -1, nullptr);
|
||||
},
|
||||
},
|
||||
context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||
context_->where_data->values.at(static_cast<std::size_t>(idx)));
|
||||
if (res != SQLITE_OK) {
|
||||
return {context_, res};
|
||||
}
|
||||
@ -87,19 +87,23 @@ auto db_delete::go() const -> db_result<context> {
|
||||
}
|
||||
|
||||
auto db_delete::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
|
||||
if (not context_->where.has_value()) {
|
||||
context_->where = context::w_t{0U, context_};
|
||||
if (not context_->where_data) {
|
||||
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
|
||||
context::w_t{0U, context_},
|
||||
});
|
||||
}
|
||||
|
||||
return context_->where->group(std::move(func));
|
||||
return context_->where_data->base.group(std::move(func));
|
||||
}
|
||||
|
||||
auto db_delete::where(std::string column_name) const -> context::w_t::cn_t {
|
||||
if (not context_->where.has_value()) {
|
||||
context_->where = context::w_t{0U, context_};
|
||||
if (not context_->where_data) {
|
||||
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
|
||||
context::w_t{0U, context_},
|
||||
});
|
||||
}
|
||||
|
||||
return context_->where->where(column_name);
|
||||
return context_->where_data->base.where(column_name);
|
||||
}
|
||||
} // namespace repertory::utils::db::sqlite
|
||||
|
||||
|
@ -24,16 +24,6 @@
|
||||
#if defined(PROJECT_ENABLE_SQLITE)
|
||||
|
||||
namespace repertory::utils::db::sqlite {
|
||||
void db_select::context::clear() {
|
||||
columns.clear();
|
||||
count_columns.clear();
|
||||
limit.reset();
|
||||
offset.reset();
|
||||
order_by.reset();
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
|
||||
auto db_select::context::db_select_op_t::dump() const -> std::string {
|
||||
return db_select{ctx}.dump();
|
||||
}
|
||||
@ -72,8 +62,8 @@ auto db_select::column(std::string column_name) -> db_select & {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_select::count(std::string column_name,
|
||||
std::string as_column_name) -> db_select & {
|
||||
auto db_select::count(std::string column_name, std::string as_column_name)
|
||||
-> db_select & {
|
||||
context_->count_columns[column_name] = as_column_name;
|
||||
return *this;
|
||||
}
|
||||
@ -108,9 +98,9 @@ auto db_select::dump() const -> std::string {
|
||||
}
|
||||
query << " FROM \"" << context_->table_name << "\"";
|
||||
|
||||
if (context_->where.has_value()) {
|
||||
if (context_->where_data) {
|
||||
std::int32_t idx{};
|
||||
query << " WHERE " << context_->where->dump(idx);
|
||||
query << " WHERE " << context_->where_data->base.dump(idx);
|
||||
}
|
||||
|
||||
if (not context_->group_by.empty()) {
|
||||
@ -156,8 +146,13 @@ auto db_select::go() const -> db_result<context> {
|
||||
return {context_, res};
|
||||
}
|
||||
|
||||
if (not context_->where_data) {
|
||||
return {context_, res};
|
||||
}
|
||||
|
||||
for (std::int32_t idx = 0;
|
||||
idx < static_cast<std::int32_t>(context_->where_values.size()); idx++) {
|
||||
idx < static_cast<std::int32_t>(context_->where_data->values.size());
|
||||
idx++) {
|
||||
res = std::visit(
|
||||
overloaded{
|
||||
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||
@ -168,7 +163,7 @@ auto db_select::go() const -> db_result<context> {
|
||||
data.c_str(), -1, nullptr);
|
||||
},
|
||||
},
|
||||
context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||
context_->where_data->values.at(static_cast<std::size_t>(idx)));
|
||||
if (res != SQLITE_OK) {
|
||||
return {context_, res};
|
||||
}
|
||||
@ -178,11 +173,13 @@ auto db_select::go() const -> db_result<context> {
|
||||
}
|
||||
|
||||
auto db_select::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
|
||||
if (not context_->where.has_value()) {
|
||||
context_->where = context::w_t{0U, context_};
|
||||
if (not context_->where_data) {
|
||||
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
|
||||
context::w_t{0U, context_},
|
||||
});
|
||||
}
|
||||
|
||||
return context_->where->group(std::move(func));
|
||||
return context_->where_data->base.group(std::move(func));
|
||||
}
|
||||
|
||||
auto db_select::group_by(std::string column_name) -> db_select & {
|
||||
@ -200,18 +197,20 @@ auto db_select::offset(std::int32_t value) -> db_select & {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_select::order_by(std::string column_name,
|
||||
bool ascending) -> db_select & {
|
||||
auto db_select::order_by(std::string column_name, bool ascending)
|
||||
-> db_select & {
|
||||
context_->order_by = {column_name, ascending};
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_select::where(std::string column_name) const -> context::w_t::cn_t {
|
||||
if (not context_->where.has_value()) {
|
||||
context_->where = context::w_t{0U, context_};
|
||||
if (not context_->where_data) {
|
||||
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
|
||||
context::w_t{0U, context_},
|
||||
});
|
||||
}
|
||||
|
||||
return context_->where->where(column_name);
|
||||
return context_->where_data->base.where(column_name);
|
||||
}
|
||||
} // namespace repertory::utils::db::sqlite
|
||||
|
||||
|
@ -24,14 +24,6 @@
|
||||
#if defined(PROJECT_ENABLE_SQLITE)
|
||||
|
||||
namespace repertory::utils::db::sqlite {
|
||||
void db_update::context::clear() {
|
||||
column_values.clear();
|
||||
limit.reset();
|
||||
order_by.reset();
|
||||
where.reset();
|
||||
where_values.clear();
|
||||
}
|
||||
|
||||
auto db_update::context::db_update_op_t::dump() const -> std::string {
|
||||
return db_update{ctx}.dump();
|
||||
}
|
||||
@ -53,8 +45,8 @@ auto db_update::context::db_update_op_t::order_by(std::string column_name,
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_update::column_value(std::string column_name,
|
||||
db_types_t value) -> db_update & {
|
||||
auto db_update::column_value(std::string column_name, db_types_t value)
|
||||
-> db_update & {
|
||||
context_->column_values[column_name] = value;
|
||||
return *this;
|
||||
}
|
||||
@ -73,9 +65,9 @@ auto db_update::dump() const -> std::string {
|
||||
query << '"' << column->first << "\"=?" + std::to_string(idx + 1);
|
||||
}
|
||||
|
||||
if (context_->where.has_value()) {
|
||||
if (context_->where_data) {
|
||||
auto idx{static_cast<std::int32_t>(context_->column_values.size())};
|
||||
query << " WHERE " << context_->where->dump(idx);
|
||||
query << " WHERE " << context_->where_data->base.dump(idx);
|
||||
}
|
||||
|
||||
if (context_->order_by.has_value()) {
|
||||
@ -124,29 +116,34 @@ auto db_update::go() const -> db_result<context> {
|
||||
}
|
||||
}
|
||||
|
||||
if (not context_->where_data) {
|
||||
return {context_, res};
|
||||
}
|
||||
|
||||
for (std::int32_t idx = 0;
|
||||
idx < static_cast<std::int32_t>(context_->where_values.size()); idx++) {
|
||||
res = std::visit(overloaded{
|
||||
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||
return sqlite3_bind_int64(
|
||||
context_->stmt.get(),
|
||||
idx +
|
||||
static_cast<std::int32_t>(
|
||||
context_->column_values.size()) +
|
||||
1,
|
||||
data);
|
||||
},
|
||||
[this, &idx](const std::string &data) -> std::int32_t {
|
||||
return sqlite3_bind_text(
|
||||
context_->stmt.get(),
|
||||
idx +
|
||||
static_cast<std::int32_t>(
|
||||
context_->column_values.size()) +
|
||||
1,
|
||||
data.c_str(), -1, nullptr);
|
||||
},
|
||||
},
|
||||
context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||
idx < static_cast<std::int32_t>(context_->where_data->values.size());
|
||||
idx++) {
|
||||
res = std::visit(
|
||||
overloaded{
|
||||
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||
return sqlite3_bind_int64(
|
||||
context_->stmt.get(),
|
||||
idx +
|
||||
static_cast<std::int32_t>(
|
||||
context_->column_values.size()) +
|
||||
1,
|
||||
data);
|
||||
},
|
||||
[this, &idx](const std::string &data) -> std::int32_t {
|
||||
return sqlite3_bind_text(context_->stmt.get(),
|
||||
idx +
|
||||
static_cast<std::int32_t>(
|
||||
context_->column_values.size()) +
|
||||
1,
|
||||
data.c_str(), -1, nullptr);
|
||||
},
|
||||
},
|
||||
context_->where_data->values.at(static_cast<std::size_t>(idx)));
|
||||
if (res != SQLITE_OK) {
|
||||
return {context_, res};
|
||||
}
|
||||
@ -156,11 +153,13 @@ auto db_update::go() const -> db_result<context> {
|
||||
}
|
||||
|
||||
auto db_update::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
|
||||
if (not context_->where.has_value()) {
|
||||
context_->where = context::w_t{0U, context_};
|
||||
if (not context_->where_data) {
|
||||
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
|
||||
context::w_t{0U, context_},
|
||||
});
|
||||
}
|
||||
|
||||
return context_->where->group(std::move(func));
|
||||
return context_->where_data->base.group(std::move(func));
|
||||
}
|
||||
|
||||
auto db_update::limit(std::int32_t value) -> db_update & {
|
||||
@ -168,18 +167,20 @@ auto db_update::limit(std::int32_t value) -> db_update & {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_update::order_by(std::string column_name,
|
||||
bool ascending) -> db_update & {
|
||||
auto db_update::order_by(std::string column_name, bool ascending)
|
||||
-> db_update & {
|
||||
context_->order_by = {column_name, ascending};
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_update::where(std::string column_name) const -> context::w_t::cn_t {
|
||||
if (not context_->where.has_value()) {
|
||||
context_->where = context::w_t{0U, context_};
|
||||
if (not context_->where_data) {
|
||||
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
|
||||
context::w_t{0U, context_},
|
||||
});
|
||||
}
|
||||
|
||||
return context_->where->where(column_name);
|
||||
return context_->where_data->base.where(column_name);
|
||||
}
|
||||
} // namespace repertory::utils::db::sqlite
|
||||
|
||||
|
@ -25,6 +25,27 @@ namespace repertory::utils::error {
|
||||
std::atomic<const i_exception_handler *> exception_handler{
|
||||
&default_exception_handler};
|
||||
|
||||
auto create_error_message(std::string_view function_name,
|
||||
std::vector<std::string_view> items) -> std::string {
|
||||
std::stringstream stream{};
|
||||
stream << function_name;
|
||||
for (auto &&item : items) {
|
||||
stream << '|' << item;
|
||||
}
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
void handle_error(std::string_view function_name, std::string_view msg) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_error(function_name, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_error(function_name, msg);
|
||||
}
|
||||
|
||||
void handle_exception(std::string_view function_name) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
|
@ -33,7 +33,7 @@ namespace {
|
||||
file_size = 0U;
|
||||
|
||||
#if defined(_WIN32)
|
||||
struct _stat64 st {};
|
||||
struct _stat64 st{};
|
||||
auto res = _stat64(std::string{path}.c_str(), &st);
|
||||
if (res != 0) {
|
||||
return false;
|
||||
@ -52,10 +52,10 @@ namespace {
|
||||
auto abs_path = repertory::utils::path::absolute(path);
|
||||
|
||||
#if defined(_WIN32)
|
||||
return (::PathFileExistsA(abs_path.c_str()) &&
|
||||
not ::PathIsDirectoryA(abs_path.c_str()));
|
||||
return ((::PathFileExistsA(abs_path.c_str()) != 0) &&
|
||||
(::PathIsDirectoryA(abs_path.c_str()) == 0));
|
||||
#else // !defined(_WIN32)
|
||||
struct stat64 st {};
|
||||
struct stat64 st{};
|
||||
return (stat64(abs_path.c_str(), &st) == 0 && not S_ISDIR(st.st_mode));
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
@ -119,11 +119,15 @@ void file::open() {
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
file_ = file_t(_fsopen(path_.c_str(), read_only_ ? "rb" : "rb+", _SH_DENYNO),
|
||||
file_deleter());
|
||||
file_ = file_t{
|
||||
_fsopen(path_.c_str(), read_only_ ? "rb" : "rb+", _SH_DENYNO),
|
||||
file_deleter(),
|
||||
};
|
||||
#else // !defined(_WIN32)
|
||||
file_ =
|
||||
file_t(fopen(path_.c_str(), read_only_ ? "rb" : "rb+"), file_deleter());
|
||||
file_ = file_t{
|
||||
fopen(path_.c_str(), read_only_ ? "rb" : "rb+"),
|
||||
file_deleter(),
|
||||
};
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
@ -150,8 +154,8 @@ auto file::open_file(std::string_view path, bool read_only) -> fs_file_t {
|
||||
return new_file;
|
||||
}
|
||||
|
||||
auto file::open_or_create_file(std::string_view path,
|
||||
bool read_only) -> fs_file_t {
|
||||
auto file::open_or_create_file(std::string_view path, bool read_only)
|
||||
-> fs_file_t {
|
||||
auto abs_path = utils::path::absolute(path);
|
||||
if (not is_file(abs_path)) {
|
||||
#if defined(_WIN32)
|
||||
@ -196,7 +200,7 @@ auto file::copy_to(std::string_view new_path, bool overwrite) const -> bool {
|
||||
|
||||
#if defined(_WIN32)
|
||||
return ::CopyFileA(path_.c_str(), to_path.c_str(),
|
||||
overwrite ? TRUE : FALSE);
|
||||
overwrite ? TRUE : FALSE) != 0;
|
||||
#else // !defined(_WIN32)
|
||||
return std::filesystem::copy_file(
|
||||
path_, to_path,
|
||||
@ -264,8 +268,8 @@ auto file::move_to(std::string_view path) -> bool {
|
||||
|
||||
auto success{false};
|
||||
#if defined(_WIN32)
|
||||
success = !!::MoveFileExA(path_.c_str(), abs_path.c_str(),
|
||||
MOVEFILE_REPLACE_EXISTING);
|
||||
success = ::MoveFileExA(path_.c_str(), abs_path.c_str(),
|
||||
MOVEFILE_REPLACE_EXISTING) != 0;
|
||||
#else // !// defined(_WIN32)
|
||||
std::error_code ec{};
|
||||
std::filesystem::rename(path_, abs_path, ec);
|
||||
@ -415,7 +419,7 @@ auto file::remove() -> bool {
|
||||
|
||||
return utils::retry_action([this]() -> bool {
|
||||
#if defined(_WIN32)
|
||||
return ::DeleteFileA(path_.c_str());
|
||||
return ::DeleteFileA(path_.c_str()) != 0;
|
||||
#else // !defined(_WIN32)
|
||||
std::error_code ec{};
|
||||
return std::filesystem::remove(path_, ec);
|
||||
|
@ -26,6 +26,39 @@
|
||||
#include "utils/string.hpp"
|
||||
|
||||
namespace repertory::utils {
|
||||
void create_console() {
|
||||
if (AllocConsole() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
FILE *dummy{nullptr};
|
||||
freopen_s(&dummy, "CONOUT$", "w", stdout);
|
||||
freopen_s(&dummy, "CONOUT$", "w", stderr);
|
||||
freopen_s(&dummy, "CONIN$", "r", stdin);
|
||||
std::cout.clear();
|
||||
std::clog.clear();
|
||||
std::cerr.clear();
|
||||
std::cin.clear();
|
||||
|
||||
auto *out_w = CreateFileW(L"CONOUT$", GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
auto *in_w = CreateFileW(L"CONIN$", GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
SetStdHandle(STD_OUTPUT_HANDLE, out_w);
|
||||
SetStdHandle(STD_ERROR_HANDLE, out_w);
|
||||
SetStdHandle(STD_INPUT_HANDLE, in_w);
|
||||
std::wcout.clear();
|
||||
std::wclog.clear();
|
||||
std::wcerr.clear();
|
||||
std::wcin.clear();
|
||||
}
|
||||
|
||||
void free_console() {
|
||||
FreeConsole();
|
||||
}
|
||||
|
||||
auto get_last_error_code() -> DWORD { return ::GetLastError(); }
|
||||
|
||||
auto get_local_app_data_directory() -> const std::string & {
|
||||
|
Reference in New Issue
Block a user