soci-simple.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2008 Maciej Sobczak
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 #define SOCI_SOURCE
9 
10 #include "soci-simple.h"
11 #include "soci.h"
12 
13 #include <cstddef>
14 #include <cstdio>
15 #include <ctime>
16 #include <exception>
17 #include <map>
18 #include <string>
19 #include <vector>
20 
21 using namespace soci;
22 
23 namespace // unnamed
24 {
25 
26 struct session_wrapper
27 {
28  session sql;
29 
30  bool is_ok;
31  std::string error_message;
32 };
33 
34 } // namespace unnamed
35 
36 
37 SOCI_DECL session_handle soci_create_session(char const * connection_string)
38 {
39  session_wrapper * wrapper = NULL;
40  try
41  {
42  wrapper = new session_wrapper();
43  }
44  catch (...)
45  {
46  return NULL;
47  }
48 
49  try
50  {
51  wrapper->sql.open(connection_string);
52  wrapper->is_ok = true;
53  }
54  catch (std::exception const & e)
55  {
56  wrapper->is_ok = false;
57  wrapper->error_message = e.what();
58  }
59 
60  return wrapper;
61 }
62 
64 {
65  session_wrapper * wrapper = static_cast<session_wrapper *>(s);
66  delete wrapper;
67 }
68 
70 {
71  session_wrapper * wrapper = static_cast<session_wrapper *>(s);
72  try
73  {
74  wrapper->sql.begin();
75  wrapper->is_ok = true;
76  }
77  catch (std::exception const & e)
78  {
79  wrapper->is_ok = false;
80  wrapper->error_message = e.what();
81  }
82 }
83 
85 {
86  session_wrapper * wrapper = static_cast<session_wrapper *>(s);
87  try
88  {
89  wrapper->sql.commit();
90  wrapper->is_ok = true;
91  }
92  catch (std::exception const & e)
93  {
94  wrapper->is_ok = false;
95  wrapper->error_message = e.what();
96  }
97 }
98 
100 {
101  session_wrapper * wrapper = static_cast<session_wrapper *>(s);
102  try
103  {
104  wrapper->sql.rollback();
105  wrapper->is_ok = true;
106  }
107  catch (std::exception const & e)
108  {
109  wrapper->is_ok = false;
110  wrapper->error_message = e.what();
111  }
112 }
113 
114 // this will not be needed until dynamic row is exposed
115 // SOCI_DECL void soci_uppercase_column_names(session_handle s, bool forceToUpper)
116 // {
117 // session_wrapper * wrapper = static_cast<session_wrapper *>(s);
118 // wrapper->sql.uppercase_column_names(forceToUpper);
119 // wrapper->is_ok = true;
120 // }
121 
123 {
124  session_wrapper * wrapper = static_cast<session_wrapper *>(s);
125 
126  return wrapper->is_ok ? 1 : 0;
127 }
128 
130 {
131  session_wrapper * wrapper = static_cast<session_wrapper *>(s);
132 
133  return wrapper->error_message.c_str();
134 }
135 
136 
137 // statement
138 
139 
140 namespace // unnamed
141 {
142 
143 struct statement_wrapper
144 {
145  statement_wrapper(session & sql)
146  : st(sql), statement_state(clean), into_kind(empty), use_kind(empty),
147  next_position(0), is_ok(true) {}
148 
149  statement st;
150 
151  enum state { clean, defining, executing } statement_state;
152  enum kind { empty, single, bulk } into_kind, use_kind;
153 
154  // into elements
155  int next_position;
156  std::vector<data_type> into_types; // for both single and bulk
157  std::vector<indicator> into_indicators;
158  std::map<int, std::string> into_strings;
159  std::map<int, int> into_ints;
160  std::map<int, long long> into_longlongs;
161  std::map<int, double> into_doubles;
162  std::map<int, std::tm> into_dates;
163 
164  std::vector<std::vector<indicator> > into_indicators_v;
165  std::map<int, std::vector<std::string> > into_strings_v;
166  std::map<int, std::vector<int> > into_ints_v;
167  std::map<int, std::vector<long long> > into_longlongs_v;
168  std::map<int, std::vector<double> > into_doubles_v;
169  std::map<int, std::vector<std::tm> > into_dates_v;
170 
171  // use elements
172  std::map<std::string, indicator> use_indicators;
173  std::map<std::string, std::string> use_strings;
174  std::map<std::string, int> use_ints;
175  std::map<std::string, long long> use_longlongs;
176  std::map<std::string, double> use_doubles;
177  std::map<std::string, std::tm> use_dates;
178 
179  std::map<std::string, std::vector<indicator> > use_indicators_v;
180  std::map<std::string, std::vector<std::string> > use_strings_v;
181  std::map<std::string, std::vector<int> > use_ints_v;
182  std::map<std::string, std::vector<long long> > use_longlongs_v;
183  std::map<std::string, std::vector<double> > use_doubles_v;
184  std::map<std::string, std::vector<std::tm> > use_dates_v;
185 
186  // format is: "YYYY MM DD hh mm ss"
187  char date_formatted[20];
188 
189  bool is_ok;
190  std::string error_message;
191 };
192 
193 // helper for checking if the attempt was made to add more into/use elements
194 // after the statement was set for execution
195 bool cannot_add_elements(statement_wrapper & wrapper, statement_wrapper::kind k, bool into)
196 {
197  if (wrapper.statement_state == statement_wrapper::executing)
198  {
199  wrapper.is_ok = false;
200  wrapper.error_message = "Cannot add more data items.";
201  return true;
202  }
203 
204  if (into)
205  {
206  if (k == statement_wrapper::single && wrapper.into_kind == statement_wrapper::bulk)
207  {
208  wrapper.is_ok = false;
209  wrapper.error_message = "Cannot add single into data items.";
210  return true;
211  }
212  if (k == statement_wrapper::bulk && wrapper.into_kind == statement_wrapper::single)
213  {
214  wrapper.is_ok = false;
215  wrapper.error_message = "Cannot add vector into data items.";
216  return true;
217  }
218  }
219  else
220  {
221  // trying to add use elements
222  if (k == statement_wrapper::single && wrapper.use_kind == statement_wrapper::bulk)
223  {
224  wrapper.is_ok = false;
225  wrapper.error_message = "Cannot add single use data items.";
226  return true;
227  }
228  if (k == statement_wrapper::bulk && wrapper.use_kind == statement_wrapper::single)
229  {
230  wrapper.is_ok = false;
231  wrapper.error_message = "Cannot add vector use data items.";
232  return true;
233  }
234  }
235 
236  wrapper.is_ok = true;
237  return false;
238 }
239 
240 // helper for checking if the expected into element exists on the given position
241 bool position_check_failed(statement_wrapper & wrapper, statement_wrapper::kind k,
242  int position, data_type expected_type, char const * type_name)
243 {
244  if (position < 0 || position >= wrapper.next_position)
245  {
246  wrapper.is_ok = false;
247  wrapper.error_message = "Invalid position.";
248  return true;
249  }
250 
251  if (wrapper.into_types[position] != expected_type)
252  {
253  wrapper.is_ok = false;
254  wrapper.error_message = "No into ";
255  if (k == statement_wrapper::bulk)
256  {
257  wrapper.error_message += "vector ";
258  }
259  wrapper.error_message += type_name;
260  wrapper.error_message += " element at this position.";
261  return true;
262  }
263 
264  wrapper.is_ok = true;
265  return false;
266 }
267 
268 // helper for checking if the into element on the given position
269 // is not null
270 bool not_null_check_failed(statement_wrapper & wrapper, int position)
271 {
272  if (wrapper.into_indicators[position] == i_null)
273  {
274  wrapper.is_ok = false;
275  wrapper.error_message = "Element is null.";
276  return true;
277  }
278 
279  wrapper.is_ok = true;
280  return false;
281 }
282 
283 // overloaded version for vectors
284 bool not_null_check_failed(statement_wrapper & wrapper, int position, int index)
285 {
286  if (wrapper.into_indicators_v[position][index] == i_null)
287  {
288  wrapper.is_ok = false;
289  wrapper.error_message = "Element is null.";
290  return true;
291  }
292 
293  wrapper.is_ok = true;
294  return false;
295 }
296 
297 // helper for checking the index value
298 template <typename T>
299 bool index_check_failed(std::vector<T> const & v,
300  statement_wrapper & wrapper, int index)
301 {
302  if (index < 0 || index >= static_cast<int>(v.size()))
303  {
304  wrapper.is_ok = false;
305  wrapper.error_message = "Invalid index.";
306  return true;
307  }
308 
309  wrapper.is_ok = true;
310  return false;
311 }
312 
313 // helper for checking the uniqueness of the use element's name
314 bool name_unique_check_failed(statement_wrapper & wrapper,
315  statement_wrapper::kind k, char const * name)
316 {
317  bool is_unique;
318  if (k == statement_wrapper::single)
319  {
320  typedef std::map<std::string, indicator>::const_iterator iterator;
321  iterator const it = wrapper.use_indicators.find(name);
322  is_unique = it == wrapper.use_indicators.end();
323  }
324  else
325  {
326  // vector version
327 
328  typedef std::map
329  <
330  std::string,
331  std::vector<indicator>
332  >::const_iterator iterator;
333 
334  iterator const it = wrapper.use_indicators_v.find(name);
335  is_unique = it == wrapper.use_indicators_v.end();
336  }
337 
338  if (is_unique)
339  {
340  wrapper.is_ok = true;
341  return false;
342  }
343  else
344  {
345  wrapper.is_ok = false;
346  wrapper.error_message = "Name of use element should be unique.";
347  return true;
348  }
349 }
350 
351 // helper for checking if the use element with the given name exists
352 bool name_exists_check_failed(statement_wrapper & wrapper,
353  char const * name, data_type expected_type,
354  statement_wrapper::kind k, char const * type_name)
355 {
356  bool name_exists = false;
357  if (k == statement_wrapper::single)
358  {
359  switch (expected_type)
360  {
361  case dt_string:
362  {
363  typedef std::map
364  <
365  std::string,
366  std::string
367  >::const_iterator iterator;
368  iterator const it = wrapper.use_strings.find(name);
369  name_exists = (it != wrapper.use_strings.end());
370  }
371  break;
372  case dt_integer:
373  {
374  typedef std::map<std::string, int>::const_iterator iterator;
375  iterator const it = wrapper.use_ints.find(name);
376  name_exists = (it != wrapper.use_ints.end());
377  }
378  break;
379  case dt_long_long:
380  {
381  typedef std::map<std::string, long long>::const_iterator
382  iterator;
383  iterator const it = wrapper.use_longlongs.find(name);
384  name_exists = (it != wrapper.use_longlongs.end());
385  }
386  break;
387  case dt_double:
388  {
389  typedef std::map<std::string, double>::const_iterator iterator;
390  iterator const it = wrapper.use_doubles.find(name);
391  name_exists = (it != wrapper.use_doubles.end());
392  }
393  break;
394  case dt_date:
395  {
396  typedef std::map<std::string, std::tm>::const_iterator iterator;
397  iterator const it = wrapper.use_dates.find(name);
398  name_exists = (it != wrapper.use_dates.end());
399  }
400  break;
401  default:
402  assert(false);
403  }
404  }
405  else
406  {
407  // vector version
408 
409  switch (expected_type)
410  {
411  case dt_string:
412  {
413  typedef std::map
414  <
415  std::string,
416  std::vector<std::string>
417  >::const_iterator iterator;
418  iterator const it = wrapper.use_strings_v.find(name);
419  name_exists = (it != wrapper.use_strings_v.end());
420  }
421  break;
422  case dt_integer:
423  {
424  typedef std::map
425  <
426  std::string,
427  std::vector<int>
428  >::const_iterator iterator;
429  iterator const it = wrapper.use_ints_v.find(name);
430  name_exists = (it != wrapper.use_ints_v.end());
431  }
432  break;
433  case dt_long_long:
434  {
435  typedef std::map
436  <
437  std::string,
438  std::vector<long long>
439  >::const_iterator iterator;
440  iterator const it = wrapper.use_longlongs_v.find(name);
441  name_exists = (it != wrapper.use_longlongs_v.end());
442  }
443  break;
444  case dt_double:
445  {
446  typedef std::map<std::string,
447  std::vector<double> >::const_iterator iterator;
448  iterator const it = wrapper.use_doubles_v.find(name);
449  name_exists = (it != wrapper.use_doubles_v.end());
450  }
451  break;
452  case dt_date:
453  {
454  typedef std::map<std::string,
455  std::vector<std::tm> >::const_iterator iterator;
456  iterator const it = wrapper.use_dates_v.find(name);
457  name_exists = (it != wrapper.use_dates_v.end());
458  }
459  break;
460  default:
461  assert(false);
462  }
463  }
464 
465  if (name_exists)
466  {
467  wrapper.is_ok = true;
468  return false;
469  }
470  else
471  {
472  wrapper.is_ok = false;
473  wrapper.error_message = "No use ";
474  wrapper.error_message += type_name;
475  wrapper.error_message += " element with this name.";
476  return true;
477  }
478 }
479 
480 // helper function for resizing all vectors<T> in the map
481 template <typename T>
482 void resize_in_map(std::map<std::string, std::vector<T> > & m, int new_size)
483 {
484  typedef typename std::map<std::string, std::vector<T> >::iterator iterator;
485  iterator it = m.begin();
486  iterator const end = m.end();
487  for ( ; it != end; ++it)
488  {
489  std::vector<T> & v = it->second;
490  v.resize(new_size);
491  }
492 }
493 
494 // helper for formatting date values
495 char const * format_date(statement_wrapper & wrapper, std::tm const & d)
496 {
497  std::sprintf(wrapper.date_formatted, "%d %d %d %d %d %d",
498  d.tm_year + 1900, d.tm_mon + 1, d.tm_mday,
499  d.tm_hour, d.tm_min, d.tm_sec);
500 
501  return wrapper.date_formatted;
502 }
503 
504 bool string_to_date(char const * val, std::tm & /* out */ dt,
505  statement_wrapper & wrapper)
506 {
507  // format is: "YYYY MM DD hh mm ss"
508  int year;
509  int month;
510  int day;
511  int hour;
512  int minute;
513  int second;
514  int const converted = std::sscanf(val, "%d %d %d %d %d %d",
515  &year, &month, &day, &hour, &minute, &second);
516  if (converted != 6)
517  {
518  wrapper.is_ok = false;
519  wrapper.error_message = "Cannot convert date.";
520  return false;
521  }
522 
523  wrapper.is_ok = true;
524 
525  dt.tm_year = year - 1900;
526  dt.tm_mon = month - 1;
527  dt.tm_mday = day;
528  dt.tm_hour = hour;
529  dt.tm_min = minute;
530  dt.tm_sec = second;
531 
532 return true;
533 }
534 
535 } // namespace unnamed
536 
537 
539 {
540  session_wrapper * session_w = static_cast<session_wrapper *>(s);
541  try
542  {
543  statement_wrapper * statement_w = new statement_wrapper(session_w->sql);
544  return statement_w;
545  }
546  catch (std::exception const & e)
547  {
548  session_w->is_ok = false;
549  session_w->error_message = e.what();
550  return NULL;
551  }
552 }
553 
555 {
556  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
557  delete wrapper;
558 }
559 
561 {
562  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
563 
564  if (cannot_add_elements(*wrapper, statement_wrapper::single, true))
565  {
566  return -1;
567  }
568 
569  wrapper->statement_state = statement_wrapper::defining;
570  wrapper->into_kind = statement_wrapper::single;
571 
572  wrapper->into_types.push_back(dt_string);
573  wrapper->into_indicators.push_back(i_ok);
574  wrapper->into_strings[wrapper->next_position]; // create new entry
575  return wrapper->next_position++;
576 }
577 
579 {
580  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
581 
582  if (cannot_add_elements(*wrapper, statement_wrapper::single, true))
583  {
584  return -1;
585  }
586 
587  wrapper->statement_state = statement_wrapper::defining;
588  wrapper->into_kind = statement_wrapper::single;
589 
590  wrapper->into_types.push_back(dt_integer);
591  wrapper->into_indicators.push_back(i_ok);
592  wrapper->into_ints[wrapper->next_position]; // create new entry
593  return wrapper->next_position++;
594 }
595 
597 {
598  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
599 
600  if (cannot_add_elements(*wrapper, statement_wrapper::single, true))
601  {
602  return -1;
603  }
604 
605  wrapper->statement_state = statement_wrapper::defining;
606  wrapper->into_kind = statement_wrapper::single;
607 
608  wrapper->into_types.push_back(dt_long_long);
609  wrapper->into_indicators.push_back(i_ok);
610  wrapper->into_longlongs[wrapper->next_position]; // create new entry
611  return wrapper->next_position++;
612 }
613 
615 {
616  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
617 
618  if (cannot_add_elements(*wrapper, statement_wrapper::single, true))
619  {
620  return -1;
621  }
622 
623  wrapper->statement_state = statement_wrapper::defining;
624  wrapper->into_kind = statement_wrapper::single;
625 
626  wrapper->into_types.push_back(dt_double);
627  wrapper->into_indicators.push_back(i_ok);
628  wrapper->into_doubles[wrapper->next_position]; // create new entry
629  return wrapper->next_position++;
630 }
631 
633 {
634  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
635 
636  if (cannot_add_elements(*wrapper, statement_wrapper::single, true))
637  {
638  return -1;
639  }
640 
641  wrapper->statement_state = statement_wrapper::defining;
642  wrapper->into_kind = statement_wrapper::single;
643 
644  wrapper->into_types.push_back(dt_date);
645  wrapper->into_indicators.push_back(i_ok);
646  wrapper->into_dates[wrapper->next_position]; // create new entry
647  return wrapper->next_position++;
648 }
649 
651 {
652  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
653 
654  if (cannot_add_elements(*wrapper, statement_wrapper::bulk, true))
655  {
656  return -1;
657  }
658 
659  wrapper->statement_state = statement_wrapper::defining;
660  wrapper->into_kind = statement_wrapper::bulk;
661 
662  wrapper->into_types.push_back(dt_string);
663  wrapper->into_indicators_v.push_back(std::vector<indicator>());
664  wrapper->into_strings_v[wrapper->next_position];
665  return wrapper->next_position++;
666 }
667 
669 {
670  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
671 
672  if (cannot_add_elements(*wrapper, statement_wrapper::bulk, true))
673  {
674  return -1;
675  }
676 
677  wrapper->statement_state = statement_wrapper::defining;
678  wrapper->into_kind = statement_wrapper::bulk;
679 
680  wrapper->into_types.push_back(dt_integer);
681  wrapper->into_indicators_v.push_back(std::vector<indicator>());
682  wrapper->into_ints_v[wrapper->next_position];
683  return wrapper->next_position++;
684 }
685 
687 {
688  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
689 
690  if (cannot_add_elements(*wrapper, statement_wrapper::bulk, true))
691  {
692  return -1;
693  }
694 
695  wrapper->statement_state = statement_wrapper::defining;
696  wrapper->into_kind = statement_wrapper::bulk;
697 
698  wrapper->into_types.push_back(dt_long_long);
699  wrapper->into_indicators_v.push_back(std::vector<indicator>());
700  wrapper->into_longlongs_v[wrapper->next_position];
701  return wrapper->next_position++;
702 }
703 
705 {
706  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
707 
708  if (cannot_add_elements(*wrapper, statement_wrapper::bulk, true))
709  {
710  return -1;
711  }
712 
713  wrapper->statement_state = statement_wrapper::defining;
714  wrapper->into_kind = statement_wrapper::bulk;
715 
716  wrapper->into_types.push_back(dt_double);
717  wrapper->into_indicators_v.push_back(std::vector<indicator>());
718  wrapper->into_doubles_v[wrapper->next_position];
719  return wrapper->next_position++;
720 }
721 
723 {
724  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
725 
726  if (cannot_add_elements(*wrapper, statement_wrapper::bulk, true))
727  {
728  return -1;
729  }
730 
731  wrapper->statement_state = statement_wrapper::defining;
732  wrapper->into_kind = statement_wrapper::bulk;
733 
734  wrapper->into_types.push_back(dt_date);
735  wrapper->into_indicators_v.push_back(std::vector<indicator>());
736  wrapper->into_dates_v[wrapper->next_position];
737  return wrapper->next_position++;
738 }
739 
741 {
742  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
743 
744  if (position < 0 || position >= wrapper->next_position)
745  {
746  wrapper->is_ok = false;
747  wrapper->error_message = "Invalid position.";
748  return 0;
749  }
750 
751  wrapper->is_ok = true;
752  return wrapper->into_indicators[position] == i_ok ? 1 : 0;
753 }
754 
755 SOCI_DECL char const * soci_get_into_string(statement_handle st, int position)
756 {
757  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
758 
759  if (position_check_failed(*wrapper,
760  statement_wrapper::single, position, dt_string, "string") ||
761  not_null_check_failed(*wrapper, position))
762  {
763  return "";
764  }
765 
766  return wrapper->into_strings[position].c_str();
767 }
768 
770 {
771  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
772 
773  if (position_check_failed(*wrapper,
774  statement_wrapper::single, position, dt_integer, "int") ||
775  not_null_check_failed(*wrapper, position))
776  {
777  return 0;
778  }
779 
780  return wrapper->into_ints[position];
781 }
782 
784 {
785  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
786 
787  if (position_check_failed(*wrapper,
788  statement_wrapper::single, position, dt_long_long, "long long") ||
789  not_null_check_failed(*wrapper, position))
790  {
791  return 0LL;
792  }
793 
794  return wrapper->into_longlongs[position];
795 }
796 
798 {
799  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
800 
801  if (position_check_failed(*wrapper,
802  statement_wrapper::single, position, dt_double, "double") ||
803  not_null_check_failed(*wrapper, position))
804  {
805  return 0.0;
806  }
807 
808  return wrapper->into_doubles[position];
809 }
810 
811 SOCI_DECL char const * soci_get_into_date(statement_handle st, int position)
812 {
813  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
814 
815  if (position_check_failed(*wrapper,
816  statement_wrapper::single, position, dt_date, "date") ||
817  not_null_check_failed(*wrapper, position))
818  {
819  return "";
820  }
821 
822  // format is: "YYYY MM DD hh mm ss"
823  std::tm const & d = wrapper->into_dates[position];
824  return format_date(*wrapper, d);
825 }
826 
828 {
829  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
830 
831  if (wrapper->into_kind != statement_wrapper::bulk)
832  {
833  wrapper->is_ok = false;
834  wrapper->error_message = "No vector into elements.";
835  return -1;
836  }
837 
838  return static_cast<int>(wrapper->into_indicators_v[0].size());
839 }
840 
842 {
843  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
844 
845  if (new_size <= 0)
846  {
847  wrapper->is_ok = false;
848  wrapper->error_message = "Invalid size.";
849  return;
850  }
851 
852  if (wrapper->into_kind != statement_wrapper::bulk)
853  {
854  wrapper->is_ok = false;
855  wrapper->error_message = "No vector into elements.";
856  return;
857  }
858 
859  for (int i = 0; i != wrapper->next_position; ++i)
860  {
861  wrapper->into_indicators_v[i].resize(new_size);
862 
863  switch (wrapper->into_types[i])
864  {
865  case dt_string:
866  wrapper->into_strings_v[i].resize(new_size);
867  break;
868  case dt_integer:
869  wrapper->into_ints_v[i].resize(new_size);
870  break;
871  case dt_long_long:
872  wrapper->into_longlongs_v[i].resize(new_size);
873  break;
874  case dt_double:
875  wrapper->into_doubles_v[i].resize(new_size);
876  break;
877  case dt_date:
878  wrapper->into_dates_v[i].resize(new_size);
879  break;
880  default:
881  assert(false);
882  }
883  }
884 
885  wrapper->is_ok = true;
886 }
887 
888 SOCI_DECL int soci_get_into_state_v(statement_handle st, int position, int index)
889 {
890  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
891 
892  if (position < 0 || position >= wrapper->next_position)
893  {
894  wrapper->is_ok = false;
895  wrapper->error_message = "Invalid position.";
896  return 0;
897  }
898 
899  std::vector<indicator> const & v = wrapper->into_indicators_v[position];
900  if (index_check_failed(v, *wrapper, index))
901  {
902  return 0;
903  }
904 
905  return v[index] == i_ok ? 1 : 0;
906 }
907 
908 SOCI_DECL char const * soci_get_into_string_v(statement_handle st, int position, int index)
909 {
910  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
911 
912  if (position_check_failed(*wrapper,
913  statement_wrapper::bulk, position, dt_string, "string"))
914  {
915  return "";
916  }
917 
918  std::vector<std::string> const & v = wrapper->into_strings_v[position];
919  if (index_check_failed(v, *wrapper, index) ||
920  not_null_check_failed(*wrapper, position, index))
921  {
922  return "";
923  }
924 
925  return v[index].c_str();
926 }
927 
928 SOCI_DECL int soci_get_into_int_v(statement_handle st, int position, int index)
929 {
930  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
931 
932  if (position_check_failed(*wrapper,
933  statement_wrapper::bulk, position, dt_integer, "int"))
934  {
935  return 0;
936  }
937 
938  std::vector<int> const & v = wrapper->into_ints_v[position];
939  if (index_check_failed(v, *wrapper, index) ||
940  not_null_check_failed(*wrapper, position, index))
941  {
942  return 0;
943  }
944 
945  return v[index];
946 }
947 
948 SOCI_DECL long long soci_get_into_long_long_v(statement_handle st, int position, int index)
949 {
950  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
951 
952  if (position_check_failed(*wrapper,
953  statement_wrapper::bulk, position, dt_long_long, "long long"))
954  {
955  return 0;
956  }
957 
958  std::vector<long long> const & v = wrapper->into_longlongs_v[position];
959  if (index_check_failed(v, *wrapper, index) ||
960  not_null_check_failed(*wrapper, position, index))
961  {
962  return 0;
963  }
964 
965  return v[index];
966 }
967 
968 SOCI_DECL double soci_get_into_double_v(statement_handle st, int position, int index)
969 {
970  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
971 
972  if (position_check_failed(*wrapper,
973  statement_wrapper::bulk, position, dt_double, "double"))
974  {
975  return 0.0;
976  }
977 
978  std::vector<double> const & v = wrapper->into_doubles_v[position];
979  if (index_check_failed(v, *wrapper, index) ||
980  not_null_check_failed(*wrapper, position, index))
981  {
982  return 0.0;
983  }
984 
985  return v[index];
986 }
987 
988 SOCI_DECL char const * soci_get_into_date_v(statement_handle st, int position, int index)
989 {
990  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
991 
992  if (position_check_failed(*wrapper,
993  statement_wrapper::bulk, position, dt_date, "date"))
994  {
995  return "";
996  }
997 
998  std::vector<std::tm> const & v = wrapper->into_dates_v[position];
999  if (index_check_failed(v, *wrapper, index) ||
1000  not_null_check_failed(*wrapper, position, index))
1001  {
1002  return "";
1003  }
1004 
1005  return format_date(*wrapper, v[index]);
1006 }
1007 
1008 SOCI_DECL void soci_use_string(statement_handle st, char const * name)
1009 {
1010  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1011 
1012  if (cannot_add_elements(*wrapper, statement_wrapper::single, false) ||
1013  name_unique_check_failed(*wrapper, statement_wrapper::single, name))
1014  {
1015  return;
1016  }
1017 
1018  wrapper->statement_state = statement_wrapper::defining;
1019  wrapper->use_kind = statement_wrapper::single;
1020 
1021  wrapper->use_indicators[name] = i_ok; // create new entry
1022  wrapper->use_strings[name]; // create new entry
1023 }
1024 
1025 SOCI_DECL void soci_use_int(statement_handle st, char const * name)
1026 {
1027  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1028 
1029  if (cannot_add_elements(*wrapper, statement_wrapper::single, false) ||
1030  name_unique_check_failed(*wrapper, statement_wrapper::single, name))
1031  {
1032  return;
1033  }
1034 
1035  wrapper->statement_state = statement_wrapper::defining;
1036  wrapper->use_kind = statement_wrapper::single;
1037 
1038  wrapper->use_indicators[name] = i_ok; // create new entry
1039  wrapper->use_ints[name]; // create new entry
1040 }
1041 
1042 SOCI_DECL void soci_use_long_long(statement_handle st, char const * name)
1043 {
1044  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1045 
1046  if (cannot_add_elements(*wrapper, statement_wrapper::single, false) ||
1047  name_unique_check_failed(*wrapper, statement_wrapper::single, name))
1048  {
1049  return;
1050  }
1051 
1052  wrapper->statement_state = statement_wrapper::defining;
1053  wrapper->use_kind = statement_wrapper::single;
1054 
1055  wrapper->use_indicators[name] = i_ok; // create new entry
1056  wrapper->use_longlongs[name]; // create new entry
1057 }
1058 
1059 SOCI_DECL void soci_use_double(statement_handle st, char const * name)
1060 {
1061  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1062 
1063  if (cannot_add_elements(*wrapper, statement_wrapper::single, false) ||
1064  name_unique_check_failed(*wrapper, statement_wrapper::single, name))
1065  {
1066  return;
1067  }
1068 
1069  wrapper->statement_state = statement_wrapper::defining;
1070  wrapper->use_kind = statement_wrapper::single;
1071 
1072  wrapper->use_indicators[name] = i_ok; // create new entry
1073  wrapper->use_doubles[name]; // create new entry
1074 }
1075 
1076 SOCI_DECL void soci_use_date(statement_handle st, char const * name)
1077 {
1078  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1079 
1080  if (cannot_add_elements(*wrapper, statement_wrapper::single, false) ||
1081  name_unique_check_failed(*wrapper, statement_wrapper::single, name))
1082  {
1083  return;
1084  }
1085 
1086  wrapper->statement_state = statement_wrapper::defining;
1087  wrapper->use_kind = statement_wrapper::single;
1088 
1089  wrapper->use_indicators[name] = i_ok; // create new entry
1090  wrapper->use_dates[name]; // create new entry
1091 }
1092 
1093 SOCI_DECL void soci_use_string_v(statement_handle st, char const * name)
1094 {
1095  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1096 
1097  if (cannot_add_elements(*wrapper, statement_wrapper::bulk, false) ||
1098  name_unique_check_failed(*wrapper, statement_wrapper::bulk, name))
1099  {
1100  return;
1101  }
1102 
1103  wrapper->statement_state = statement_wrapper::defining;
1104  wrapper->use_kind = statement_wrapper::bulk;
1105 
1106  wrapper->use_indicators_v[name]; // create new entry
1107  wrapper->use_strings_v[name]; // create new entry
1108 }
1109 
1110 SOCI_DECL void soci_use_int_v(statement_handle st, char const * name)
1111 {
1112  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1113 
1114  if (cannot_add_elements(*wrapper, statement_wrapper::bulk, false) ||
1115  name_unique_check_failed(*wrapper, statement_wrapper::bulk, name))
1116  {
1117  return;
1118  }
1119 
1120  wrapper->statement_state = statement_wrapper::defining;
1121  wrapper->use_kind = statement_wrapper::bulk;
1122 
1123  wrapper->use_indicators_v[name]; // create new entry
1124  wrapper->use_ints_v[name]; // create new entry
1125 }
1126 
1128 {
1129  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1130 
1131  if (cannot_add_elements(*wrapper, statement_wrapper::bulk, false) ||
1132  name_unique_check_failed(*wrapper, statement_wrapper::bulk, name))
1133  {
1134  return;
1135  }
1136 
1137  wrapper->statement_state = statement_wrapper::defining;
1138  wrapper->use_kind = statement_wrapper::bulk;
1139 
1140  wrapper->use_indicators_v[name]; // create new entry
1141  wrapper->use_longlongs_v[name]; // create new entry
1142 }
1143 
1144 SOCI_DECL void soci_use_double_v(statement_handle st, char const * name)
1145 {
1146  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1147 
1148  if (cannot_add_elements(*wrapper, statement_wrapper::bulk, false) ||
1149  name_unique_check_failed(*wrapper, statement_wrapper::bulk, name))
1150  {
1151  return;
1152  }
1153 
1154  wrapper->statement_state = statement_wrapper::defining;
1155  wrapper->use_kind = statement_wrapper::bulk;
1156 
1157  wrapper->use_indicators_v[name]; // create new entry
1158  wrapper->use_doubles_v[name]; // create new entry
1159 }
1160 
1161 SOCI_DECL void soci_use_date_v(statement_handle st, char const * name)
1162 {
1163  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1164 
1165  if (cannot_add_elements(*wrapper, statement_wrapper::bulk, false) ||
1166  name_unique_check_failed(*wrapper, statement_wrapper::bulk, name))
1167  {
1168  return;
1169  }
1170 
1171  wrapper->statement_state = statement_wrapper::defining;
1172  wrapper->use_kind = statement_wrapper::bulk;
1173 
1174  wrapper->use_indicators_v[name]; // create new entry
1175  wrapper->use_dates_v[name]; // create new entry
1176 }
1177 
1178 SOCI_DECL void soci_set_use_state(statement_handle st, char const * name, int state)
1179 {
1180  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1181 
1182  typedef std::map<std::string, indicator>::const_iterator iterator;
1183  iterator const it = wrapper->use_indicators.find(name);
1184  if (it == wrapper->use_indicators.end())
1185  {
1186  wrapper->is_ok = false;
1187  wrapper->error_message = "Invalid name.";
1188  return;
1189  }
1190 
1191  wrapper->is_ok = true;
1192  wrapper->use_indicators[name] = (state != 0 ? i_ok : i_null);
1193 }
1194 
1195 SOCI_DECL void soci_set_use_string(statement_handle st, char const * name, char const * val)
1196 {
1197  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1198 
1199  if (name_exists_check_failed(*wrapper,
1200  name, dt_string, statement_wrapper::single, "string"))
1201  {
1202  return;
1203  }
1204 
1205  wrapper->use_indicators[name] = i_ok;
1206  wrapper->use_strings[name] = val;
1207 }
1208 
1209 SOCI_DECL void soci_set_use_int(statement_handle st, char const * name, int val)
1210 {
1211  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1212 
1213  if (name_exists_check_failed(*wrapper,
1214  name, dt_integer, statement_wrapper::single, "int"))
1215  {
1216  return;
1217  }
1218 
1219  wrapper->use_indicators[name] = i_ok;
1220  wrapper->use_ints[name] = val;
1221 }
1222 
1223 SOCI_DECL void soci_set_use_long_long(statement_handle st, char const * name, long long val)
1224 {
1225  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1226 
1227  if (name_exists_check_failed(*wrapper,
1228  name, dt_long_long, statement_wrapper::single, "long long"))
1229  {
1230  return;
1231  }
1232 
1233  wrapper->use_indicators[name] = i_ok;
1234  wrapper->use_longlongs[name] = val;
1235 }
1236 
1237 SOCI_DECL void soci_set_use_double(statement_handle st, char const * name, double val)
1238 {
1239  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1240 
1241  if (name_exists_check_failed(*wrapper,
1242  name, dt_double, statement_wrapper::single, "double"))
1243  {
1244  return;
1245  }
1246 
1247  wrapper->use_indicators[name] = i_ok;
1248  wrapper->use_doubles[name] = val;
1249 }
1250 
1251 SOCI_DECL void soci_set_use_date(statement_handle st, char const * name, char const * val)
1252 {
1253  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1254 
1255  if (name_exists_check_failed(*wrapper,
1256  name, dt_date, statement_wrapper::single, "date"))
1257  {
1258  return;
1259  }
1260 
1261  std::tm dt;
1262  bool const converted = string_to_date(val, dt, *wrapper);
1263  if (converted == false)
1264  {
1265  return;
1266  }
1267 
1268  wrapper->use_indicators[name] = i_ok;
1269  wrapper->use_dates[name] = dt;
1270 }
1271 
1273 {
1274  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1275 
1276  if (wrapper->use_kind != statement_wrapper::bulk)
1277  {
1278  wrapper->is_ok = false;
1279  wrapper->error_message = "No vector use elements.";
1280  return -1;
1281  }
1282 
1283  typedef std::map<std::string,
1284  std::vector<indicator> >::const_iterator iterator;
1285  iterator const any_element = wrapper->use_indicators_v.begin();
1286  assert(any_element != wrapper->use_indicators_v.end());
1287 
1288  return static_cast<int>(any_element->second.size());
1289 }
1290 
1292 {
1293  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1294 
1295  if (new_size <= 0)
1296  {
1297  wrapper->is_ok = false;
1298  wrapper->error_message = "Invalid size.";
1299  return;
1300  }
1301 
1302  if (wrapper->use_kind != statement_wrapper::bulk)
1303  {
1304  wrapper->is_ok = false;
1305  wrapper->error_message = "No vector use elements.";
1306  return;
1307  }
1308 
1309  resize_in_map(wrapper->use_indicators_v, new_size);
1310  resize_in_map(wrapper->use_strings_v, new_size);
1311  resize_in_map(wrapper->use_ints_v, new_size);
1312  resize_in_map(wrapper->use_longlongs_v, new_size);
1313  resize_in_map(wrapper->use_doubles_v, new_size);
1314  resize_in_map(wrapper->use_dates_v, new_size);
1315 
1316  wrapper->is_ok = true;
1317 }
1318 
1320  char const * name, int index, int state)
1321 {
1322  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1323 
1324  typedef std::map<std::string, std::vector<indicator> >::iterator iterator;
1325  iterator const it = wrapper->use_indicators_v.find(name);
1326  if (it == wrapper->use_indicators_v.end())
1327  {
1328  wrapper->is_ok = false;
1329  wrapper->error_message = "Invalid name.";
1330  return;
1331  }
1332 
1333  std::vector<indicator> & v = it->second;
1334  if (index_check_failed(v, *wrapper, index))
1335  {
1336  return;
1337  }
1338 
1339  v[index] = (state != 0 ? i_ok : i_null);
1340 }
1341 
1343  char const * name, int index, char const * val)
1344 {
1345  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1346 
1347  if (name_exists_check_failed(*wrapper,
1348  name, dt_string, statement_wrapper::bulk, "vector string"))
1349  {
1350  return;
1351  }
1352 
1353  std::vector<std::string> & v = wrapper->use_strings_v[name];
1354  if (index_check_failed(v, *wrapper, index))
1355  {
1356  return;
1357  }
1358 
1359  wrapper->use_indicators_v[name][index] = i_ok;
1360  v[index] = val;
1361 }
1362 
1364  char const * name, int index, int val)
1365 {
1366  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1367 
1368  if (name_exists_check_failed(*wrapper,
1369  name, dt_integer, statement_wrapper::bulk, "vector int"))
1370  {
1371  return;
1372  }
1373 
1374  std::vector<int> & v = wrapper->use_ints_v[name];
1375  if (index_check_failed(v, *wrapper, index))
1376  {
1377  return;
1378  }
1379 
1380  wrapper->use_indicators_v[name][index] = i_ok;
1381  v[index] = val;
1382 }
1383 
1385  char const * name, int index, long long val)
1386 {
1387  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1388 
1389  if (name_exists_check_failed(*wrapper,
1390  name, dt_long_long, statement_wrapper::bulk, "vector long long"))
1391  {
1392  return;
1393  }
1394 
1395  std::vector<long long> & v = wrapper->use_longlongs_v[name];
1396  if (index_check_failed(v, *wrapper, index))
1397  {
1398  return;
1399  }
1400 
1401  wrapper->use_indicators_v[name][index] = i_ok;
1402  v[index] = val;
1403 }
1404 
1406  char const * name, int index, double val)
1407 {
1408  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1409 
1410  if (name_exists_check_failed(*wrapper,
1411  name, dt_double, statement_wrapper::bulk, "vector double"))
1412  {
1413  return;
1414  }
1415 
1416  std::vector<double> & v = wrapper->use_doubles_v[name];
1417  if (index_check_failed(v, *wrapper, index))
1418  {
1419  return;
1420  }
1421 
1422  wrapper->use_indicators_v[name][index] = i_ok;
1423  v[index] = val;
1424 }
1425 
1427  char const * name, int index, char const * val)
1428 {
1429  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1430 
1431  if (name_exists_check_failed(*wrapper,
1432  name, dt_date, statement_wrapper::bulk, "vector date"))
1433  {
1434  return;
1435  }
1436 
1437  std::vector<std::tm> & v = wrapper->use_dates_v[name];
1438  if (index_check_failed(v, *wrapper, index))
1439  {
1440  return;
1441  }
1442 
1443  std::tm dt;
1444  bool const converted = string_to_date(val, dt, *wrapper);
1445  if (converted == false)
1446  {
1447  return;
1448  }
1449 
1450  wrapper->use_indicators_v[name][index] = i_ok;
1451  v[index] = dt;
1452 }
1453 
1455 {
1456  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1457 
1458  typedef std::map<std::string, indicator>::const_iterator iterator;
1459  iterator const it = wrapper->use_indicators.find(name);
1460  if (it == wrapper->use_indicators.end())
1461  {
1462  wrapper->is_ok = false;
1463  wrapper->error_message = "Invalid name.";
1464  return 0;
1465  }
1466 
1467  wrapper->is_ok = true;
1468  return wrapper->use_indicators[name] == i_ok ? 1 : 0;
1469 }
1470 
1471 SOCI_DECL char const * soci_get_use_string(statement_handle st, char const * name)
1472 {
1473  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1474 
1475  if (name_exists_check_failed(*wrapper,
1476  name, dt_string, statement_wrapper::bulk, "string"))
1477  {
1478  return "";
1479  }
1480 
1481  return wrapper->use_strings[name].c_str();
1482 }
1483 
1484 SOCI_DECL int soci_get_use_int(statement_handle st, char const * name)
1485 {
1486  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1487 
1488  if (name_exists_check_failed(*wrapper,
1489  name, dt_integer, statement_wrapper::bulk, "int"))
1490  {
1491  return 0;
1492  }
1493 
1494  return wrapper->use_ints[name];
1495 }
1496 
1497 SOCI_DECL long long soci_get_use_long_long(statement_handle st, char const * name)
1498 {
1499  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1500 
1501  if (name_exists_check_failed(*wrapper,
1502  name, dt_long_long, statement_wrapper::bulk, "long long"))
1503  {
1504  return 0LL;
1505  }
1506 
1507  return wrapper->use_longlongs[name];
1508 }
1509 
1510 SOCI_DECL double soci_get_use_double(statement_handle st, char const * name)
1511 {
1512  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1513 
1514  if (name_exists_check_failed(*wrapper,
1515  name, dt_double, statement_wrapper::bulk, "double"))
1516  {
1517  return 0.0;
1518  }
1519 
1520  return wrapper->use_doubles[name];
1521 }
1522 
1523 SOCI_DECL char const * soci_get_use_date(statement_handle st, char const * name)
1524 {
1525  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1526 
1527  if (name_exists_check_failed(*wrapper,
1528  name, dt_date, statement_wrapper::bulk, "date"))
1529  {
1530  return "";
1531  }
1532 
1533  // format is: "YYYY MM DD hh mm ss"
1534  std::tm const & d = wrapper->use_dates[name];
1535  std::sprintf(wrapper->date_formatted, "%d %d %d %d %d %d",
1536  d.tm_year + 1900, d.tm_mon + 1, d.tm_mday,
1537  d.tm_hour, d.tm_min, d.tm_sec);
1538 
1539  return wrapper->date_formatted;
1540 }
1541 
1542 SOCI_DECL void soci_prepare(statement_handle st, char const * query)
1543 {
1544  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1545 
1546  try
1547  {
1548  wrapper->statement_state = statement_wrapper::executing;
1549 
1550  // bind all into elements
1551 
1552  int const into_elements = static_cast<int>(wrapper->into_types.size());
1553  if (wrapper->into_kind == statement_wrapper::single)
1554  {
1555  for (int i = 0; i != into_elements; ++i)
1556  {
1557  switch (wrapper->into_types[i])
1558  {
1559  case dt_string:
1560  wrapper->st.exchange(
1561  into(wrapper->into_strings[i], wrapper->into_indicators[i]));
1562  break;
1563  case dt_integer:
1564  wrapper->st.exchange(
1565  into(wrapper->into_ints[i], wrapper->into_indicators[i]));
1566  break;
1567  case dt_long_long:
1568  wrapper->st.exchange(
1569  into(wrapper->into_longlongs[i], wrapper->into_indicators[i]));
1570  break;
1571  case dt_double:
1572  wrapper->st.exchange(
1573  into(wrapper->into_doubles[i], wrapper->into_indicators[i]));
1574  break;
1575  case dt_date:
1576  wrapper->st.exchange(
1577  into(wrapper->into_dates[i], wrapper->into_indicators[i]));
1578  break;
1579  default:
1580  assert(false);
1581  }
1582  }
1583  }
1584  else
1585  {
1586  // vector elements
1587  for (int i = 0; i != into_elements; ++i)
1588  {
1589  switch (wrapper->into_types[i])
1590  {
1591  case dt_string:
1592  wrapper->st.exchange(
1593  into(wrapper->into_strings_v[i], wrapper->into_indicators_v[i]));
1594  break;
1595  case dt_integer:
1596  wrapper->st.exchange(
1597  into(wrapper->into_ints_v[i], wrapper->into_indicators_v[i]));
1598  break;
1599  case dt_long_long:
1600  wrapper->st.exchange(
1601  into(wrapper->into_longlongs_v[i], wrapper->into_indicators_v[i]));
1602  break;
1603  case dt_double:
1604  wrapper->st.exchange(
1605  into(wrapper->into_doubles_v[i], wrapper->into_indicators_v[i]));
1606  break;
1607  case dt_date:
1608  wrapper->st.exchange(
1609  into(wrapper->into_dates_v[i], wrapper->into_indicators_v[i]));
1610  break;
1611  default:
1612  assert(false);
1613  }
1614  }
1615  }
1616 
1617  // bind all use elements
1618  {
1619  // strings
1620  typedef std::map<std::string, std::string>::iterator iterator;
1621  iterator uit = wrapper->use_strings.begin();
1622  iterator const uend = wrapper->use_strings.end();
1623  for ( ; uit != uend; ++uit)
1624  {
1625  std::string const & use_name = uit->first;
1626  std::string & use_string = uit->second;
1627  indicator & use_ind = wrapper->use_indicators[use_name];
1628  wrapper->st.exchange(use(use_string, use_ind, use_name));
1629  }
1630  }
1631  {
1632  // ints
1633  typedef std::map<std::string, int>::iterator iterator;
1634  iterator uit = wrapper->use_ints.begin();
1635  iterator const uend = wrapper->use_ints.end();
1636  for ( ; uit != uend; ++uit)
1637  {
1638  std::string const & use_name = uit->first;
1639  int & use_int = uit->second;
1640  indicator & use_ind = wrapper->use_indicators[use_name];
1641  wrapper->st.exchange(use(use_int, use_ind, use_name));
1642  }
1643  }
1644  {
1645  // longlongs
1646  typedef std::map<std::string, long long>::iterator iterator;
1647  iterator uit = wrapper->use_longlongs.begin();
1648  iterator const uend = wrapper->use_longlongs.end();
1649  for ( ; uit != uend; ++uit)
1650  {
1651  std::string const & use_name = uit->first;
1652  long long & use_longlong = uit->second;
1653  indicator & use_ind = wrapper->use_indicators[use_name];
1654  wrapper->st.exchange(use(use_longlong, use_ind, use_name));
1655  }
1656  }
1657  {
1658  // doubles
1659  typedef std::map<std::string, double>::iterator iterator;
1660  iterator uit = wrapper->use_doubles.begin();
1661  iterator const uend = wrapper->use_doubles.end();
1662  for ( ; uit != uend; ++uit)
1663  {
1664  std::string const & use_name = uit->first;
1665  double & use_double = uit->second;
1666  indicator & use_ind = wrapper->use_indicators[use_name];
1667  wrapper->st.exchange(use(use_double, use_ind, use_name));
1668  }
1669  }
1670  {
1671  // dates
1672  typedef std::map<std::string, std::tm>::iterator iterator;
1673  iterator uit = wrapper->use_dates.begin();
1674  iterator const uend = wrapper->use_dates.end();
1675  for ( ; uit != uend; ++uit)
1676  {
1677  std::string const & use_name = uit->first;
1678  std::tm & use_date = uit->second;
1679  indicator & use_ind = wrapper->use_indicators[use_name];
1680  wrapper->st.exchange(use(use_date, use_ind, use_name));
1681  }
1682  }
1683 
1684  // bind all use vecctor elements
1685  {
1686  // strings
1687  typedef std::map<std::string,
1688  std::vector<std::string> >::iterator iterator;
1689  iterator uit = wrapper->use_strings_v.begin();
1690  iterator const uend = wrapper->use_strings_v.end();
1691  for ( ; uit != uend; ++uit)
1692  {
1693  std::string const & use_name = uit->first;
1694  std::vector<std::string> & use_string = uit->second;
1695  std::vector<indicator> & use_ind =
1696  wrapper->use_indicators_v[use_name];
1697  wrapper->st.exchange(use(use_string, use_ind, use_name));
1698  }
1699  }
1700  {
1701  // ints
1702  typedef std::map<std::string,
1703  std::vector<int> >::iterator iterator;
1704  iterator uit = wrapper->use_ints_v.begin();
1705  iterator const uend = wrapper->use_ints_v.end();
1706  for ( ; uit != uend; ++uit)
1707  {
1708  std::string const & use_name = uit->first;
1709  std::vector<int> & use_int = uit->second;
1710  std::vector<indicator> & use_ind =
1711  wrapper->use_indicators_v[use_name];
1712  wrapper->st.exchange(use(use_int, use_ind, use_name));
1713  }
1714  }
1715  {
1716  // longlongs
1717  typedef std::map<std::string,
1718  std::vector<long long> >::iterator iterator;
1719  iterator uit = wrapper->use_longlongs_v.begin();
1720  iterator const uend = wrapper->use_longlongs_v.end();
1721  for ( ; uit != uend; ++uit)
1722  {
1723  std::string const & use_name = uit->first;
1724  std::vector<long long> & use_longlong = uit->second;
1725  std::vector<indicator> & use_ind =
1726  wrapper->use_indicators_v[use_name];
1727  wrapper->st.exchange(use(use_longlong, use_ind, use_name));
1728  }
1729  }
1730  {
1731  // doubles
1732  typedef std::map<std::string,
1733  std::vector<double> >::iterator iterator;
1734  iterator uit = wrapper->use_doubles_v.begin();
1735  iterator const uend = wrapper->use_doubles_v.end();
1736  for ( ; uit != uend; ++uit)
1737  {
1738  std::string const & use_name = uit->first;
1739  std::vector<double> & use_double = uit->second;
1740  std::vector<indicator> & use_ind =
1741  wrapper->use_indicators_v[use_name];
1742  wrapper->st.exchange(use(use_double, use_ind, use_name));
1743  }
1744  }
1745  {
1746  // dates
1747  typedef std::map<std::string,
1748  std::vector<std::tm> >::iterator iterator;
1749  iterator uit = wrapper->use_dates_v.begin();
1750  iterator const uend = wrapper->use_dates_v.end();
1751  for ( ; uit != uend; ++uit)
1752  {
1753  std::string const & use_name = uit->first;
1754  std::vector<std::tm> & use_date = uit->second;
1755  std::vector<indicator> & use_ind =
1756  wrapper->use_indicators_v[use_name];
1757  wrapper->st.exchange(use(use_date, use_ind, use_name));
1758  }
1759  }
1760 
1761  wrapper->st.alloc();
1762  wrapper->st.prepare(query);
1763  wrapper->st.define_and_bind();
1764 
1765  wrapper->is_ok = true;
1766  }
1767  catch (std::exception const & e)
1768  {
1769  wrapper->is_ok = false;
1770  wrapper->error_message = e.what();
1771  }
1772 }
1773 
1774 SOCI_DECL int soci_execute(statement_handle st, int withDataExchange)
1775 {
1776  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1777 
1778  try
1779  {
1780  bool const gotData = wrapper->st.execute(withDataExchange != 0);
1781 
1782  wrapper->is_ok = true;
1783 
1784  return gotData ? 1 : 0;
1785  }
1786  catch (std::exception const & e)
1787  {
1788  wrapper->is_ok = false;
1789  wrapper->error_message = e.what();
1790 
1791  return 0;
1792  }
1793 }
1794 
1796 {
1797  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1798 
1799  return wrapper->st.get_affected_rows();
1800 }
1801 
1803 {
1804  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1805 
1806  try
1807  {
1808  bool const gotData = wrapper->st.fetch();
1809 
1810  wrapper->is_ok = true;
1811 
1812  return gotData ? 1 : 0;
1813  }
1814  catch (std::exception const & e)
1815  {
1816  wrapper->is_ok = false;
1817  wrapper->error_message = e.what();
1818 
1819  return 0;
1820  }
1821 }
1822 
1824 {
1825  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1826 
1827  return wrapper->st.got_data() ? 1 : 0;
1828 }
1829 
1831 {
1832  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1833 
1834  return wrapper->is_ok ? 1 : 0;
1835 }
1836 
1838 {
1839  statement_wrapper * wrapper = static_cast<statement_wrapper *>(st);
1840 
1841  return wrapper->error_message.c_str();
1842 }
SOCI_DECL char const * soci_get_into_date(statement_handle st, int position)
SOCI_DECL int soci_get_into_state_v(statement_handle st, int position, int index)
SOCI_DECL void soci_into_resize_v(statement_handle st, int new_size)
SOCI_DECL int soci_into_double_v(statement_handle st)
SOCI_DECL int soci_execute(statement_handle st, int withDataExchange)
details::into_container< T, details::no_indicator > into(T &t)
Definition: into.h:51
SOCI_DECL double soci_get_into_double_v(statement_handle st, int position, int index)
SOCI_DECL int soci_use_get_size_v(statement_handle st)
SOCI_DECL void soci_set_use_date(statement_handle st, char const *name, char const *val)
SOCI_DECL void soci_use_resize_v(statement_handle st, int new_size)
SOCI_DECL session_handle soci_create_session(char const *connection_string)
Definition: soci-simple.cpp:37
SOCI_DECL void soci_set_use_double(statement_handle st, char const *name, double val)
SOCI_DECL int soci_into_long_long(statement_handle st)
SOCI_DECL int soci_into_string(statement_handle st)
SOCI_EMPTY_DECL empty_backend_factory const empty
SOCI_DECL void soci_use_long_long_v(statement_handle st, char const *name)
SOCI_DECL void soci_set_use_long_long_v(statement_handle st, char const *name, int index, long long val)
SOCI_DECL int soci_into_date_v(statement_handle st)
SOCI_DECL void soci_commit(session_handle s)
Definition: soci-simple.cpp:84
SOCI_DECL void soci_use_date_v(statement_handle st, char const *name)
SOCI_DECL char const * soci_get_use_date(statement_handle st, char const *name)
SOCI_DECL int soci_statement_state(statement_handle st)
SOCI_DECL void soci_use_int_v(statement_handle st, char const *name)
SOCI_DECL void soci_destroy_statement(statement_handle st)
SOCI_DECL long long soci_get_into_long_long(statement_handle st, int position)
SOCI_DECL int soci_get_use_int(statement_handle st, char const *name)
SOCI_DECL long long soci_get_use_long_long(statement_handle st, char const *name)
void * session_handle
Definition: soci-simple.h:20
SOCI_DECL int soci_get_into_int(statement_handle st, int position)
SOCI_DECL void soci_use_double_v(statement_handle st, char const *name)
SOCI_DECL void soci_set_use_state(statement_handle st, char const *name, int state)
SOCI_DECL char const * soci_get_use_string(statement_handle st, char const *name)
SOCI_DECL char const * soci_get_into_date_v(statement_handle st, int position, int index)
#define SOCI_DECL
Definition: soci-config.h:31
SOCI_DECL void soci_set_use_state_v(statement_handle st, char const *name, int index, int state)
SOCI_DECL int soci_got_data(statement_handle st)
SOCI_DECL int soci_session_state(session_handle s)
SOCI_DECL void soci_set_use_string_v(statement_handle st, char const *name, int index, char const *val)
SOCI_DECL int soci_get_into_int_v(statement_handle st, int position, int index)
SOCI_DECL long long soci_get_affected_rows(statement_handle st)
SOCI_DECL char const * soci_get_into_string_v(statement_handle st, int position, int index)
SOCI_DECL int soci_fetch(statement_handle st)
SOCI_DECL void soci_use_int(statement_handle st, char const *name)
SOCI_DECL double soci_get_into_double(statement_handle st, int position)
SOCI_DECL int soci_get_into_state(statement_handle st, int position)
SOCI_DECL void soci_set_use_string(statement_handle st, char const *name, char const *val)
SOCI_DECL char const * soci_session_error_message(session_handle s)
SOCI_DECL int soci_into_long_long_v(statement_handle st)
SOCI_DECL void soci_set_use_int_v(statement_handle st, char const *name, int index, int val)
SOCI_DECL void soci_use_double(statement_handle st, char const *name)
SOCI_DECL double soci_get_use_double(statement_handle st, char const *name)
SOCI_DECL int soci_into_get_size_v(statement_handle st)
SOCI_DECL char const * soci_get_into_string(statement_handle st, int position)
SOCI_DECL int soci_get_use_state(statement_handle st, char const *name)
void * statement_handle
Definition: soci-simple.h:33
SOCI_DECL int soci_into_date(statement_handle st)
SOCI_DECL void soci_use_string(statement_handle st, char const *name)
SOCI_DECL void soci_begin(session_handle s)
Definition: soci-simple.cpp:69
SOCI_DECL void soci_set_use_double_v(statement_handle st, char const *name, int index, double val)
SOCI_DECL long long soci_get_into_long_long_v(statement_handle st, int position, int index)
SOCI_DECL void soci_use_string_v(statement_handle st, char const *name)
SOCI_DECL void soci_set_use_int(statement_handle st, char const *name, int val)
SOCI_DECL char const * soci_statement_error_message(statement_handle st)
SOCI_DECL void soci_use_date(statement_handle st, char const *name)
SOCI_DECL int soci_into_double(statement_handle st)
SOCI_DECL void soci_use_long_long(statement_handle st, char const *name)
SOCI_DECL int soci_into_int(statement_handle st)
SOCI_DECL void soci_prepare(statement_handle st, char const *query)
SOCI_DECL int soci_into_string_v(statement_handle st)
details::use_container< T, details::no_indicator > use(T &t, const std::string &name=std::string())
Definition: use.h:43
SOCI_DECL int soci_into_int_v(statement_handle st)
SOCI_DECL void soci_rollback(session_handle s)
Definition: soci-simple.cpp:99
SOCI_DECL void soci_destroy_session(session_handle s)
Definition: soci-simple.cpp:63
SOCI_DECL statement_handle soci_create_statement(session_handle s)
SOCI_DECL void soci_set_use_date_v(statement_handle st, char const *name, int index, char const *val)
SOCI_DECL void soci_set_use_long_long(statement_handle st, char const *name, long long val)


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:41