added date_type_t, time_type_t and timestamp, ensure allocated postgres resources are released, split repository into basic_repository and repository.

This commit is contained in:
2026-01-06 15:43:20 +01:00
parent f07a360da2
commit 0c6b5a0a93
60 changed files with 1132 additions and 1225 deletions
+12 -5
View File
@@ -5,12 +5,17 @@
namespace matador::backends::postgres {
postgres_statement::postgres_statement(PGconn *db, std::string name, const sql::query_context &query)
postgres_statement::postgres_statement(PGconn *db, PGresult *res, std::string name, const sql::query_context &query)
: statement_impl(query, 0)
, db_(db)
, res_(res)
, name_(std::move(name))
{}
postgres_statement::~postgres_statement() {
PQclear(res_);
}
utils::result<size_t, utils::error> postgres_statement::execute(const sql::parameter_binder& bindings) {
const auto* postgres_bindings = dynamic_cast<const postgres_parameter_binder*>(&bindings);
if (!postgres_bindings) {
@@ -28,12 +33,14 @@ utils::result<size_t, utils::error> postgres_statement::execute(const sql::param
return utils::failure(make_error(sql::error_code::EXECUTE_FAILED, res, db_, "Failed to execute statement", query_.sql));
}
const auto *tuples = PQcmdTuples(res);
if (strlen(tuples) == 0) {
return utils::ok(static_cast<size_t>(0));
size_t value{0};
if (const auto *tuples = PQcmdTuples(res); strlen(tuples) != 0) {
value = std::stoul(tuples);
}
return utils::ok(static_cast<size_t>(std::stoul(tuples)));
PQclear(res);
return utils::ok(value);
}
utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> postgres_statement::fetch(const sql::parameter_binder& bindings) {