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