Commit 51c4c1e1 authored by Vadim Zeitlin's avatar Vadim Zeitlin

Fix the length of strings in DB2 vector operations

This is the same as a2c1ce7aceb564c11f48b3b586e2e77245c3deab except for
DB2 backend (which is, of course, very similar to ODBC one as ODBC API
is very close to DB2 CLI).
parent be4f26fe
......@@ -194,11 +194,23 @@ void db2_vector_into_type_backend::post_fetch(bool gotData, indicator *ind)
std::vector<std::string> &v(*vp);
char *pos = buf;
const char *pos = buf;
std::size_t const vsize = v.size();
for (std::size_t i = 0; i != vsize; ++i)
{
v[i].assign(pos, strlen(pos));
// See ODBC backend for explanation, this code for determining
// the string length is exactly the same as there.
const char* end = pos + indVec[i];
while (end != pos)
{
if (*--end != ' ')
{
++end;
break;
}
}
v[i].assign(pos, end - pos);
pos += colSize;
}
}
......
......@@ -139,18 +139,20 @@ void db2_vector_use_type_backend::prepare_for_bind(void *&data, SQLUINTEGER &siz
prepare_indicators(vecSize);
for (std::size_t i = 0; i != vecSize; ++i)
{
std::size_t sz = v[i].length() + 1; // add one for null
std::size_t sz = v[i].length();
indVec[i] = static_cast<long>(sz);
maxSize = sz > maxSize ? sz : maxSize;
}
maxSize++; // For terminating nul.
buf = new char[maxSize * vecSize];
memset(buf, 0, maxSize * vecSize);
char *pos = buf;
for (std::size_t i = 0; i != vecSize; ++i)
{
strncpy(pos, v[i].c_str(), v[i].length());
memcpy(pos, v[i].c_str(), v[i].length());
pos += maxSize;
}
......
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