initial matador ng commit

This commit is contained in:
2025-02-02 20:37:12 +01:00
parent 19de5714f4
commit ded3daceb3
378 changed files with 14913 additions and 13431 deletions
+30 -9
View File
@@ -12,27 +12,48 @@ postgres_statement::postgres_statement(PGconn *db, PGresult *result, std::string
, binder_(query_.bind_vars.size())
{}
size_t postgres_statement::execute()
utils::result<size_t, utils::error> postgres_statement::execute()
{
PGresult *res = PQexecPrepared(db_, name_.c_str(), static_cast<int>(binder_.params().size()), binder_.params().data(), nullptr, nullptr, 0);
PGresult *res = PQexecPrepared(db_,
name_.c_str(),
static_cast<int>(binder_.params().values.size()),
binder_.params().values.data(),
binder_.params().lengths.data(),
binder_.params().formats.data(),
0);
throw_postgres_error(res, db_, "postgres", query_.sql);
if (is_result_error(res)) {
return utils::failure(make_error(sql::error_code::EXECUTE_FAILED, res, db_, "Failed to execute statement", query_.sql));
}
return std::stoul(PQcmdTuples(res));
const auto *tuples = PQcmdTuples(res);
if (strlen(tuples) == 0) {
return utils::ok(static_cast<size_t>(0));
}
return utils::ok(static_cast<size_t>(std::stoul(tuples)));
}
std::unique_ptr<sql::query_result_impl> postgres_statement::fetch()
utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> postgres_statement::fetch()
{
PGresult *res = PQexecPrepared(db_, name_.c_str(), static_cast<int>(binder_.params().size()), binder_.params().data(), nullptr, nullptr, 0);
PGresult *res = PQexecPrepared(db_,
name_.c_str(),
static_cast<int>(binder_.params().values.size()),
binder_.params().values.data(),
binder_.params().lengths.data(),
binder_.params().formats.data(),
0);
throw_postgres_error(res, db_, "postgres", query_.sql);
if (is_result_error(res)) {
return utils::failure(make_error(sql::error_code::FETCH_FAILED, res, db_, "Failed to fetch statement", query_.sql));
}
return std::move(std::make_unique<sql::query_result_impl>(std::make_unique<postgres_result_reader>(res), std::move(query_.prototype)));
return utils::ok(std::make_unique<sql::query_result_impl>(std::make_unique<postgres_result_reader>(res), query_.prototype));
}
void postgres_statement::reset() {}
sql::parameter_binder& postgres_statement::binder()
utils::attribute_writer& postgres_statement::binder()
{
return binder_;
}