mysql/standard-into-type.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton
3 // MySQL backend copyright (C) 2006 Pawel Aleksander Fedorynski
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 
9 #define SOCI_MYSQL_SOURCE
10 #include "soci-mysql.h"
11 #include <soci-platform.h>
12 #include "common.h"
13 // std
14 #include <cassert>
15 #include <ciso646>
16 #include <cstdlib>
17 #include <cstring>
18 #include <ctime>
19 #include <string>
20 
21 #ifdef _MSC_VER
22 #pragma warning(disable:4355)
23 #endif
24 
25 using namespace soci;
26 using namespace soci::details;
27 using namespace soci::details::mysql;
28 
29 
31  int &position, void *data, exchange_type type)
32 {
33  data_ = data;
34  type_ = type;
35  position_ = position++;
36 }
37 
39 {
40  // nothing to do here
41 }
42 
44  bool gotData, bool calledFromFetch, indicator *ind)
45 {
46  if (calledFromFetch == true && gotData == false)
47  {
48  // this is a normal end-of-rowset condition,
49  // no need to do anything (fetch() will return false)
50  return;
51  }
52 
53  if (gotData)
54  {
55  int pos = position_ - 1;
56  //mysql_data_seek(statement_.result_, statement_.currentRow_);
57  mysql_row_seek(statement_.result_,
58  statement_.resultRowOffsets_[statement_.currentRow_]);
59  MYSQL_ROW row = mysql_fetch_row(statement_.result_);
60  if (row[pos] == NULL)
61  {
62  if (ind == NULL)
63  {
64  throw soci_error(
65  "Null value fetched and no indicator defined.");
66  }
67  *ind = i_null;
68  return;
69  }
70  else
71  {
72  if (ind != NULL)
73  {
74  *ind = i_ok;
75  }
76  }
77  const char *buf = row[pos] != NULL ? row[pos] : "";
78  switch (type_)
79  {
80  case x_char:
81  {
82  char *dest = static_cast<char*>(data_);
83  *dest = *buf;
84  }
85  break;
86  case x_stdstring:
87  {
88  std::string *dest = static_cast<std::string *>(data_);
89  unsigned long * lengths =
90  mysql_fetch_lengths(statement_.result_);
91  dest->assign(buf, lengths[pos]);
92  }
93  break;
94  case x_short:
95  {
96  short *dest = static_cast<short*>(data_);
97  parse_num(buf, *dest);
98  }
99  break;
100  case x_integer:
101  {
102  int *dest = static_cast<int*>(data_);
103  parse_num(buf, *dest);
104  }
105  break;
106  case x_long_long:
107  {
108  long long *dest = static_cast<long long *>(data_);
109  parse_num(buf, *dest);
110  }
111  break;
113  {
114  unsigned long long *dest =
115  static_cast<unsigned long long*>(data_);
116  parse_num(buf, *dest);
117  }
118  break;
119  case x_double:
120  {
121  double *dest = static_cast<double*>(data_);
122  parse_num(buf, *dest);
123  }
124  break;
125  case x_stdtm:
126  {
127  // attempt to parse the string and convert to std::tm
128  std::tm *dest = static_cast<std::tm *>(data_);
129  parse_std_tm(buf, *dest);
130  }
131  break;
132  default:
133  throw soci_error("Into element used with non-supported type.");
134  }
135  }
136 }
137 
139 {
140  // nothing to do here
141 }
void parse_std_tm(char const *buf, std::tm &t)
Definition: row.h:41
virtual void define_by_pos(int &position, void *data, details::exchange_type type)
void parse_num(char const *buf, T &x)
Definition: mysql/common.h:46
virtual void post_fetch(bool gotData, bool calledFromFetch, indicator *ind)


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