fix
This commit is contained in:
parent
37d393c1f9
commit
8cc6868480
@ -240,7 +240,7 @@ struct db_next_t final {
|
|||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
|
||||||
return ctx->where->dump(idx);
|
return ctx->where->dump(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ struct db_next_limit_t final {
|
|||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
|
||||||
return ctx->where->dump(idx);
|
return ctx->where->dump(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ struct db_where_next_t final {
|
|||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
|
||||||
return ctx->where->dump(idx);
|
return ctx->where->dump(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +338,7 @@ struct db_where_next_limit_t final {
|
|||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
|
||||||
return ctx->where->dump(idx);
|
return ctx->where->dump(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,6 +377,8 @@ struct db_comp_next_t final {
|
|||||||
value,
|
value,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ctx->where_values.push_back(&value);
|
||||||
|
|
||||||
return wn_t{
|
return wn_t{
|
||||||
ctx,
|
ctx,
|
||||||
owner,
|
owner,
|
||||||
@ -413,6 +415,8 @@ struct db_comp_next_limit_t final {
|
|||||||
value,
|
value,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ctx->where_values.push_back(&value);
|
||||||
|
|
||||||
return wn_t{
|
return wn_t{
|
||||||
ctx,
|
ctx,
|
||||||
owner,
|
owner,
|
||||||
@ -447,7 +451,7 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
|
|||||||
|
|
||||||
std::vector<action_t> actions{};
|
std::vector<action_t> actions{};
|
||||||
|
|
||||||
[[nodiscard]] static auto dump(std::int64_t &idx,
|
[[nodiscard]] static auto dump(std::int32_t &idx,
|
||||||
auto &&data) -> std::string {
|
auto &&data) -> std::string {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
|
|
||||||
@ -473,7 +477,7 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
|
|||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
|
||||||
return dump(idx, *this);
|
return dump(idx, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,7 +514,7 @@ template <typename ctx_t, typename op_t> struct db_where_with_limit_t final {
|
|||||||
|
|
||||||
std::vector<action_t> actions{};
|
std::vector<action_t> actions{};
|
||||||
|
|
||||||
[[nodiscard]] static auto dump(std::int64_t &idx,
|
[[nodiscard]] static auto dump(std::int32_t &idx,
|
||||||
auto &&data) -> std::string {
|
auto &&data) -> std::string {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
|
|
||||||
@ -536,7 +540,7 @@ template <typename ctx_t, typename op_t> struct db_where_with_limit_t final {
|
|||||||
|
|
||||||
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
|
||||||
|
|
||||||
[[nodiscard]] auto dump(std::int64_t &idx) const -> std::string {
|
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
|
||||||
return dump(idx, *this);
|
return dump(idx, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,8 @@ public:
|
|||||||
std::string table_name;
|
std::string table_name;
|
||||||
|
|
||||||
std::optional<db_where_t<context, db_delete>> where;
|
std::optional<db_where_t<context, db_delete>> where;
|
||||||
|
std::vector<db_types_t *> where_values;
|
||||||
|
|
||||||
db3_stmt_t stmt{nullptr};
|
db3_stmt_t stmt{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,6 +41,8 @@ public:
|
|||||||
std::optional<std::int32_t> limit;
|
std::optional<std::int32_t> limit;
|
||||||
std::optional<std::pair<std::string, bool>> order_by;
|
std::optional<std::pair<std::string, bool>> order_by;
|
||||||
std::optional<db_where_with_limit_t<context, db_select>> where;
|
std::optional<db_where_with_limit_t<context, db_select>> where;
|
||||||
|
std::vector<db_types_t *> where_values;
|
||||||
|
|
||||||
db3_stmt_t stmt{nullptr};
|
db3_stmt_t stmt{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -34,10 +34,12 @@ public:
|
|||||||
sqlite3 &db3;
|
sqlite3 &db3;
|
||||||
std::string table_name;
|
std::string table_name;
|
||||||
|
|
||||||
std::optional<db_where_with_limit_t<context, db_update>> where;
|
std::map<std::string, db_types_t> column_values{};
|
||||||
std::map<std::string, db_types_t> values{};
|
|
||||||
std::optional<std::int32_t> limit;
|
std::optional<std::int32_t> limit;
|
||||||
std::optional<std::pair<std::string, bool>> order_by;
|
std::optional<std::pair<std::string, bool>> order_by;
|
||||||
|
std::optional<db_where_with_limit_t<context, db_update>> where;
|
||||||
|
std::vector<db_types_t *> where_values;
|
||||||
|
|
||||||
db3_stmt_t stmt{nullptr};
|
db3_stmt_t stmt{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,27 +53,26 @@ auto db_delete::go() const -> db_result<context> {
|
|||||||
}
|
}
|
||||||
context_->stmt.reset(stmt_ptr);
|
context_->stmt.reset(stmt_ptr);
|
||||||
|
|
||||||
// for (std::int32_t idx = 0;
|
for (std::int32_t idx = 0;
|
||||||
// idx < static_cast<std::int32_t>(context_->ands.size()); idx++) {
|
idx < static_cast<std::int32_t>(context_->where_values.size()); idx++) {
|
||||||
// res = std::visit(
|
res = std::visit(
|
||||||
// overloaded{
|
overloaded{
|
||||||
// [this, &idx](std::int64_t data) -> std::int32_t {
|
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||||
// return sqlite3_bind_int64(context_->stmt.get(), idx + 1, data);
|
return sqlite3_bind_int64(context_->stmt.get(), idx + 1, data);
|
||||||
// },
|
},
|
||||||
// [this, &idx](const std::string &data) -> std::int32_t {
|
[this, &idx](const std::string &data) -> std::int32_t {
|
||||||
// return sqlite3_bind_text(context_->stmt.get(), idx + 1,
|
return sqlite3_bind_text(context_->stmt.get(), idx + 1,
|
||||||
// data.c_str(), -1, nullptr);
|
data.c_str(), -1, nullptr);
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// context_->ands.at(static_cast<std::size_t>(idx)).value);
|
*context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||||
// if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
// utils::error::raise_error(function_name,
|
utils::error::raise_error(function_name,
|
||||||
// "failed to bind|" + std::to_string(res) + '|'
|
"failed to bind|" + std::to_string(res) + '|' +
|
||||||
// +
|
sqlite3_errstr(res) + '|' + query_str);
|
||||||
// sqlite3_errstr(res) + '|' + query_str);
|
return {context_, res};
|
||||||
// return {context_, res};
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
return {context_, res};
|
return {context_, res};
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ auto db_select::dump() const -> std::string {
|
|||||||
query << " FROM \"" << context_->table_name << "\"";
|
query << " FROM \"" << context_->table_name << "\"";
|
||||||
|
|
||||||
if (context_->where.has_value()) {
|
if (context_->where.has_value()) {
|
||||||
std::int64_t idx{};
|
std::int32_t idx{};
|
||||||
query << " WHERE " << context_->where->dump(idx);
|
query << " WHERE " << context_->where->dump(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,27 +99,26 @@ auto db_select::go() const -> db_result<context> {
|
|||||||
}
|
}
|
||||||
context_->stmt.reset(stmt_ptr);
|
context_->stmt.reset(stmt_ptr);
|
||||||
|
|
||||||
// for (std::int32_t idx = 0;
|
for (std::int32_t idx = 0;
|
||||||
// idx < static_cast<std::int32_t>(context_->ands.size()); idx++) {
|
idx < static_cast<std::int32_t>(context_->where_values.size()); idx++) {
|
||||||
// res = std::visit(
|
res = std::visit(
|
||||||
// overloaded{
|
overloaded{
|
||||||
// [this, &idx](std::int64_t data) -> std::int32_t {
|
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||||
// return sqlite3_bind_int64(context_->stmt.get(), idx + 1, data);
|
return sqlite3_bind_int64(context_->stmt.get(), idx + 1, data);
|
||||||
// },
|
},
|
||||||
// [this, &idx](const std::string &data) -> std::int32_t {
|
[this, &idx](const std::string &data) -> std::int32_t {
|
||||||
// return sqlite3_bind_text(context_->stmt.get(), idx + 1,
|
return sqlite3_bind_text(context_->stmt.get(), idx + 1,
|
||||||
// data.c_str(), -1, nullptr);
|
data.c_str(), -1, nullptr);
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// context_->ands.at(static_cast<std::size_t>(idx)).value);
|
*context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||||
// if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
// utils::error::raise_error(function_name,
|
utils::error::raise_error(function_name,
|
||||||
// "failed to bind|" + std::to_string(res) + '|'
|
"failed to bind|" + std::to_string(res) + '|' +
|
||||||
// +
|
sqlite3_errstr(res) + '|' + query_str);
|
||||||
// sqlite3_errstr(res) + '|' + query_str);
|
return {context_, res};
|
||||||
// return {context_, res};
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
return {context_, res};
|
return {context_, res};
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
namespace repertory::db {
|
namespace repertory::db {
|
||||||
auto db_update::column_value(std::string column_name,
|
auto db_update::column_value(std::string column_name,
|
||||||
db_types_t value) -> db_update & {
|
db_types_t value) -> db_update & {
|
||||||
context_->values[column_name] = value;
|
context_->column_values[column_name] = value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,17 +33,17 @@ auto db_update::dump() const -> std::string {
|
|||||||
query << "UPDATE \"" << context_->table_name << "\" SET ";
|
query << "UPDATE \"" << context_->table_name << "\" SET ";
|
||||||
|
|
||||||
for (std::int32_t idx = 0;
|
for (std::int32_t idx = 0;
|
||||||
idx < static_cast<std::int32_t>(context_->values.size()); idx++) {
|
idx < static_cast<std::int32_t>(context_->column_values.size()); idx++) {
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
query << ", ";
|
query << ", ";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto column = std::next(context_->values.begin(), idx);
|
auto column = std::next(context_->column_values.begin(), idx);
|
||||||
query << '"' << column->first << "\"=?" + std::to_string(idx + 1);
|
query << '"' << column->first << "\"=?" + std::to_string(idx + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context_->where.has_value()) {
|
if (context_->where.has_value()) {
|
||||||
auto idx{static_cast<std::int64_t>(context_->values.size())};
|
auto idx{static_cast<std::int32_t>(context_->column_values.size())};
|
||||||
query << " WHERE " << context_->where->dump(idx);
|
query << " WHERE " << context_->where->dump(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ auto db_update::go() const -> db_result<context> {
|
|||||||
context_->stmt.reset(stmt_ptr);
|
context_->stmt.reset(stmt_ptr);
|
||||||
|
|
||||||
for (std::int32_t idx = 0;
|
for (std::int32_t idx = 0;
|
||||||
idx < static_cast<std::int32_t>(context_->values.size()); idx++) {
|
idx < static_cast<std::int32_t>(context_->column_values.size()); idx++) {
|
||||||
res = std::visit(
|
res = std::visit(
|
||||||
overloaded{
|
overloaded{
|
||||||
[this, &idx](std::int64_t data) -> std::int32_t {
|
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||||
@ -90,7 +90,7 @@ auto db_update::go() const -> db_result<context> {
|
|||||||
data.c_str(), -1, nullptr);
|
data.c_str(), -1, nullptr);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
std::next(context_->values.begin(), idx)->second);
|
std::next(context_->column_values.begin(), idx)->second);
|
||||||
if (res != SQLITE_OK) {
|
if (res != SQLITE_OK) {
|
||||||
utils::error::raise_error(function_name, "failed to bind|" +
|
utils::error::raise_error(function_name, "failed to bind|" +
|
||||||
std::to_string(res) + '|' +
|
std::to_string(res) + '|' +
|
||||||
@ -99,32 +99,36 @@ auto db_update::go() const -> db_result<context> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (std::int32_t idx = 0;
|
for (std::int32_t idx = 0;
|
||||||
// idx < static_cast<std::int32_t>(context_->ands.size()); idx++) {
|
idx < static_cast<std::int32_t>(context_->where_values.size()); idx++) {
|
||||||
// res = std::visit(
|
res = std::visit(overloaded{
|
||||||
// overloaded{
|
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||||
// [this, &idx](std::int64_t data) -> std::int32_t {
|
return sqlite3_bind_int64(
|
||||||
// return sqlite3_bind_int64(
|
context_->stmt.get(),
|
||||||
// context_->stmt.get(),
|
idx +
|
||||||
// idx + static_cast<std::int32_t>(context_->values.size()) +
|
static_cast<std::int32_t>(
|
||||||
// 1, data);
|
context_->column_values.size()) +
|
||||||
// },
|
1,
|
||||||
// [this, &idx](const std::string &data) -> std::int32_t {
|
data);
|
||||||
// return sqlite3_bind_text(
|
},
|
||||||
// context_->stmt.get(),
|
[this, &idx](const std::string &data) -> std::int32_t {
|
||||||
// idx + static_cast<std::int32_t>(context_->values.size()) +
|
return sqlite3_bind_text(
|
||||||
// 1, data.c_str(), -1, nullptr);
|
context_->stmt.get(),
|
||||||
// },
|
idx +
|
||||||
// },
|
static_cast<std::int32_t>(
|
||||||
// context_->ands.at(static_cast<std::size_t>(idx)).value);
|
context_->column_values.size()) +
|
||||||
// if (res != SQLITE_OK) {
|
1,
|
||||||
// utils::error::raise_error(function_name,
|
data.c_str(), -1, nullptr);
|
||||||
// "failed to bind|" + std::to_string(res) + '|'
|
},
|
||||||
// +
|
},
|
||||||
// sqlite3_errstr(res) + '|' + query_str);
|
*context_->where_values.at(static_cast<std::size_t>(idx)));
|
||||||
// return {context_, res};
|
if (res != SQLITE_OK) {
|
||||||
// }
|
utils::error::raise_error(function_name,
|
||||||
// }
|
"failed to bind|" + std::to_string(res) + '|' +
|
||||||
|
sqlite3_errstr(res) + '|' + query_str);
|
||||||
|
return {context_, res};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {context_, res};
|
return {context_, res};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user