implemented prepared statement for postgres and sqlite

This commit is contained in:
2023-12-09 11:08:03 +01:00
parent 8ba70cc79e
commit da423ea8bb
59 changed files with 1769 additions and 314 deletions
@@ -0,0 +1,40 @@
#include "postgres_statement.hpp"
#include "postgres_error.hpp"
#include "postgres_result_reader.hpp"
namespace matador::backends::postgres {
postgres_statement::postgres_statement(PGconn *db, PGresult *result, const std::string &name, const sql::query_context &query)
: statement_impl(query)
, db_(db)
, result_(result)
, name_(name)
, binder_(query_.bind_vars.size())
{}
size_t postgres_statement::execute()
{
PGresult *res = PQexecPrepared(db_, name_.c_str(), static_cast<int>(binder_.params().size()), binder_.params().data(), nullptr, nullptr, 0);
throw_postgres_error(res, db_, "postgres", query_.sql);
return std::stoul(PQcmdTuples(res));
}
std::unique_ptr<sql::query_result_impl> postgres_statement::fetch()
{
PGresult *res = PQexecPrepared(db_, name_.c_str(), static_cast<int>(binder_.params().size()), binder_.params().data(), nullptr, nullptr, 0);
throw_postgres_error(res, db_, "postgres", query_.sql);
return std::move(std::make_unique<sql::query_result_impl>(std::make_unique<postgres_result_reader>(res), std::move(query_.prototype)));
}
void postgres_statement::reset() {}
sql::parameter_binder& postgres_statement::binder()
{
return binder_;
}
}