added postgres backend

This commit is contained in:
2023-11-25 12:33:51 +01:00
parent c2a96f4cbd
commit 825e530a8d
20 changed files with 547 additions and 65 deletions
@@ -0,0 +1,120 @@
#include "postgres_result_reader.hpp"
#include "matador/sql/to_value.hpp"
namespace matador::backends::postgres {
postgres_result_reader::postgres_result_reader(PGresult *result)
: result_(result)
, row_count_(PQntuples(result_))
, column_count_(PQnfields(result_))
{}
postgres_result_reader::~postgres_result_reader()
{
if (result_) {
PQclear(result_);
}
}
size_t postgres_result_reader::column_count() const
{
return column_count_;
}
const char *postgres_result_reader::column(size_t index) const
{
return nullptr;
}
bool postgres_result_reader::fetch()
{
return ++row_index_ < row_count_;
}
void postgres_result_reader::read_value(const char *id, size_t index, char &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, short &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, int &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, long &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, long long int &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, unsigned char &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, unsigned short &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, unsigned int &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, unsigned long &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, unsigned long long int &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, bool &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, float &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, double &value)
{
sql::to_value(value, PQgetvalue(result_, static_cast<int>(row_index_), static_cast<int>(index)));
}
void postgres_result_reader::read_value(const char *id, size_t index, char *value, size_t s)
{
}
void postgres_result_reader::read_value(const char *id, size_t index, std::string &value)
{
}
void postgres_result_reader::read_value(const char *id, size_t index, std::string &value, size_t s)
{
}
void postgres_result_reader::read_value(const char *id, size_t index, sql::any_type &value, sql::data_type_t type,
size_t size)
{
}
}