9 #define SOCI_DB2_SOURCE 21 #pragma warning(disable:4312) 32 throw soci_error(
"Vectors of size 0 are not allowed.");
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;
60 std::vector<int> *vp =
static_cast<std::vector<int> *
>(data);
61 std::vector<int> &v(*vp);
62 prepare_indicators(v.size());
69 cType = SQL_C_SBIGINT;
70 size =
sizeof(
long long);
71 std::vector<long long> *vp
72 =
static_cast<std::vector<long long> *
>(data);
73 std::vector<long long> &v(*vp);
74 prepare_indicators(v.size());
81 cType = SQL_C_UBIGINT;
82 size =
sizeof(
unsigned long long);
83 std::vector<unsigned long long> *vp
84 =
static_cast<std::vector<unsigned long long> *
>(data);
85 std::vector<unsigned long long> &v(*vp);
86 prepare_indicators(v.size());
94 size =
sizeof(double);
95 std::vector<double> *vp =
static_cast<std::vector<double> *
>(data);
96 std::vector<double> &v(*vp);
97 prepare_indicators(v.size());
105 std::vector<char> *vp
106 =
static_cast<std::vector<char> *
>(data);
107 std::size_t
const vsize = vp->size();
109 prepare_indicators(vsize);
111 size =
sizeof(char) * 2;
112 buf =
new char[size * vsize];
116 for (std::size_t i = 0; i != vsize; ++i)
132 std::vector<std::string> *vp
133 =
static_cast<std::vector<std::string> *
>(data);
134 std::vector<std::string> &v(*vp);
136 std::size_t maxSize = 0;
137 std::size_t
const vecSize = v.size();
138 prepare_indicators(vecSize);
139 for (std::size_t i = 0; i != vecSize; ++i)
141 std::size_t sz = v[i].length() + 1;
142 indVec[i] =
static_cast<long>(sz);
143 maxSize = sz > maxSize ? sz : maxSize;
146 buf =
new char[maxSize * vecSize];
147 memset(buf, 0, maxSize * vecSize);
150 for (std::size_t i = 0; i != vecSize; ++i)
152 strncpy(pos, v[i].c_str(), v[i].length());
157 size =
static_cast<SQLINTEGER
>(maxSize);
162 std::vector<std::tm> *vp
163 =
static_cast<std::vector<std::tm> *
>(data);
165 prepare_indicators(vp->size());
167 buf =
new char[
sizeof(TIMESTAMP_STRUCT) * vp->size()];
169 sqlType = SQL_TYPE_TIMESTAMP;
170 cType = SQL_C_TYPE_TIMESTAMP;
195 prepare_for_bind(data, size, sqlType, cType);
197 SQLINTEGER arraySize = (SQLINTEGER)indVec.size();
198 SQLSetStmtAttr(statement_.hStmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)arraySize, 0);
200 SQLRETURN cliRC = SQLBindParameter(statement_.hStmt, static_cast<SQLUSMALLINT>(position++),
201 SQL_PARAM_INPUT, cType, sqlType, size, 0,
202 static_cast<SQLPOINTER>(data), size, indptr);
204 if ( cliRC != SQL_SUCCESS )
206 throw db2_soci_error(
"Error while binding value to column", cliRC);
215 throw soci_error(
"Binding for use elements must be either by position or by name.");
219 bind_helper(position, data, type);
230 throw soci_error(
"Binding for use elements must be either by position or by name.");
234 for (std::vector<std::string>::iterator it = statement_.names.begin();
235 it != statement_.names.end(); ++it)
247 bind_helper(position, data, type);
251 std::ostringstream ss;
252 ss <<
"Unable to find name '" << name <<
"' to bind to";
262 std::vector<std::tm> *vp
263 =
static_cast<std::vector<std::tm> *
>(data);
265 std::vector<std::tm> &v(*vp);
268 std::size_t
const vsize = v.size();
269 for (std::size_t i = 0; i != vsize; ++i)
272 TIMESTAMP_STRUCT * ts =
reinterpret_cast<TIMESTAMP_STRUCT*
>(pos);
274 ts->year =
static_cast<SQLSMALLINT
>(t.tm_year + 1900);
275 ts->month =
static_cast<SQLUSMALLINT
>(t.tm_mon + 1);
276 ts->day =
static_cast<SQLUSMALLINT
>(t.tm_mday);
277 ts->hour =
static_cast<SQLUSMALLINT
>(t.tm_hour);
278 ts->minute =
static_cast<SQLUSMALLINT
>(t.tm_min);
279 ts->second =
static_cast<SQLUSMALLINT
>(t.tm_sec);
281 pos +=
sizeof(TIMESTAMP_STRUCT);
288 std::size_t
const vsize = size();
289 for (std::size_t i = 0; i != vsize; ++i, ++ind)
293 indVec[i] = SQL_NULL_DATA;
308 std::size_t
const vsize = size();
309 for (std::size_t i = 0; i != vsize; ++i, ++ind)
328 std::vector<char> *vp =
static_cast<std::vector<char> *
>(data);
334 std::vector<short> *vp =
static_cast<std::vector<short> *
>(data);
340 std::vector<int> *vp =
static_cast<std::vector<int> *
>(data);
346 std::vector<long long> *vp
347 =
static_cast<std::vector<long long> *
>(data);
353 std::vector<unsigned long long> *vp
354 =
static_cast<std::vector<unsigned long long> *
>(data);
360 std::vector<double> *vp
361 =
static_cast<std::vector<double> *
>(data);
367 std::vector<std::string> *vp
368 =
static_cast<std::vector<std::string> *
>(data);
374 std::vector<std::tm> *vp
375 =
static_cast<std::vector<std::tm> *
>(data);
void pre_use(indicator const *ind)
void prepare_indicators(std::size_t size)
void bind_helper(int &position, void *data, details::exchange_type type)
void bind_by_name(std::string const &name, void *data, details::exchange_type type)
void prepare_for_bind(void *&data, SQLUINTEGER &size, SQLSMALLINT &sqlType, SQLSMALLINT &cType)
void bind_by_pos(int &position, void *data, details::exchange_type type)