Commit 11a8982d authored by Vadim Zeitlin's avatar Vadim Zeitlin

Add a helper function for copying strings in ODBC backend too

This will be reused for XML and CLOB types soon.
parent 556f5d33
......@@ -177,6 +177,15 @@ struct odbc_standard_use_type_backend : details::standard_use_type_backend,
details::exchange_type type_;
char *buf_;
SQLLEN indHolder_;
private:
// Copy string data to buf_ and set size, sqlType and cType to the values
// appropriate for strings.
void copy_from_string(std::string const& s,
SQLLEN& size,
SQLSMALLINT& sqlType,
SQLSMALLINT& cType);
};
struct odbc_vector_use_type_backend : details::vector_use_type_backend,
......
......@@ -86,13 +86,8 @@ void* odbc_standard_use_type_backend::prepare_for_bind(
case x_stdstring:
{
std::string const& s = exchange_type_cast<x_stdstring>(data_);
sqlType = SQL_VARCHAR;
cType = SQL_C_CHAR;
size = s.size();
buf_ = new char[size+1];
memcpy(buf_, s.c_str(), size);
buf_[size++] = '\0';
indHolder_ = SQL_NTS;
copy_from_string(s, size, sqlType, cType);
}
break;
case x_stdtm:
......@@ -128,6 +123,22 @@ void* odbc_standard_use_type_backend::prepare_for_bind(
return buf_ ? buf_ : data_;
}
void odbc_standard_use_type_backend::copy_from_string(
std::string const& s,
SQLLEN& size,
SQLSMALLINT& sqlType,
SQLSMALLINT& cType
)
{
sqlType = SQL_VARCHAR;
cType = SQL_C_CHAR;
size = s.size();
buf_ = new char[size+1];
memcpy(buf_, s.c_str(), size);
buf_[size++] = '\0';
indHolder_ = SQL_NTS;
}
void odbc_standard_use_type_backend::bind_by_pos(
int &position, void *data, exchange_type type, bool /* readOnly */)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment