Add a helper function for copying strings in ODBC backend too

This will be reused for XML and CLOB types soon.
This commit is contained in:
Vadim Zeitlin
2017-09-15 01:30:58 +02:00
parent 556f5d3369
commit 11a8982d5b
2 changed files with 27 additions and 7 deletions
+9
View File
@@ -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,
+18 -7
View File
@@ -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 */)
{