26 struct session_wrapper
31 std::string error_message;
39 session_wrapper * wrapper = NULL;
42 wrapper =
new session_wrapper();
51 wrapper->sql.open(connection_string);
52 wrapper->is_ok =
true;
54 catch (std::exception
const & e)
56 wrapper->is_ok =
false;
57 wrapper->error_message = e.what();
65 session_wrapper * wrapper =
static_cast<session_wrapper *
>(s);
71 session_wrapper * wrapper =
static_cast<session_wrapper *
>(s);
75 wrapper->is_ok =
true;
77 catch (std::exception
const & e)
79 wrapper->is_ok =
false;
80 wrapper->error_message = e.what();
86 session_wrapper * wrapper =
static_cast<session_wrapper *
>(s);
89 wrapper->sql.commit();
90 wrapper->is_ok =
true;
92 catch (std::exception
const & e)
94 wrapper->is_ok =
false;
95 wrapper->error_message = e.what();
101 session_wrapper * wrapper =
static_cast<session_wrapper *
>(s);
104 wrapper->sql.rollback();
105 wrapper->is_ok =
true;
107 catch (std::exception
const & e)
109 wrapper->is_ok =
false;
110 wrapper->error_message = e.what();
124 session_wrapper * wrapper =
static_cast<session_wrapper *
>(s);
126 return wrapper->is_ok ? 1 : 0;
131 session_wrapper * wrapper =
static_cast<session_wrapper *
>(s);
133 return wrapper->error_message.c_str();
143 struct statement_wrapper
145 statement_wrapper(
session & sql)
146 : st(sql), statement_state(clean), into_kind(
empty), use_kind(
empty),
147 next_position(0), is_ok(
true) {}
151 enum state { clean, defining, executing } statement_state;
152 enum kind {
empty, single, bulk } into_kind, use_kind;
156 std::vector<data_type> into_types;
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;
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;
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;
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;
187 char date_formatted[20];
190 std::string error_message;
195 bool cannot_add_elements(statement_wrapper & wrapper, statement_wrapper::kind k,
bool into)
197 if (wrapper.statement_state == statement_wrapper::executing)
199 wrapper.is_ok =
false;
200 wrapper.error_message =
"Cannot add more data items.";
206 if (k == statement_wrapper::single && wrapper.into_kind == statement_wrapper::bulk)
208 wrapper.is_ok =
false;
209 wrapper.error_message =
"Cannot add single into data items.";
212 if (k == statement_wrapper::bulk && wrapper.into_kind == statement_wrapper::single)
214 wrapper.is_ok =
false;
215 wrapper.error_message =
"Cannot add vector into data items.";
222 if (k == statement_wrapper::single && wrapper.use_kind == statement_wrapper::bulk)
224 wrapper.is_ok =
false;
225 wrapper.error_message =
"Cannot add single use data items.";
228 if (k == statement_wrapper::bulk && wrapper.use_kind == statement_wrapper::single)
230 wrapper.is_ok =
false;
231 wrapper.error_message =
"Cannot add vector use data items.";
236 wrapper.is_ok =
true;
241 bool position_check_failed(statement_wrapper & wrapper, statement_wrapper::kind k,
242 int position,
data_type expected_type,
char const * type_name)
244 if (position < 0 || position >= wrapper.next_position)
246 wrapper.is_ok =
false;
247 wrapper.error_message =
"Invalid position.";
251 if (wrapper.into_types[position] != expected_type)
253 wrapper.is_ok =
false;
254 wrapper.error_message =
"No into ";
255 if (k == statement_wrapper::bulk)
257 wrapper.error_message +=
"vector ";
259 wrapper.error_message += type_name;
260 wrapper.error_message +=
" element at this position.";
264 wrapper.is_ok =
true;
270 bool not_null_check_failed(statement_wrapper & wrapper,
int position)
272 if (wrapper.into_indicators[position] ==
i_null)
274 wrapper.is_ok =
false;
275 wrapper.error_message =
"Element is null.";
279 wrapper.is_ok =
true;
284 bool not_null_check_failed(statement_wrapper & wrapper,
int position,
int index)
286 if (wrapper.into_indicators_v[position][index] ==
i_null)
288 wrapper.is_ok =
false;
289 wrapper.error_message =
"Element is null.";
293 wrapper.is_ok =
true;
298 template <
typename T>
299 bool index_check_failed(std::vector<T>
const & v,
300 statement_wrapper & wrapper,
int index)
302 if (index < 0 || index >= static_cast<int>(v.size()))
304 wrapper.is_ok =
false;
305 wrapper.error_message =
"Invalid index.";
309 wrapper.is_ok =
true;
314 bool name_unique_check_failed(statement_wrapper & wrapper,
315 statement_wrapper::kind k,
char const * name)
318 if (k == statement_wrapper::single)
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();
331 std::vector<indicator>
332 >::const_iterator iterator;
334 iterator
const it = wrapper.use_indicators_v.find(name);
335 is_unique = it == wrapper.use_indicators_v.end();
340 wrapper.is_ok =
true;
345 wrapper.is_ok =
false;
346 wrapper.error_message =
"Name of use element should be unique.";
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)
356 bool name_exists =
false;
357 if (k == statement_wrapper::single)
359 switch (expected_type)
367 >::const_iterator iterator;
368 iterator
const it = wrapper.use_strings.find(name);
369 name_exists = (it != wrapper.use_strings.end());
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());
381 typedef std::map<std::string, long long>::const_iterator
383 iterator
const it = wrapper.use_longlongs.find(name);
384 name_exists = (it != wrapper.use_longlongs.end());
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());
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());
409 switch (expected_type)
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());
428 >::const_iterator iterator;
429 iterator
const it = wrapper.use_ints_v.find(name);
430 name_exists = (it != wrapper.use_ints_v.end());
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());
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());
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());
467 wrapper.is_ok =
true;
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.";
481 template <
typename T>
482 void resize_in_map(std::map<std::string, std::vector<T> > & m,
int new_size)
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)
489 std::vector<T> & v = it->second;
495 char const * format_date(statement_wrapper & wrapper, std::tm
const & d)
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);
501 return wrapper.date_formatted;
504 bool string_to_date(
char const * val, std::tm & dt,
505 statement_wrapper & wrapper)
514 int const converted = std::sscanf(val,
"%d %d %d %d %d %d",
515 &year, &month, &day, &hour, &minute, &second);
518 wrapper.is_ok =
false;
519 wrapper.error_message =
"Cannot convert date.";
523 wrapper.is_ok =
true;
525 dt.tm_year = year - 1900;
526 dt.tm_mon = month - 1;
540 session_wrapper * session_w =
static_cast<session_wrapper *
>(s);
543 statement_wrapper * statement_w =
new statement_wrapper(session_w->sql);
546 catch (std::exception
const & e)
548 session_w->is_ok =
false;
549 session_w->error_message = e.what();
556 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
562 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
564 if (cannot_add_elements(*wrapper, statement_wrapper::single,
true))
569 wrapper->statement_state = statement_wrapper::defining;
570 wrapper->into_kind = statement_wrapper::single;
572 wrapper->into_types.push_back(
dt_string);
573 wrapper->into_indicators.push_back(
i_ok);
574 wrapper->into_strings[wrapper->next_position];
575 return wrapper->next_position++;
580 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
582 if (cannot_add_elements(*wrapper, statement_wrapper::single,
true))
587 wrapper->statement_state = statement_wrapper::defining;
588 wrapper->into_kind = statement_wrapper::single;
591 wrapper->into_indicators.push_back(
i_ok);
592 wrapper->into_ints[wrapper->next_position];
593 return wrapper->next_position++;
598 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
600 if (cannot_add_elements(*wrapper, statement_wrapper::single,
true))
605 wrapper->statement_state = statement_wrapper::defining;
606 wrapper->into_kind = statement_wrapper::single;
609 wrapper->into_indicators.push_back(
i_ok);
610 wrapper->into_longlongs[wrapper->next_position];
611 return wrapper->next_position++;
616 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
618 if (cannot_add_elements(*wrapper, statement_wrapper::single,
true))
623 wrapper->statement_state = statement_wrapper::defining;
624 wrapper->into_kind = statement_wrapper::single;
626 wrapper->into_types.push_back(
dt_double);
627 wrapper->into_indicators.push_back(
i_ok);
628 wrapper->into_doubles[wrapper->next_position];
629 return wrapper->next_position++;
634 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
636 if (cannot_add_elements(*wrapper, statement_wrapper::single,
true))
641 wrapper->statement_state = statement_wrapper::defining;
642 wrapper->into_kind = statement_wrapper::single;
644 wrapper->into_types.push_back(
dt_date);
645 wrapper->into_indicators.push_back(
i_ok);
646 wrapper->into_dates[wrapper->next_position];
647 return wrapper->next_position++;
652 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
654 if (cannot_add_elements(*wrapper, statement_wrapper::bulk,
true))
659 wrapper->statement_state = statement_wrapper::defining;
660 wrapper->into_kind = statement_wrapper::bulk;
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++;
670 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
672 if (cannot_add_elements(*wrapper, statement_wrapper::bulk,
true))
677 wrapper->statement_state = statement_wrapper::defining;
678 wrapper->into_kind = statement_wrapper::bulk;
681 wrapper->into_indicators_v.push_back(std::vector<indicator>());
682 wrapper->into_ints_v[wrapper->next_position];
683 return wrapper->next_position++;
688 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
690 if (cannot_add_elements(*wrapper, statement_wrapper::bulk,
true))
695 wrapper->statement_state = statement_wrapper::defining;
696 wrapper->into_kind = statement_wrapper::bulk;
699 wrapper->into_indicators_v.push_back(std::vector<indicator>());
700 wrapper->into_longlongs_v[wrapper->next_position];
701 return wrapper->next_position++;
706 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
708 if (cannot_add_elements(*wrapper, statement_wrapper::bulk,
true))
713 wrapper->statement_state = statement_wrapper::defining;
714 wrapper->into_kind = statement_wrapper::bulk;
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++;
724 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
726 if (cannot_add_elements(*wrapper, statement_wrapper::bulk,
true))
731 wrapper->statement_state = statement_wrapper::defining;
732 wrapper->into_kind = statement_wrapper::bulk;
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++;
742 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
744 if (position < 0 || position >= wrapper->next_position)
746 wrapper->is_ok =
false;
747 wrapper->error_message =
"Invalid position.";
751 wrapper->is_ok =
true;
752 return wrapper->into_indicators[position] ==
i_ok ? 1 : 0;
757 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
759 if (position_check_failed(*wrapper,
760 statement_wrapper::single, position,
dt_string,
"string") ||
761 not_null_check_failed(*wrapper, position))
766 return wrapper->into_strings[position].c_str();
771 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
773 if (position_check_failed(*wrapper,
774 statement_wrapper::single, position,
dt_integer,
"int") ||
775 not_null_check_failed(*wrapper, position))
780 return wrapper->into_ints[position];
785 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
787 if (position_check_failed(*wrapper,
788 statement_wrapper::single, position,
dt_long_long,
"long long") ||
789 not_null_check_failed(*wrapper, position))
794 return wrapper->into_longlongs[position];
799 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
801 if (position_check_failed(*wrapper,
802 statement_wrapper::single, position,
dt_double,
"double") ||
803 not_null_check_failed(*wrapper, position))
808 return wrapper->into_doubles[position];
813 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
815 if (position_check_failed(*wrapper,
816 statement_wrapper::single, position,
dt_date,
"date") ||
817 not_null_check_failed(*wrapper, position))
823 std::tm
const & d = wrapper->into_dates[position];
824 return format_date(*wrapper, d);
829 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
831 if (wrapper->into_kind != statement_wrapper::bulk)
833 wrapper->is_ok =
false;
834 wrapper->error_message =
"No vector into elements.";
838 return static_cast<int>(wrapper->into_indicators_v[0].size());
843 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
847 wrapper->is_ok =
false;
848 wrapper->error_message =
"Invalid size.";
852 if (wrapper->into_kind != statement_wrapper::bulk)
854 wrapper->is_ok =
false;
855 wrapper->error_message =
"No vector into elements.";
859 for (
int i = 0; i != wrapper->next_position; ++i)
861 wrapper->into_indicators_v[i].resize(new_size);
863 switch (wrapper->into_types[i])
866 wrapper->into_strings_v[i].resize(new_size);
869 wrapper->into_ints_v[i].resize(new_size);
872 wrapper->into_longlongs_v[i].resize(new_size);
875 wrapper->into_doubles_v[i].resize(new_size);
878 wrapper->into_dates_v[i].resize(new_size);
885 wrapper->is_ok =
true;
890 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
892 if (position < 0 || position >= wrapper->next_position)
894 wrapper->is_ok =
false;
895 wrapper->error_message =
"Invalid position.";
899 std::vector<indicator>
const & v = wrapper->into_indicators_v[position];
900 if (index_check_failed(v, *wrapper, index))
905 return v[index] ==
i_ok ? 1 : 0;
910 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
912 if (position_check_failed(*wrapper,
913 statement_wrapper::bulk, position,
dt_string,
"string"))
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))
925 return v[index].c_str();
930 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
932 if (position_check_failed(*wrapper,
933 statement_wrapper::bulk, position,
dt_integer,
"int"))
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))
950 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
952 if (position_check_failed(*wrapper,
953 statement_wrapper::bulk, position,
dt_long_long,
"long long"))
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))
970 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
972 if (position_check_failed(*wrapper,
973 statement_wrapper::bulk, position,
dt_double,
"double"))
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))
990 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
992 if (position_check_failed(*wrapper,
993 statement_wrapper::bulk, position,
dt_date,
"date"))
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))
1005 return format_date(*wrapper, v[index]);
1010 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1012 if (cannot_add_elements(*wrapper, statement_wrapper::single,
false) ||
1013 name_unique_check_failed(*wrapper, statement_wrapper::single, name))
1018 wrapper->statement_state = statement_wrapper::defining;
1019 wrapper->use_kind = statement_wrapper::single;
1021 wrapper->use_indicators[name] =
i_ok;
1022 wrapper->use_strings[name];
1027 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1029 if (cannot_add_elements(*wrapper, statement_wrapper::single,
false) ||
1030 name_unique_check_failed(*wrapper, statement_wrapper::single, name))
1035 wrapper->statement_state = statement_wrapper::defining;
1036 wrapper->use_kind = statement_wrapper::single;
1038 wrapper->use_indicators[name] =
i_ok;
1039 wrapper->use_ints[name];
1044 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1046 if (cannot_add_elements(*wrapper, statement_wrapper::single,
false) ||
1047 name_unique_check_failed(*wrapper, statement_wrapper::single, name))
1052 wrapper->statement_state = statement_wrapper::defining;
1053 wrapper->use_kind = statement_wrapper::single;
1055 wrapper->use_indicators[name] =
i_ok;
1056 wrapper->use_longlongs[name];
1061 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1063 if (cannot_add_elements(*wrapper, statement_wrapper::single,
false) ||
1064 name_unique_check_failed(*wrapper, statement_wrapper::single, name))
1069 wrapper->statement_state = statement_wrapper::defining;
1070 wrapper->use_kind = statement_wrapper::single;
1072 wrapper->use_indicators[name] =
i_ok;
1073 wrapper->use_doubles[name];
1078 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1080 if (cannot_add_elements(*wrapper, statement_wrapper::single,
false) ||
1081 name_unique_check_failed(*wrapper, statement_wrapper::single, name))
1086 wrapper->statement_state = statement_wrapper::defining;
1087 wrapper->use_kind = statement_wrapper::single;
1089 wrapper->use_indicators[name] =
i_ok;
1090 wrapper->use_dates[name];
1095 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1097 if (cannot_add_elements(*wrapper, statement_wrapper::bulk,
false) ||
1098 name_unique_check_failed(*wrapper, statement_wrapper::bulk, name))
1103 wrapper->statement_state = statement_wrapper::defining;
1104 wrapper->use_kind = statement_wrapper::bulk;
1106 wrapper->use_indicators_v[name];
1107 wrapper->use_strings_v[name];
1112 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1114 if (cannot_add_elements(*wrapper, statement_wrapper::bulk,
false) ||
1115 name_unique_check_failed(*wrapper, statement_wrapper::bulk, name))
1120 wrapper->statement_state = statement_wrapper::defining;
1121 wrapper->use_kind = statement_wrapper::bulk;
1123 wrapper->use_indicators_v[name];
1124 wrapper->use_ints_v[name];
1129 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1131 if (cannot_add_elements(*wrapper, statement_wrapper::bulk,
false) ||
1132 name_unique_check_failed(*wrapper, statement_wrapper::bulk, name))
1137 wrapper->statement_state = statement_wrapper::defining;
1138 wrapper->use_kind = statement_wrapper::bulk;
1140 wrapper->use_indicators_v[name];
1141 wrapper->use_longlongs_v[name];
1146 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1148 if (cannot_add_elements(*wrapper, statement_wrapper::bulk,
false) ||
1149 name_unique_check_failed(*wrapper, statement_wrapper::bulk, name))
1154 wrapper->statement_state = statement_wrapper::defining;
1155 wrapper->use_kind = statement_wrapper::bulk;
1157 wrapper->use_indicators_v[name];
1158 wrapper->use_doubles_v[name];
1163 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1165 if (cannot_add_elements(*wrapper, statement_wrapper::bulk,
false) ||
1166 name_unique_check_failed(*wrapper, statement_wrapper::bulk, name))
1171 wrapper->statement_state = statement_wrapper::defining;
1172 wrapper->use_kind = statement_wrapper::bulk;
1174 wrapper->use_indicators_v[name];
1175 wrapper->use_dates_v[name];
1180 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
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())
1186 wrapper->is_ok =
false;
1187 wrapper->error_message =
"Invalid name.";
1191 wrapper->is_ok =
true;
1192 wrapper->use_indicators[name] = (state != 0 ?
i_ok :
i_null);
1197 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1199 if (name_exists_check_failed(*wrapper,
1200 name,
dt_string, statement_wrapper::single,
"string"))
1205 wrapper->use_indicators[name] =
i_ok;
1206 wrapper->use_strings[name] = val;
1211 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1213 if (name_exists_check_failed(*wrapper,
1214 name,
dt_integer, statement_wrapper::single,
"int"))
1219 wrapper->use_indicators[name] =
i_ok;
1220 wrapper->use_ints[name] = val;
1225 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1227 if (name_exists_check_failed(*wrapper,
1228 name,
dt_long_long, statement_wrapper::single,
"long long"))
1233 wrapper->use_indicators[name] =
i_ok;
1234 wrapper->use_longlongs[name] = val;
1239 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1241 if (name_exists_check_failed(*wrapper,
1242 name,
dt_double, statement_wrapper::single,
"double"))
1247 wrapper->use_indicators[name] =
i_ok;
1248 wrapper->use_doubles[name] = val;
1253 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1255 if (name_exists_check_failed(*wrapper,
1256 name,
dt_date, statement_wrapper::single,
"date"))
1262 bool const converted = string_to_date(val, dt, *wrapper);
1263 if (converted ==
false)
1268 wrapper->use_indicators[name] =
i_ok;
1269 wrapper->use_dates[name] = dt;
1274 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1276 if (wrapper->use_kind != statement_wrapper::bulk)
1278 wrapper->is_ok =
false;
1279 wrapper->error_message =
"No vector use elements.";
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());
1288 return static_cast<int>(any_element->second.size());
1293 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1297 wrapper->is_ok =
false;
1298 wrapper->error_message =
"Invalid size.";
1302 if (wrapper->use_kind != statement_wrapper::bulk)
1304 wrapper->is_ok =
false;
1305 wrapper->error_message =
"No vector use elements.";
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);
1316 wrapper->is_ok =
true;
1320 char const * name,
int index,
int state)
1322 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
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())
1328 wrapper->is_ok =
false;
1329 wrapper->error_message =
"Invalid name.";
1333 std::vector<indicator> & v = it->second;
1334 if (index_check_failed(v, *wrapper, index))
1343 char const * name,
int index,
char const * val)
1345 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1347 if (name_exists_check_failed(*wrapper,
1348 name,
dt_string, statement_wrapper::bulk,
"vector string"))
1353 std::vector<std::string> & v = wrapper->use_strings_v[name];
1354 if (index_check_failed(v, *wrapper, index))
1359 wrapper->use_indicators_v[name][index] =
i_ok;
1364 char const * name,
int index,
int val)
1366 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1368 if (name_exists_check_failed(*wrapper,
1369 name,
dt_integer, statement_wrapper::bulk,
"vector int"))
1374 std::vector<int> & v = wrapper->use_ints_v[name];
1375 if (index_check_failed(v, *wrapper, index))
1380 wrapper->use_indicators_v[name][index] =
i_ok;
1385 char const * name,
int index,
long long val)
1387 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1389 if (name_exists_check_failed(*wrapper,
1390 name,
dt_long_long, statement_wrapper::bulk,
"vector long long"))
1395 std::vector<long long> & v = wrapper->use_longlongs_v[name];
1396 if (index_check_failed(v, *wrapper, index))
1401 wrapper->use_indicators_v[name][index] =
i_ok;
1406 char const * name,
int index,
double val)
1408 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1410 if (name_exists_check_failed(*wrapper,
1411 name,
dt_double, statement_wrapper::bulk,
"vector double"))
1416 std::vector<double> & v = wrapper->use_doubles_v[name];
1417 if (index_check_failed(v, *wrapper, index))
1422 wrapper->use_indicators_v[name][index] =
i_ok;
1427 char const * name,
int index,
char const * val)
1429 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1431 if (name_exists_check_failed(*wrapper,
1432 name,
dt_date, statement_wrapper::bulk,
"vector date"))
1437 std::vector<std::tm> & v = wrapper->use_dates_v[name];
1438 if (index_check_failed(v, *wrapper, index))
1444 bool const converted = string_to_date(val, dt, *wrapper);
1445 if (converted ==
false)
1450 wrapper->use_indicators_v[name][index] =
i_ok;
1456 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
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())
1462 wrapper->is_ok =
false;
1463 wrapper->error_message =
"Invalid name.";
1467 wrapper->is_ok =
true;
1468 return wrapper->use_indicators[name] ==
i_ok ? 1 : 0;
1473 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1475 if (name_exists_check_failed(*wrapper,
1476 name,
dt_string, statement_wrapper::bulk,
"string"))
1481 return wrapper->use_strings[name].c_str();
1486 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1488 if (name_exists_check_failed(*wrapper,
1489 name,
dt_integer, statement_wrapper::bulk,
"int"))
1494 return wrapper->use_ints[name];
1499 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1501 if (name_exists_check_failed(*wrapper,
1502 name,
dt_long_long, statement_wrapper::bulk,
"long long"))
1507 return wrapper->use_longlongs[name];
1512 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1514 if (name_exists_check_failed(*wrapper,
1515 name,
dt_double, statement_wrapper::bulk,
"double"))
1520 return wrapper->use_doubles[name];
1525 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1527 if (name_exists_check_failed(*wrapper,
1528 name,
dt_date, statement_wrapper::bulk,
"date"))
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);
1539 return wrapper->date_formatted;
1544 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1548 wrapper->statement_state = statement_wrapper::executing;
1552 int const into_elements =
static_cast<int>(wrapper->into_types.size());
1553 if (wrapper->into_kind == statement_wrapper::single)
1555 for (
int i = 0; i != into_elements; ++i)
1557 switch (wrapper->into_types[i])
1560 wrapper->st.exchange(
1561 into(wrapper->into_strings[i], wrapper->into_indicators[i]));
1564 wrapper->st.exchange(
1565 into(wrapper->into_ints[i], wrapper->into_indicators[i]));
1568 wrapper->st.exchange(
1569 into(wrapper->into_longlongs[i], wrapper->into_indicators[i]));
1572 wrapper->st.exchange(
1573 into(wrapper->into_doubles[i], wrapper->into_indicators[i]));
1576 wrapper->st.exchange(
1577 into(wrapper->into_dates[i], wrapper->into_indicators[i]));
1587 for (
int i = 0; i != into_elements; ++i)
1589 switch (wrapper->into_types[i])
1592 wrapper->st.exchange(
1593 into(wrapper->into_strings_v[i], wrapper->into_indicators_v[i]));
1596 wrapper->st.exchange(
1597 into(wrapper->into_ints_v[i], wrapper->into_indicators_v[i]));
1600 wrapper->st.exchange(
1601 into(wrapper->into_longlongs_v[i], wrapper->into_indicators_v[i]));
1604 wrapper->st.exchange(
1605 into(wrapper->into_doubles_v[i], wrapper->into_indicators_v[i]));
1608 wrapper->st.exchange(
1609 into(wrapper->into_dates_v[i], wrapper->into_indicators_v[i]));
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)
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));
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)
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));
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)
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));
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)
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));
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)
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));
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)
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));
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)
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));
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)
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));
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)
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));
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)
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));
1761 wrapper->st.alloc();
1762 wrapper->st.prepare(query);
1763 wrapper->st.define_and_bind();
1765 wrapper->is_ok =
true;
1767 catch (std::exception
const & e)
1769 wrapper->is_ok =
false;
1770 wrapper->error_message = e.what();
1776 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1780 bool const gotData = wrapper->st.execute(withDataExchange != 0);
1782 wrapper->is_ok =
true;
1784 return gotData ? 1 : 0;
1786 catch (std::exception
const & e)
1788 wrapper->is_ok =
false;
1789 wrapper->error_message = e.what();
1797 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1799 return wrapper->st.get_affected_rows();
1804 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1808 bool const gotData = wrapper->st.fetch();
1810 wrapper->is_ok =
true;
1812 return gotData ? 1 : 0;
1814 catch (std::exception
const & e)
1816 wrapper->is_ok =
false;
1817 wrapper->error_message = e.what();
1825 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1827 return wrapper->st.got_data() ? 1 : 0;
1832 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1834 return wrapper->is_ok ? 1 : 0;
1839 statement_wrapper * wrapper =
static_cast<statement_wrapper *
>(st);
1841 return wrapper->error_message.c_str();
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)
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)
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)
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)
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)
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)
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)
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())
SOCI_DECL int soci_into_int_v(statement_handle st)
SOCI_DECL void soci_rollback(session_handle s)
SOCI_DECL void soci_destroy_session(session_handle s)
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)