firebird/standard-use-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, bool /* readOnly */)
19 {
20  if (statement_.boundByName_)
21  {
22  throw soci_error(
23  "Binding for use elements must be either by position or by name.");
24  }
25 
26  position_ = position-1;
27  data_ = data;
28  type_ = type;
29 
30  ++position;
31 
32  statement_.useType_ = eStandard;
33  statement_.uses_.push_back(static_cast<void*>(this));
34 
35  XSQLVAR *var = statement_.sqlda2p_->sqlvar+position_;
36 
37  buf_ = allocBuffer(var);
38  var->sqldata = buf_;
39  var->sqlind = &indISCHolder_;
40 
41  statement_.boundByPos_ = true;
42 }
43 
45  std::string const & name, void * data,
46  exchange_type type, bool /* readOnly */)
47 {
48  if (statement_.boundByPos_)
49  {
50  throw soci_error(
51  "Binding for use elements must be either by position or by name.");
52  }
53 
54  std::map <std::string, int> :: iterator idx =
55  statement_.names_.find(name);
56 
57  if (idx == statement_.names_.end())
58  {
59  throw soci_error("Missing use element for bind by name (" + name + ")");
60  }
61 
62  position_ = idx->second;
63  data_ = data;
64  type_ = type;
65 
66  statement_.useType_ = eStandard;
67  statement_.uses_.push_back(static_cast<void*>(this));
68 
69  XSQLVAR *var = statement_.sqlda2p_->sqlvar+position_;
70 
71  buf_ = allocBuffer(var);
72  var->sqldata = buf_;
73  var->sqlind = &indISCHolder_;
74 
75  statement_.boundByName_ = true;
76 }
77 
79 {
80  indISCHolder_ = 0;
81  if (ind)
82  {
83  switch (*ind)
84  {
85  case i_null:
86  indISCHolder_ = -1;
87  break;
88  case i_ok:
89  indISCHolder_ = 0;
90  break;
91  default:
92  throw soci_error("Unsupported indicator value.");
93  }
94  }
95 }
96 
98 {
99  XSQLVAR *var = statement_.sqlda2p_->sqlvar+position_;
100 
101  if (0 != indISCHolder_)
102  return;
103 
104  switch (type_)
105  {
106  case x_char:
107  setTextParam(static_cast<char*>(data_), 1, buf_, var);
108  break;
109  case x_short:
110  to_isc<short>(data_, var);
111  break;
112  case x_integer:
113  to_isc<int>(data_, var);
114  break;
115  case x_long_long:
116  to_isc<long long>(data_, var);
117  break;
118  case x_double:
119  to_isc<double>(data_, var);
120  break;
121 
122  case x_stdstring:
123  {
124  std::string *tmp = static_cast<std::string*>(data_);
125  setTextParam(tmp->c_str(), tmp->size(), buf_, var);
126  }
127  break;
128  case x_stdtm:
129  tmEncode(var->sqltype,
130  static_cast<std::tm*>(data_), buf_);
131  break;
132 
133  // cases that require special handling
134  case x_blob:
135  {
136  blob *tmp = static_cast<blob*>(data_);
137 
139  dynamic_cast<firebird_blob_backend*>(tmp->get_backend());
140 
141  if (NULL == blob)
142  {
143  throw soci_error("Can't get Firebid BLOB BackEnd");
144  }
145 
146  blob->save();
147  memcpy(buf_, &blob->bid_, var->sqllen);
148  }
149  break;
150  default:
151  throw soci_error("Use element used with non-supported type.");
152  } // switch
153 }
154 
156  bool /* gotData */, indicator * /* ind */)
157 {
158  // TODO: Is it possible to have the bound element being overwritten
159  // by the database?
160  // If not, then nothing to do here, please remove this comment.
161  // If yes, then use the value of the readOnly parameter:
162  // - true: the given object should not be modified and the backend
163  // should detect if the modification was performed on the
164  // isolated buffer and throw an exception if the buffer was modified
165  // (this indicates logic error, because the user used const object
166  // and executed a query that attempted to modified it)
167  // - false: the modification should be propagated to the given object.
168  // ...
169 }
170 
172 {
173  if (buf_ != NULL)
174  {
175  delete [] buf_;
176  buf_ = NULL;
177  }
178  std::vector<void*>::iterator it =
179  std::find(statement_.uses_.begin(), statement_.uses_.end(), this);
180  if (it != statement_.uses_.end())
181  statement_.uses_.erase(it);
182 }
void tmEncode(short type, std::tm *src, void *dst)
void setTextParam(char const *s, std::size_t size, char *buf_, XSQLVAR *var)
char * allocBuffer(XSQLVAR *var)
virtual void post_use(bool gotData, indicator *ind)
details::blob_backend * get_backend()
Definition: blob.h:39
virtual void bind_by_pos(int &position, void *data, details::exchange_type type, bool readOnly)
virtual void bind_by_name(std::string const &name, void *data, details::exchange_type type, bool readOnly)


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