summaryrefslogtreecommitdiff
path: root/libodbcpp/odbc-column.h
blob: e02649c24f4624cf3cb7e50645c1dd3c9c3f1d35 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#ifndef ODBC_COLUMN_H
#define ODBC_COLUMN_H

#include "odbc-bind.h"
#include "odbc-param.h"
#include "odbc-param_fwd.h"
#include <algorithm>
#include <column.h>
#include <glibmm/ustring.h>
#include <sql.h>
#include <sqlext.h>
#include <vector>

namespace ODBC {
	class SelectCommand;
	class Column : public virtual Bind, public virtual DB::Column {
	public:
		Column(SelectCommand *, const Glib::ustring & s, unsigned int i);
		virtual ~Column() override = default;
		void bind();
		virtual void * rwDataAddress() = 0;
		virtual bool resize();

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

		const SelectCommand * selectCmd;

	protected:
		virtual const Param * meAsAParam() const = 0;
	};
	class CharArrayColumn : public Column, public Param {
	public:
		using CharArray = std::vector<char>;
		CharArrayColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i, SQLULEN sizeHint) :
			DB::Column(n, i), Column(sc, n, i)
		{
			data.resize(std::max<SQLULEN>(sizeHint, 64) + 1);
		}
		SQLSMALLINT
		ctype() const override
		{
			return SQL_C_CHAR;
		}
		SQLSMALLINT
		stype() const override
		{
			return SQL_CHAR;
		}
		SQLULEN
		size() const override
		{
			return data.size();
		}
		SQLSMALLINT
		dp() const override
		{
			return 0;
		}
		const void *
		dataAddress() const override
		{
			return &data.front();
		}
		void *
		rwDataAddress() override
		{
			return &data.front();
		}
		void operator=(const Glib::ustring & d);
		bool resize() override;
		void apply(DB::HandleField &) const override;

	protected:
		virtual const Param *
		meAsAParam() const override
		{
			return this;
		}
		CharArray data;
	};
	class SignedIntegerColumn : public Column, public SignedIntegerParam {
	public:
		SignedIntegerColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i) :
			DB::Column(n, i), Column(sc, n, i)
		{
		}
		SQLSMALLINT
		ctype() const override
		{
			return SignedIntegerParam::ctype();
		}
		SQLULEN
		size() const override
		{
			return SignedIntegerParam::size();
		}
		void *
		rwDataAddress() override
		{
			return &data;
		}
		const Param *
		meAsAParam() const override
		{
			return this;
		}
		void apply(DB::HandleField &) const override;
	};
#ifdef COMPLETENESS
	class UnsignedIntegerColumn : public Column, public UnsignedIntegerParam {
	public:
		UnsignedIntegerColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i) : Column(sc, n, i) { }
		const Param *
		meAsAParam() const override
		{
			return this;
		}
	};
#endif
	class FloatingPointColumn : public Column, public FloatingPointParam {
	public:
		FloatingPointColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i) :
			DB::Column(n, i), Column(sc, n, i)
		{
		}
		SQLSMALLINT
		ctype() const override
		{
			return FloatingPointParam::ctype();
		}
		SQLULEN
		size() const override
		{
			return FloatingPointParam::size();
		}
		void *
		rwDataAddress() override
		{
			return &data;
		}
		const Param *
		meAsAParam() const override
		{
			return this;
		}
		void apply(DB::HandleField &) const override;
	};
	class IntervalColumn : public Column, public IntervalParam {
	public:
		IntervalColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i) : DB::Column(n, i), Column(sc, n, i)
		{
		}
		SQLSMALLINT
		ctype() const override
		{
			return IntervalParam::ctype();
		}
		SQLULEN
		size() const override
		{
			return IntervalParam::size();
		}
		void *
		rwDataAddress() override
		{
			return &data;
		}
		const Param *
		meAsAParam() const override
		{
			return this;
		}
		void apply(DB::HandleField &) const override;
	};
	class TimeStampColumn : public Column, public TimeStampParam {
	public:
		TimeStampColumn(SelectCommand * sc, const Glib::ustring & n, unsigned int i) :
			DB::Column(n, i), Column(sc, n, i)
		{
		}
		SQLSMALLINT
		ctype() const override
		{
			return TimeStampParam::ctype();
		}
		SQLULEN
		size() const override
		{
			return TimeStampParam::size();
		}
		void *
		rwDataAddress() override
		{
			return &data;
		}
		const Param *
		meAsAParam() const override
		{
			return this;
		}
		void apply(DB::HandleField &) const override;
	};
}

#endif