6 #define SOCI_ODBC_SOURCE 19 #pragma warning(disable:4996) 20 #define snprintf _snprintf 25 SQLLEN &size, SQLSMALLINT &sqlType, SQLSMALLINT &cType)
31 sqlType = SQL_SMALLINT;
36 sqlType = SQL_INTEGER;
41 if (use_string_for_bigint())
43 sqlType = SQL_NUMERIC;
45 size = max_bigint_length;
46 buf_ =
new char[size];
48 *static_cast<long long *>(data_));
54 cType = SQL_C_SBIGINT;
55 size =
sizeof(
long long);
59 if (use_string_for_bigint())
61 sqlType = SQL_NUMERIC;
63 size = max_bigint_length;
64 buf_ =
new char[size];
66 *static_cast<unsigned long long *>(data_));
72 cType = SQL_C_UBIGINT;
73 size =
sizeof(
unsigned long long);
79 size =
sizeof(double);
86 buf_ =
new char[size];
87 buf_[0] = *
static_cast<char*
>(data_);
93 std::string* s =
static_cast<std::string*
>(data_);
94 sqlType = SQL_VARCHAR;
97 buf_ =
new char[size+1];
98 memcpy(buf_, s->c_str(), size);
100 indHolder_ = SQL_NTS;
105 std::tm *t =
static_cast<std::tm *
>(data_);
107 sqlType = SQL_TIMESTAMP;
108 cType = SQL_C_TIMESTAMP;
109 buf_ =
new char[
sizeof(TIMESTAMP_STRUCT)];
114 TIMESTAMP_STRUCT * ts =
reinterpret_cast<TIMESTAMP_STRUCT*
>(buf_);
116 ts->year =
static_cast<SQLSMALLINT
>(t->tm_year + 1900);
117 ts->month =
static_cast<SQLUSMALLINT
>(t->tm_mon + 1);
118 ts->day =
static_cast<SQLUSMALLINT
>(t->tm_mday);
119 ts->hour =
static_cast<SQLUSMALLINT
>(t->tm_hour);
120 ts->minute =
static_cast<SQLUSMALLINT
>(t->tm_min);
121 ts->second =
static_cast<SQLUSMALLINT
>(t->tm_sec);
149 return buf_ ? buf_ : data_;
155 if (statement_.boundByName_)
158 "Binding for use elements must be either by position or by name.");
161 position_ = position++;
165 statement_.boundByPos_ =
true;
169 std::string
const &name,
void *data,
exchange_type type,
bool )
171 if (statement_.boundByPos_)
174 "Binding for use elements must be either by position or by name.");
180 for (std::vector<std::string>::iterator it = statement_.names_.begin();
181 it != statement_.names_.end(); ++it)
193 std::ostringstream ss;
194 ss <<
"Unable to find name '" << name <<
"' to bind to";
198 position_ = position;
202 statement_.boundByName_ =
true;
212 void*
const sqlData = prepare_for_bind(size, sqlType, cType);
214 SQLRETURN rc = SQLBindParameter(statement_.hstmt_,
215 static_cast<SQLUSMALLINT>(position_),
217 cType, sqlType, size, 0,
218 sqlData, 0, &indHolder_);
227 if (ind != NULL && *ind ==
i_null)
229 indHolder_ = SQL_NULL_DATA;
243 else if (indHolder_ == SQL_NULL_DATA)
virtual void bind_by_name(std::string const &name, void *data, details::exchange_type type, bool readOnly)
virtual void bind_by_pos(int &position, void *data, details::exchange_type type, bool readOnly)
void * prepare_for_bind(SQLLEN &size, SQLSMALLINT &sqlType, SQLSMALLINT &cType)
bool is_odbc_error(SQLRETURN rc)
virtual void pre_use(indicator const *ind)
virtual void post_use(bool gotData, indicator *ind)