firebird/standard-into-type.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, Rafal Bobrowski
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_FIREBIRD_SOURCE
9 #include "soci-firebird.h"
10 #include "common.h"
11 #include <soci.h>
12 
13 using namespace soci;
14 using namespace soci::details;
15 using namespace soci::details::firebird;
16 
18  int & position, void * data, exchange_type type)
19 {
20  position_ = position-1;
21  data_ = data;
22  type_ = type;
23 
24  ++position;
25 
26  statement_.intoType_ = eStandard;
27  statement_.intos_.push_back(static_cast<void*>(this));
28 
29  XSQLVAR *var = statement_.sqldap_->sqlvar+position_;
30 
31  buf_ = allocBuffer(var);
32  var->sqldata = buf_;
33  var->sqlind = &indISCHolder_;
34 }
35 
37 {
38  // nothing to do
39 }
40 
42  bool gotData, bool calledFromFetch, indicator * ind)
43 {
44  if (calledFromFetch && (gotData == false))
45  {
46  // this is a normal end-of-rowset condition,
47  // no need to set anything (fetch() will return false)
48  return;
49  }
50 
51  if (gotData)
52  {
53  if (i_null == statement_.inds_[position_][0] && NULL == ind)
54  {
55  throw soci_error("Null value fetched and no indicator defined.");
56  }
57  else if (NULL != ind)
58  {
59  *ind = statement_.inds_[position_][0];
60  }
61  }
62 }
63 
64 
66 {
67  XSQLVAR *var = statement_.sqldap_->sqlvar+position_;
68 
69  switch (type_)
70  {
71  // simple cases
72  case x_char:
73  *reinterpret_cast<char*>(data_) = getTextParam(var)[0];
74  break;
75  case x_short:
76  {
77  short t = from_isc<short>(var);
78  *reinterpret_cast<short*>(data_) = t;
79  }
80  break;
81  case x_integer:
82  {
83  int t = from_isc<int>(var);
84  *reinterpret_cast<int *>(data_) = t;
85  }
86  break;
87  case x_long_long:
88  {
89  long long t = from_isc<long long>(var);
90  *reinterpret_cast<long long *>(data_) = t;
91  }
92  break;
93  case x_double:
94  {
95  double t = from_isc<double>(var);
96  *reinterpret_cast<double*>(data_) = t;
97  }
98  break;
99 
100  // cases that require adjustments and buffer management
101  case x_stdstring:
102  *(reinterpret_cast<std::string*>(data_)) = getTextParam(var);
103  break;
104  case x_stdtm:
105  tmDecode(var->sqltype,
106  buf_, static_cast<std::tm*>(data_));
107 
108  // isc_decode_timestamp() used by tmDecode() incorrectly sets
109  // tm_isdst to 0 in the struct that it creates, see
110  // http://tracker.firebirdsql.org/browse/CORE-3877, work around it
111  // by pretending the DST is actually unknown.
112  static_cast<std::tm*>(data_)->tm_isdst = -1;
113  break;
114 
115  // cases that require special handling
116  case x_blob:
117  {
118  blob *tmp = reinterpret_cast<blob*>(data_);
119 
121  dynamic_cast<firebird_blob_backend*>(tmp->get_backend());
122 
123  if (0 == blob)
124  {
125  throw soci_error("Can't get Firebid BLOB BackEnd");
126  }
127 
128  blob->assign(*reinterpret_cast<ISC_QUAD*>(buf_));
129  }
130  break;
131  default:
132  throw soci_error("Into element used with non-supported type.");
133  } // switch
134 }
135 
137 {
138  if (buf_ != NULL)
139  {
140  delete [] buf_;
141  buf_ = NULL;
142  }
143  std::vector<void*>::iterator it =
144  std::find(statement_.intos_.begin(), statement_.intos_.end(), this);
145  if (it != statement_.intos_.end())
146  statement_.intos_.erase(it);
147 }
virtual void assign(ISC_QUAD const &bid)
virtual void define_by_pos(int &position, void *data, details::exchange_type type)
char * allocBuffer(XSQLVAR *var)
void tmDecode(short type, void *src, std::tm *dst)
details::blob_backend * get_backend()
Definition: blob.h:39
virtual void post_fetch(bool gotData, bool calledFromFetch, indicator *ind)
std::string getTextParam(XSQLVAR const *var)


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