Skip to content

Commit

Permalink
MSSQLSpatial: Don't truncate string values (fixes #843)
Browse files Browse the repository at this point in the history
On UNIX and other systems where the size of "wchar_t" is greater than two
bytes, shorten the length of each charater in a wide-character string before
passing it to the ODBC driver so the string is not truncated.
  • Loading branch information
Simon South authored and rouault committed Aug 13, 2018
1 parent fb70611 commit 96424d2
Showing 1 changed file with 7 additions and 0 deletions.
Expand Up @@ -2372,6 +2372,13 @@ void OGRMSSQLSpatialTableLayer::AppendFieldValue(CPLODBCStatement *poStatement,
"String data truncation applied on field: %s. Use a more recent ODBC driver that supports handling large string values.", poFeatureDefn->GetFieldDefn(i)->GetNameRef() );
#endif
}
#if WCHAR_MAX > 0xFFFFu
// Shorten each character to a two-byte value, as expected by
// the ODBC driver
GUInt16 *panBuffer = reinterpret_cast<GUInt16 *>(buffer);
for( unsigned int nIndex = 1; nIndex < nLen; nIndex += 1 )
panBuffer[nIndex] = static_cast<GUInt16>(buffer[nIndex]);
#endif
int nRetCode = SQLBindParameter(poStatement->GetStatement(), (SQLUSMALLINT)((*bind_num) + 1),
SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_WVARCHAR, nLen, 0, (SQLPOINTER)buffer, 0, nullptr);
if ( nRetCode == SQL_SUCCESS || nRetCode == SQL_SUCCESS_WITH_INFO )
Expand Down

0 comments on commit 96424d2

Please sign in to comment.