Commit 0723512f authored by Sergei Nikulov's avatar Sergei Nikulov

fixed #383

parent 2fcad8b2
......@@ -33,6 +33,10 @@
#include <sqlext.h> // ODBC
#include <string.h> // strcpy()
#ifndef SQL_SS_LENGTH_UNLIMITED
#define SQL_SS_LENGTH_UNLIMITED 0
#endif
namespace soci
{
......@@ -41,6 +45,10 @@ namespace details
// TODO: Do we want to make it a part of public interface? --mloskot
std::size_t const odbc_max_buffer_length = 100 * 1024 * 1024;
// select max size from following MSDN article
// https://msdn.microsoft.com/en-us/library/ms130896.aspx
SQLLEN const ODBC_MAX_COL_SIZE = 8000;
// This cast is only used to avoid compiler warnings when passing strings
// to ODBC functions, the returned string may *not* be really modified.
inline SQLCHAR* sqlchar_cast(std::string const& s)
......
......@@ -37,7 +37,7 @@ void odbc_standard_into_type_backend::define_by_pos(
// Patch: set to min between column size and 100MB (used ot be 32769)
// Column size for text data type can be too large for buffer allocation
size = static_cast<SQLUINTEGER>(statement_.column_size(position_));
size = size > odbc_max_buffer_length ? odbc_max_buffer_length : size;
size = (size > odbc_max_buffer_length || size == 0) ? odbc_max_buffer_length : size;
size++;
buf_ = new char[size];
data = buf_;
......
......@@ -93,15 +93,6 @@ void* odbc_standard_use_type_backend::prepare_for_bind(
memcpy(buf_, s.c_str(), size);
buf_[size++] = '\0';
indHolder_ = SQL_NTS;
// Strings of greater length are silently truncated at 8000 limit by MS
// SQL unless SQL_SS_LENGTH_UNLIMITED (which is defined as 0, but not
// available in all headers) is used.
if (size > 8000)
{
sqlType = SQL_LONGVARCHAR;
size = 0 /* SQL_SS_LENGTH_UNLIMITED */;
}
}
break;
case x_stdtm:
......@@ -212,14 +203,19 @@ void odbc_standard_use_type_backend::pre_use(indicator const *ind)
SQLSMALLINT sqlType(0);
SQLSMALLINT cType(0);
SQLLEN size(0);
SQLLEN bufLen(0);
void* const sqlData = prepare_for_bind(size, sqlType, cType);
if (size > ODBC_MAX_COL_SIZE)
{
bufLen = size;
size = SQL_SS_LENGTH_UNLIMITED;
}
SQLRETURN rc = SQLBindParameter(statement_.hstmt_,
static_cast<SQLUSMALLINT>(position_),
SQL_PARAM_INPUT,
cType, sqlType, size, 0,
sqlData, 0, &indHolder_);
sqlData, bufLen, &indHolder_);
if (is_odbc_error(rc))
{
......
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