8 #define SOCI_ODBC_SOURCE 22 #pragma warning(disable:4312) 32 throw soci_error(
"Vectors of size 0 are not allowed.");
35 indHolderVec_.resize(size);
36 indHolders_ = &indHolderVec_[0];
40 SQLSMALLINT &sqlType, SQLSMALLINT &cType)
46 sqlType = SQL_SMALLINT;
49 std::vector<short> *vp =
static_cast<std::vector<short> *
>(data);
50 std::vector<short> &v(*vp);
51 prepare_indicators(v.size());
57 sqlType = SQL_INTEGER;
59 size =
sizeof(SQLINTEGER);
60 assert(
sizeof(SQLINTEGER) ==
sizeof(
int));
61 std::vector<int> *vp =
static_cast<std::vector<int> *
>(data);
62 std::vector<int> &v(*vp);
63 prepare_indicators(v.size());
69 std::vector<long long> *vp =
70 static_cast<std::vector<long long> *
>(data);
71 std::vector<long long> &v(*vp);
72 std::size_t
const vsize = v.size();
73 prepare_indicators(vsize);
75 if (use_string_for_bigint())
77 sqlType = SQL_NUMERIC;
79 size = max_bigint_length;
80 buf_ =
new char[size * vsize];
86 cType = SQL_C_SBIGINT;
87 size =
sizeof(
long long);
94 std::vector<unsigned long long> *vp =
95 static_cast<std::vector<unsigned long long> *
>(data);
96 std::vector<unsigned long long> &v(*vp);
97 std::size_t
const vsize = v.size();
98 prepare_indicators(vsize);
100 if (use_string_for_bigint())
102 sqlType = SQL_NUMERIC;
104 size = max_bigint_length;
105 buf_ =
new char[size * vsize];
110 sqlType = SQL_BIGINT;
111 cType = SQL_C_SBIGINT;
112 size =
sizeof(
unsigned long long);
119 sqlType = SQL_DOUBLE;
120 cType = SQL_C_DOUBLE;
121 size =
sizeof(double);
122 std::vector<double> *vp =
static_cast<std::vector<double> *
>(data);
123 std::vector<double> &v(*vp);
124 prepare_indicators(v.size());
132 std::vector<char> *vp
133 =
static_cast<std::vector<char> *
>(data);
134 std::size_t
const vsize = vp->size();
136 prepare_indicators(vsize);
138 size =
sizeof(char) * 2;
139 buf_ =
new char[size * vsize];
143 for (std::size_t i = 0; i != vsize; ++i)
159 std::vector<std::string> *vp
160 =
static_cast<std::vector<std::string> *
>(data);
161 std::vector<std::string> &v(*vp);
163 std::size_t maxSize = 0;
164 std::size_t
const vecSize = v.size();
165 prepare_indicators(vecSize);
166 for (std::size_t i = 0; i != vecSize; ++i)
168 std::size_t sz = v[i].length() + 1;
169 indHolderVec_[i] =
static_cast<long>(sz);
170 maxSize = sz > maxSize ? sz : maxSize;
173 buf_ =
new char[maxSize * vecSize];
174 memset(buf_, 0, maxSize * vecSize);
177 for (std::size_t i = 0; i != vecSize; ++i)
179 strncpy(pos, v[i].c_str(), v[i].length());
184 size =
static_cast<SQLINTEGER
>(maxSize);
189 std::vector<std::tm> *vp
190 =
static_cast<std::vector<std::tm> *
>(data);
192 prepare_indicators(vp->size());
194 buf_ =
new char[
sizeof(TIMESTAMP_STRUCT) * vp->size()];
196 sqlType = SQL_TYPE_TIMESTAMP;
197 cType = SQL_C_TYPE_TIMESTAMP;
222 prepare_for_bind(data, size, sqlType, cType);
224 SQLULEN
const arraySize =
static_cast<SQLULEN
>(indHolderVec_.size());
225 SQLSetStmtAttr(statement_.hstmt_, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)arraySize, 0);
227 SQLRETURN rc = SQLBindParameter(statement_.hstmt_, static_cast<SQLUSMALLINT>(position++),
228 SQL_PARAM_INPUT, cType, sqlType, size, 0,
229 static_cast<SQLPOINTER>(data), size, indHolders_);
234 "Error while binding value to column");
241 if (statement_.boundByName_)
244 "Binding for use elements must be either by position or by name.");
247 bind_helper(position, data, type);
249 statement_.boundByPos_ =
true;
255 if (statement_.boundByPos_)
258 "Binding for use elements must be either by position or by name.");
264 for (std::vector<std::string>::iterator it = statement_.names_.begin();
265 it != statement_.names_.end(); ++it)
277 bind_helper(position, data, type);
281 std::ostringstream ss;
282 ss <<
"Unable to find name '" << name <<
"' to bind to";
286 statement_.boundByName_ =
true;
294 std::vector<std::tm> *vp
295 =
static_cast<std::vector<std::tm> *
>(data_);
297 std::vector<std::tm> &v(*vp);
300 std::size_t
const vsize = v.size();
301 for (std::size_t i = 0; i != vsize; ++i)
304 TIMESTAMP_STRUCT * ts =
reinterpret_cast<TIMESTAMP_STRUCT*
>(pos);
306 ts->year =
static_cast<SQLSMALLINT
>(t.tm_year + 1900);
307 ts->month =
static_cast<SQLUSMALLINT
>(t.tm_mon + 1);
308 ts->day =
static_cast<SQLUSMALLINT
>(t.tm_mday);
309 ts->hour =
static_cast<SQLUSMALLINT
>(t.tm_hour);
310 ts->minute =
static_cast<SQLUSMALLINT
>(t.tm_min);
311 ts->second =
static_cast<SQLUSMALLINT
>(t.tm_sec);
313 pos +=
sizeof(TIMESTAMP_STRUCT);
316 else if (type_ ==
x_long_long && use_string_for_bigint())
318 std::vector<long long> *vp
319 =
static_cast<std::vector<long long> *
>(data_);
320 std::vector<long long> &v(*vp);
323 std::size_t
const vsize = v.size();
324 for (std::size_t i = 0; i != vsize; ++i)
326 snprintf(pos, max_bigint_length,
"%" LL_FMT_FLAGS "d", v[i]);
327 pos += max_bigint_length;
332 std::vector<unsigned long long> *vp
333 =
static_cast<std::vector<unsigned long long> *
>(data_);
334 std::vector<unsigned long long> &v(*vp);
337 std::size_t
const vsize = v.size();
338 for (std::size_t i = 0; i != vsize; ++i)
340 snprintf(pos, max_bigint_length,
"%" LL_FMT_FLAGS "u", v[i]);
341 pos += max_bigint_length;
348 std::size_t
const vsize = size();
349 for (std::size_t i = 0; i != vsize; ++i, ++ind)
353 indHolderVec_[i] = SQL_NULL_DATA;
360 indHolderVec_[i] = SQL_NTS;
368 std::size_t
const vsize = size();
369 for (std::size_t i = 0; i != vsize; ++i, ++ind)
374 indHolderVec_[i] = SQL_NTS;
388 std::vector<char> *vp =
static_cast<std::vector<char> *
>(data_);
394 std::vector<short> *vp =
static_cast<std::vector<short> *
>(data_);
400 std::vector<int> *vp =
static_cast<std::vector<int> *
>(data_);
406 std::vector<long long> *vp =
407 static_cast<std::vector<long long> *
>(data_);
413 std::vector<unsigned long long> *vp =
414 static_cast<std::vector<unsigned long long> *
>(data_);
420 std::vector<double> *vp
421 =
static_cast<std::vector<double> *
>(data_);
427 std::vector<std::string> *vp
428 =
static_cast<std::vector<std::string> *
>(data_);
434 std::vector<std::tm> *vp
435 =
static_cast<std::vector<std::tm> *
>(data_);
virtual void bind_by_name(std::string const &name, void *data, details::exchange_type type)
bool is_odbc_error(SQLRETURN rc)
virtual void bind_by_pos(int &position, void *data, details::exchange_type type)
virtual std::size_t size()
void prepare_for_bind(void *&data, SQLUINTEGER &size, SQLSMALLINT &sqlType, SQLSMALLINT &cType)
void prepare_indicators(std::size_t size)
void bind_helper(int &position, void *data, details::exchange_type type)
virtual void pre_use(indicator const *ind)