mirror of
https://github.com/SOCI/soci.git
synced 2026-04-27 06:40:16 -05:00
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:
@@ -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 */)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user