summaryrefslogtreecommitdiff
path: root/libpqpp/pq-column.h
blob: 6bf2669186ba96d9f2fb5736a645475a31a51153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef PG_COLUMN_H
#define PG_COLUMN_H

#include "pq-helpers.h"
#include <column.h>
#include <cstring>
#include <libpq-fe.h>

namespace PQ {
	class SelectBase;

	class Column : public DB::Column {
	public:
		Column(const SelectBase *, unsigned int field);

		[[nodiscard]] bool isNull() const override;
		void apply(DB::HandleField &) const override;

	protected:
		template<typename T>
		inline T
		valueAs() const
		{
			T v {};
			std::memcpy(&v, value(), sizeof(T));
			return v;
		}

		const char * value() const;
		std::size_t length() const;

		const SelectBase * sc;
		const Oid oid;

		// Buffer for PQunescapeBytea
		using BufPtr = std::unique_ptr<unsigned char, pq_deleter<PQfreemem>>;
		mutable BufPtr buf;
	};
}

#endif