1//
2// MySQLException.cpp
3//
4// Library: SQL/MySQL
5// Package: MySQL
6// Module: Binder
7//
8// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/SQL/MySQL/Binder.h"
16
17
18namespace Poco {
19namespace SQL {
20namespace MySQL {
21
22
23Binder::Binder()
24{
25}
26
27
28Binder::~Binder()
29{
30 for (std::vector<MYSQL_TIME*>::iterator it = _dates.begin(); it != _dates.end(); ++it)
31 {
32 delete *it;
33 *it = 0;
34 }
35}
36
37
38void Binder::bind(std::size_t pos, const Poco::Int8& val, Direction dir, const WhenNullCb& /*nullCb*/)
39{
40 poco_assert(dir == PD_IN);
41 realBind(pos, MYSQL_TYPE_TINY, &val, 0);
42}
43
44
45void Binder::bind(std::size_t pos, const Poco::UInt8& val, Direction dir, const WhenNullCb& /*nullCb*/)
46{
47 poco_assert(dir == PD_IN);
48 realBind(pos, MYSQL_TYPE_TINY, &val, 0, true);
49}
50
51
52void Binder::bind(std::size_t pos, const Poco::Int16& val, Direction dir, const WhenNullCb& /*nullCb*/)
53{
54 poco_assert(dir == PD_IN);
55 realBind(pos, MYSQL_TYPE_SHORT, &val, 0);
56}
57
58
59void Binder::bind(std::size_t pos, const Poco::UInt16& val, Direction dir, const WhenNullCb& /*nullCb*/)
60{
61 poco_assert(dir == PD_IN);
62 realBind(pos, MYSQL_TYPE_SHORT, &val, 0, true);
63}
64
65
66void Binder::bind(std::size_t pos, const Poco::Int32& val, Direction dir, const WhenNullCb& /*nullCb*/)
67{
68 poco_assert(dir == PD_IN);
69 realBind(pos, MYSQL_TYPE_LONG, &val, 0);
70}
71
72
73void Binder::bind(std::size_t pos, const Poco::UInt32& val, Direction dir, const WhenNullCb& /*nullCb*/)
74{
75 poco_assert(dir == PD_IN);
76 realBind(pos, MYSQL_TYPE_LONG, &val, 0, true);
77}
78
79
80void Binder::bind(std::size_t pos, const Poco::Int64& val, Direction dir, const WhenNullCb& /*nullCb*/)
81{
82 poco_assert(dir == PD_IN);
83 realBind(pos, MYSQL_TYPE_LONGLONG, &val, 0);
84}
85
86
87void Binder::bind(std::size_t pos, const Poco::UInt64& val, Direction dir, const WhenNullCb& /*nullCb*/)
88{
89 poco_assert(dir == PD_IN);
90 realBind(pos, MYSQL_TYPE_LONGLONG, &val, 0, true);
91}
92
93
94#ifndef POCO_LONG_IS_64_BIT
95
96void Binder::bind(std::size_t pos, const long& val, Direction dir, const WhenNullCb& /*nullCb*/)
97{
98 poco_assert(dir == PD_IN);
99 realBind(pos, MYSQL_TYPE_LONG, &val, 0);
100}
101
102
103void Binder::bind(std::size_t pos, const unsigned long& val, Direction dir, const WhenNullCb& /*nullCb*/)
104{
105 poco_assert(dir == PD_IN);
106 realBind(pos, MYSQL_TYPE_LONG, &val, 0, true);
107}
108
109#endif // POCO_LONG_IS_64_BIT
110
111
112void Binder::bind(std::size_t pos, const bool& val, Direction dir, const WhenNullCb& /*nullCb*/)
113{
114 poco_assert(dir == PD_IN);
115 realBind(pos, MYSQL_TYPE_TINY, &val, 0);
116}
117
118
119void Binder::bind(std::size_t pos, const float& val, Direction dir, const WhenNullCb& /*nullCb*/)
120{
121 poco_assert(dir == PD_IN);
122 realBind(pos, MYSQL_TYPE_FLOAT, &val, 0);
123}
124
125
126void Binder::bind(std::size_t pos, const double& val, Direction dir, const WhenNullCb& /*nullCb*/)
127{
128 poco_assert(dir == PD_IN);
129 realBind(pos, MYSQL_TYPE_DOUBLE, &val, 0);
130}
131
132
133void Binder::bind(std::size_t pos, const char& val, Direction dir, const WhenNullCb& /*nullCb*/)
134{
135 poco_assert(dir == PD_IN);
136 realBind(pos, MYSQL_TYPE_TINY, &val, 0);
137}
138
139
140void Binder::bind(std::size_t pos, const std::string& val, Direction dir, const WhenNullCb& /*nullCb*/)
141{
142 poco_assert(dir == PD_IN);
143 realBind(pos, MYSQL_TYPE_STRING, val.c_str(), static_cast<int>(val.length()));
144}
145
146
147void Binder::bind(std::size_t pos, const Poco::SQL::BLOB& val, Direction dir, const WhenNullCb& /*nullCb*/)
148{
149 poco_assert(dir == PD_IN);
150 realBind(pos, MYSQL_TYPE_BLOB, val.rawContent(), static_cast<int>(val.size()));
151}
152
153
154void Binder::bind(std::size_t pos, const Poco::SQL::CLOB& val, Direction dir, const WhenNullCb& /*nullCb*/)
155{
156 poco_assert(dir == PD_IN);
157 realBind(pos, MYSQL_TYPE_BLOB, val.rawContent(), static_cast<int>(val.size()));
158}
159
160
161void Binder::bind(std::size_t pos, const DateTime& val, Direction dir, const WhenNullCb& /*nullCb*/)
162{
163 poco_assert(dir == PD_IN);
164 MYSQL_TIME mt = {0};
165
166 mt.year = val.year();
167 mt.month = val.month();
168 mt.day = val.day();
169 mt.hour = val.hour();
170 mt.minute = val.minute();
171 mt.second = val.second();
172 mt.second_part = val.millisecond() * 1000 + val.microsecond();
173
174 mt.time_type = MYSQL_TIMESTAMP_DATETIME;
175
176 _dates.push_back(new MYSQL_TIME(mt));
177
178 realBind(pos, MYSQL_TYPE_DATETIME, _dates.back(), sizeof(MYSQL_TIME));
179}
180
181
182void Binder::bind(std::size_t pos, const Date& val, Direction dir, const WhenNullCb& /*nullCb*/)
183{
184 poco_assert(dir == PD_IN);
185 MYSQL_TIME mt = {0};
186
187 mt.year = val.year();
188 mt.month = val.month();
189 mt.day = val.day();
190
191 mt.time_type = MYSQL_TIMESTAMP_DATE;
192
193 _dates.push_back(new MYSQL_TIME(mt));
194
195 realBind(pos, MYSQL_TYPE_DATE, _dates.back(), sizeof(MYSQL_TIME));
196}
197
198
199void Binder::bind(std::size_t pos, const Time& val, Direction dir, const WhenNullCb& /*nullCb*/)
200{
201 poco_assert(dir == PD_IN);
202 MYSQL_TIME mt = {0};
203
204 mt.hour = val.hour();
205 mt.minute = val.minute();
206 mt.second = val.second();
207
208 mt.time_type = MYSQL_TIMESTAMP_TIME;
209
210 _dates.push_back(new MYSQL_TIME(mt));
211
212 realBind(pos, MYSQL_TYPE_TIME, _dates.back(), sizeof(MYSQL_TIME));
213}
214
215
216void Binder::bind(std::size_t pos, const NullData&, Direction dir, const std::type_info& /*bindType*/)
217{
218 poco_assert(dir == PD_IN);
219 realBind(pos, MYSQL_TYPE_NULL, 0, 0);
220}
221
222
223std::size_t Binder::size() const
224{
225 return static_cast<std::size_t>(_bindArray.size());
226}
227
228
229MYSQL_BIND* Binder::getBindArray() const
230{
231 if (_bindArray.size() == 0)
232 {
233 return 0;
234 }
235
236 return const_cast<MYSQL_BIND*>(&_bindArray[0]);
237}
238
239
240/*void Binder::updateDates()
241{
242 for (std::size_t i = 0; i < _dates.size(); i++)
243 {
244 switch (_dates[i].mt.time_type)
245 {
246 case MYSQL_TIMESTAMP_DATE:
247 _dates[i].mt.year = _dates[i].link.date->year();
248 _dates[i].mt.month = _dates[i].link.date->month();
249 _dates[i].mt.day = _dates[i].link.date->day();
250 break;
251 case MYSQL_TIMESTAMP_DATETIME:
252 _dates[i].mt.year = _dates[i].link.dateTime->year();
253 _dates[i].mt.month = _dates[i].link.dateTime->month();
254 _dates[i].mt.day = _dates[i].link.dateTime->day();
255 _dates[i].mt.hour = _dates[i].link.dateTime->hour();
256 _dates[i].mt.minute = _dates[i].link.dateTime->minute();
257 _dates[i].mt.second = _dates[i].link.dateTime->second();
258 _dates[i].mt.second_part = _dates[i].link.dateTime->millisecond();
259 break;
260 case MYSQL_TIMESTAMP_TIME:
261 _dates[i].mt.hour = _dates[i].link.time->hour();
262 _dates[i].mt.minute = _dates[i].link.time->minute();
263 _dates[i].mt.second = _dates[i].link.time->second();
264 break;
265 }
266 }
267}*/
268
269///////////////////
270//
271// Private
272//
273////////////////////
274
275void Binder::realBind(std::size_t pos, enum_field_types type, const void* buffer, int length, bool isUnsigned)
276{
277 if (pos >= _bindArray.size())
278 {
279 std::size_t s = static_cast<std::size_t>(_bindArray.size());
280 _bindArray.resize(pos + 1);
281
282 std::memset(&_bindArray[s], 0, sizeof(MYSQL_BIND) * (_bindArray.size() - s));
283 }
284
285 MYSQL_BIND b = {0};
286
287 b.buffer_type = type;
288 b.buffer = const_cast<void*>(buffer);
289 b.buffer_length = length;
290 b.is_unsigned = isUnsigned;
291
292 _bindArray[pos] = b;
293}
294
295
296void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::Int8>& /*val*/, Direction /*dir*/)
297{
298 throw NotImplementedException();
299}
300
301
302void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::Int8>& /*val*/, Direction /*dir*/)
303{
304 throw NotImplementedException();
305}
306
307
308void Binder::bind(std::size_t /*pos*/, const std::list<Poco::Int8>& /*val*/, Direction /*dir*/)
309{
310 throw NotImplementedException();
311}
312
313
314void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::UInt8>& /*val*/, Direction /*dir*/)
315{
316 throw NotImplementedException();
317}
318
319
320void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::UInt8>& /*val*/, Direction /*dir*/)
321{
322 throw NotImplementedException();
323}
324
325
326void Binder::bind(std::size_t /*pos*/, const std::list<Poco::UInt8>& /*val*/, Direction /*dir*/)
327{
328 throw NotImplementedException();
329}
330
331
332void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::Int16>& /*val*/, Direction /*dir*/)
333{
334 throw NotImplementedException();
335}
336
337
338void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::Int16>& /*val*/, Direction /*dir*/)
339{
340 throw NotImplementedException();
341}
342
343
344void Binder::bind(std::size_t /*pos*/, const std::list<Poco::Int16>& /*val*/, Direction /*dir*/)
345{
346 throw NotImplementedException();
347}
348
349
350void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::UInt16>& /*val*/, Direction /*dir*/)
351{
352 throw NotImplementedException();
353}
354
355
356void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::UInt16>& /*val*/, Direction /*dir*/)
357{
358 throw NotImplementedException();
359}
360
361
362void Binder::bind(std::size_t /*pos*/, const std::list<Poco::UInt16>& /*val*/, Direction /*dir*/)
363{
364 throw NotImplementedException();
365}
366
367
368void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::Int32>& /*val*/, Direction /*dir*/)
369{
370 throw NotImplementedException();
371}
372
373
374void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::Int32>& /*val*/, Direction /*dir*/)
375{
376 throw NotImplementedException();
377}
378
379
380void Binder::bind(std::size_t /*pos*/, const std::list<Poco::Int32>& /*val*/, Direction /*dir*/)
381{
382 throw NotImplementedException();
383}
384
385
386void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::UInt32>& /*val*/, Direction /*dir*/)
387{
388 throw NotImplementedException();
389}
390
391
392void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::UInt32>& /*val*/, Direction /*dir*/)
393{
394 throw NotImplementedException();
395}
396
397
398void Binder::bind(std::size_t /*pos*/, const std::list<Poco::UInt32>& /*val*/, Direction /*dir*/)
399{
400 throw NotImplementedException();
401}
402
403
404void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::Int64>& /*val*/, Direction /*dir*/)
405{
406 throw NotImplementedException();
407}
408
409
410void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::Int64>& /*val*/, Direction /*dir*/)
411{
412 throw NotImplementedException();
413}
414
415
416void Binder::bind(std::size_t /*pos*/, const std::list<Poco::Int64>& /*val*/, Direction /*dir*/)
417{
418 throw NotImplementedException();
419}
420
421
422void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::UInt64>& /*val*/, Direction /*dir*/)
423{
424 throw NotImplementedException();
425}
426
427
428void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::UInt64>& /*val*/, Direction /*dir*/)
429{
430 throw NotImplementedException();
431}
432
433
434void Binder::bind(std::size_t /*pos*/, const std::list<Poco::UInt64>& /*val*/, Direction /*dir*/)
435{
436 throw NotImplementedException();
437}
438
439
440void Binder::bind(std::size_t /*pos*/, const std::vector<bool>& /*val*/, Direction /*dir*/)
441{
442 throw NotImplementedException();
443}
444
445
446void Binder::bind(std::size_t /*pos*/, const std::deque<bool>& /*val*/, Direction /*dir*/)
447{
448 throw NotImplementedException();
449}
450
451
452void Binder::bind(std::size_t /*pos*/, const std::list<bool>& /*val*/, Direction /*dir*/)
453{
454 throw NotImplementedException();
455}
456
457
458void Binder::bind(std::size_t /*pos*/, const std::vector<float>& /*val*/, Direction /*dir*/)
459{
460 throw NotImplementedException();
461}
462
463
464void Binder::bind(std::size_t /*pos*/, const std::deque<float>& /*val*/, Direction /*dir*/)
465{
466 throw NotImplementedException();
467}
468
469
470void Binder::bind(std::size_t /*pos*/, const std::list<float>& /*val*/, Direction /*dir*/)
471{
472 throw NotImplementedException();
473}
474
475
476void Binder::bind(std::size_t /*pos*/, const std::vector<double>& /*val*/, Direction /*dir*/)
477{
478 throw NotImplementedException();
479}
480
481
482void Binder::bind(std::size_t /*pos*/, const std::deque<double>& /*val*/, Direction /*dir*/)
483{
484 throw NotImplementedException();
485}
486
487
488void Binder::bind(std::size_t /*pos*/, const std::list<double>& /*val*/, Direction /*dir*/)
489{
490 throw NotImplementedException();
491}
492
493
494void Binder::bind(std::size_t /*pos*/, const std::vector<char>& /*val*/, Direction /*dir*/)
495{
496 throw NotImplementedException();
497}
498
499
500void Binder::bind(std::size_t /*pos*/, const std::deque<char>& /*val*/, Direction /*dir*/)
501{
502 throw NotImplementedException();
503}
504
505
506void Binder::bind(std::size_t /*pos*/, const std::list<char>& /*val*/, Direction /*dir*/)
507{
508 throw NotImplementedException();
509}
510
511
512void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::SQL::BLOB>& /*val*/, Direction /*dir*/)
513{
514 throw NotImplementedException();
515}
516
517
518void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::SQL::BLOB>& /*val*/, Direction /*dir*/)
519{
520 throw NotImplementedException();
521}
522
523
524void Binder::bind(std::size_t /*pos*/, const std::list<Poco::SQL::BLOB>& /*val*/, Direction /*dir*/)
525{
526 throw NotImplementedException();
527}
528
529
530void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::SQL::CLOB>& /*val*/, Direction /*dir*/)
531{
532 throw NotImplementedException();
533}
534
535
536void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::SQL::CLOB>& /*val*/, Direction /*dir*/)
537{
538 throw NotImplementedException();
539}
540
541
542void Binder::bind(std::size_t /*pos*/, const std::list<Poco::SQL::CLOB>& /*val*/, Direction /*dir*/)
543{
544 throw NotImplementedException();
545}
546
547
548void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::DateTime>& /*val*/, Direction /*dir*/)
549{
550 throw NotImplementedException();
551}
552
553
554void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::DateTime>& /*val*/, Direction /*dir*/)
555{
556 throw NotImplementedException();
557}
558
559
560void Binder::bind(std::size_t /*pos*/, const std::list<Poco::DateTime>& /*val*/, Direction /*dir*/)
561{
562 throw NotImplementedException();
563}
564
565
566void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::SQL::Date>& /*val*/, Direction /*dir*/)
567{
568 throw NotImplementedException();
569}
570
571
572void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::SQL::Date>& /*val*/, Direction /*dir*/)
573{
574 throw NotImplementedException();
575}
576
577
578void Binder::bind(std::size_t /*pos*/, const std::list<Poco::SQL::Date>& /*val*/, Direction /*dir*/)
579{
580 throw NotImplementedException();
581}
582
583
584void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::SQL::Time>& /*val*/, Direction /*dir*/)
585{
586 throw NotImplementedException();
587}
588
589
590void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::SQL::Time>& /*val*/, Direction /*dir*/)
591{
592 throw NotImplementedException();
593}
594
595
596void Binder::bind(std::size_t /*pos*/, const std::list<Poco::SQL::Time>& /*val*/, Direction /*dir*/)
597{
598 throw NotImplementedException();
599}
600
601
602void Binder::bind(std::size_t /*pos*/, const std::vector<Poco::SQL::NullData>& /*val*/, Direction /*dir*/, const std::type_info& /*bindType*/)
603{
604 throw NotImplementedException();
605}
606
607
608void Binder::bind(std::size_t /*pos*/, const std::deque<Poco::SQL::NullData>& /*val*/, Direction /*dir*/, const std::type_info& /*bindType*/)
609{
610 throw NotImplementedException();
611}
612
613
614void Binder::bind(std::size_t /*pos*/, const std::list<Poco::SQL::NullData>& /*val*/, Direction /*dir*/, const std::type_info& /*bindType*/)
615{
616 throw NotImplementedException();
617}
618
619
620void Binder::bind(std::size_t /*pos*/, const std::vector<std::string>& /*val*/, Direction /*dir*/)
621{
622 throw NotImplementedException();
623}
624
625
626void Binder::bind(std::size_t /*pos*/, const std::deque<std::string>& /*val*/, Direction /*dir*/)
627{
628 throw NotImplementedException();
629}
630
631
632void Binder::bind(std::size_t /*pos*/, const std::list<std::string>& /*val*/, Direction /*dir*/)
633{
634 throw NotImplementedException();
635}
636
637
638} } } // namespace Poco::SQL::MySQL
639