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