summaryrefslogtreecommitdiff
path: root/libodbcpp/odbc-param.h
blob: 32d3f99e8fed9b139eac7e288ba024ebf830750f (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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#ifndef ODBC_PARAM_H
#define ODBC_PARAM_H

#include "odbc-param_fwd.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#ifndef __clang__
#	pragma GCC diagnostic ignored "-Wuseless-cast"
#endif
#include <glibmm/ustring.h>
#pragma GCC diagnostic pop
#include <boost/date_time/posix_time/posix_time.hpp>
#include <sql.h>
#include <sqlext.h>
#include <string>
#include <string_view>

namespace ODBC {
	class Command;
	class BooleanParam : public Param {
	public:
		BooleanParam() : Param() { }
		BooleanParam(Command * c, unsigned int i) : Param(c, i)
		{
			bindLen = static_cast<SQLLEN>(BooleanParam::size());
		}
		virtual SQLSMALLINT
		ctype() const override
		{
			return SQL_C_BIT;
		}
		virtual SQLSMALLINT
		stype() const override
		{
			return SQL_C_BIT;
		}
		virtual SQLULEN
		size() const override
		{
			return sizeof(SQLINTEGER);
		}
		virtual SQLSMALLINT
		dp() const override
		{
			return 0;
		}
		virtual const void *
		dataAddress() const override
		{
			return &data;
		}
		BooleanParam &
		operator=(const SQLINTEGER & d)
		{
			data = d;
			return *this;
		}

	protected:
		SQLINTEGER data;
	};
	class SignedIntegerParam : public Param {
	public:
		SignedIntegerParam() : Param() { }
		SignedIntegerParam(Command * c, unsigned int i) : Param(c, i)
		{
			bindLen = static_cast<SQLLEN>(SignedIntegerParam::size());
		}
		virtual SQLSMALLINT
		ctype() const override
		{
			return SQL_C_SBIGINT;
		}
		virtual SQLSMALLINT
		stype() const override
		{
			return SQL_C_SBIGINT;
		}
		virtual SQLULEN
		size() const override
		{
			return sizeof(data);
		}
		virtual SQLSMALLINT
		dp() const override
		{
			return 0;
		}
		virtual const void *
		dataAddress() const override
		{
			return &data;
		}
		SignedIntegerParam &
		operator=(const SQLBIGINT & d)
		{
			data = d;
			return *this;
		}

	protected:
		SQLBIGINT data;
	};
	class UnsignedIntegerParam : public Param {
	public:
		UnsignedIntegerParam() : Param() { }
		UnsignedIntegerParam(Command * c, unsigned int i) : Param(c, i)
		{
			bindLen = static_cast<SQLLEN>(UnsignedIntegerParam::size());
		}
		virtual SQLSMALLINT
		ctype() const override
		{
			return SQL_C_UBIGINT;
		}
		virtual SQLSMALLINT
		stype() const override
		{
			return SQL_C_UBIGINT;
		}
		virtual SQLULEN
		size() const override
		{
			return sizeof(data);
		}
		virtual SQLSMALLINT
		dp() const override
		{
			return 0;
		}
		virtual const void *
		dataAddress() const override
		{
			return &data;
		}
		UnsignedIntegerParam &
		operator=(const SQLUBIGINT & d)
		{
			data = d;
			return *this;
		}

	protected:
		SQLUBIGINT data;
	};
	class FloatingPointParam : public Param {
	public:
		FloatingPointParam() : Param() { }
		FloatingPointParam(Command * c, unsigned int i) : Param(c, i)
		{
			bindLen = static_cast<SQLLEN>(FloatingPointParam::size());
		}
		virtual SQLSMALLINT
		ctype() const override
		{
			return SQL_C_DOUBLE;
		}
		virtual SQLSMALLINT
		stype() const override
		{
			return SQL_C_DOUBLE;
		}
		virtual SQLULEN
		size() const override
		{
			return sizeof(SQLDOUBLE);
		}
		virtual SQLSMALLINT
		dp() const override
		{
			return 10;
		}
		virtual const void *
		dataAddress() const override
		{
			return &data;
		}
		FloatingPointParam &
		operator=(const double & d)
		{
			data = d;
			return *this;
		}
		FloatingPointParam &
		operator=(const float & f)
		{
			return operator=(static_cast<double>(f));
		}

	protected:
		SQLDOUBLE data;
	};
	class StdStringParam : public Param {
	public:
		StdStringParam() : Param() { }
		StdStringParam(Command * c, unsigned int i) : Param(c, i)
		{
			bindLen = static_cast<SQLLEN>(StdStringParam::size());
		}
		virtual SQLSMALLINT
		ctype() const override
		{
			return SQL_C_CHAR;
		}
		virtual SQLSMALLINT
		stype() const override
		{
			return SQL_CHAR;
		}
		virtual SQLULEN
		size() const override
		{
			return data.length();
		}
		virtual SQLSMALLINT
		dp() const override
		{
			return 0;
		}
		virtual const void *
		dataAddress() const override
		{
			return data.data();
		}
		StdStringParam & operator=(const std::string_view & d);
		StdStringParam & operator=(const Glib::ustring & d);

	protected:
		std::string data;
	};
	class IntervalParam : public Param {
	public:
		IntervalParam() : Param() { }
		IntervalParam(Command * c, unsigned int i) : Param(c, i)
		{
			bindLen = static_cast<SQLLEN>(IntervalParam::size());
		}
		virtual SQLSMALLINT
		ctype() const override
		{
			return SQL_C_INTERVAL_DAY_TO_SECOND;
		}
		virtual SQLSMALLINT
		stype() const override
		{
			return SQL_INTERVAL_DAY_TO_SECOND;
		}
		virtual SQLULEN
		size() const override
		{
			return sizeof(SQL_INTERVAL_STRUCT);
		}
		virtual SQLSMALLINT
		dp() const override
		{
			return boost::posix_time::time_res_traits::num_fractional_digits();
		}
		virtual const void *
		dataAddress() const override
		{
			return &data;
		}
		IntervalParam & operator=(const boost::posix_time::time_duration & d);

	protected:
		SQL_INTERVAL_STRUCT data;
	};
	class TimeStampParam : public Param {
	public:
		TimeStampParam() : Param() { }
		TimeStampParam(Command * c, unsigned int i) : Param(c, i)
		{
			bindLen = static_cast<SQLLEN>(TimeStampParam::size());
		}
		virtual SQLSMALLINT
		ctype() const override
		{
			return SQL_C_TYPE_TIMESTAMP;
		}
		virtual SQLSMALLINT
		stype() const override
		{
			return SQL_TYPE_TIMESTAMP;
		}
		virtual SQLULEN
		size() const override
		{
			return sizeof(SQL_TIMESTAMP_STRUCT);
		}
		virtual SQLSMALLINT
		dp() const override
		{
			return boost::posix_time::time_res_traits::num_fractional_digits();
		}
		virtual const void *
		dataAddress() const override
		{
			return &data;
		}
		TimeStampParam & operator=(const boost::posix_time::ptime & d);

	protected:
		SQL_TIMESTAMP_STRUCT data;
	};
	class NullParam : public Param {
	public:
		NullParam() : Param() { }
		NullParam(Command * c, unsigned int i) : Param(c, i)
		{
			bindLen = SQL_NULL_DATA;
		}
		virtual SQLSMALLINT
		ctype() const override
		{
			return SQL_C_LONG;
		}
		virtual SQLSMALLINT
		stype() const override
		{
			return SQL_C_LONG;
		}
		virtual SQLULEN
		size() const override
		{
			return 0;
		}
		virtual SQLSMALLINT
		dp() const override
		{
			return 0;
		}
		virtual const void *
		dataAddress() const override
		{
			return nullptr;
		}
	};
}

#endif