You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm loading a set of features from a GeoPackage file into a Microsoft SQL Server database and expecting the value of each feature attribute to be preserved.
However, I'm finding the value of each string attribute is being truncated to a single character. For example, an attribute with a value of "City Centre" in the source database is being stored as "C" in SQL Server.
This is another issue related to the difference between the wchar_t type on Windows and UNIX: The SQL Server ODBC driver expects the width of SQLWCHAR data to be exactly two bytes per character, which matches the definition of wchar_t on Windows but conflicts with Linux, where the type is four bytes long.
Consequently, the third and fourth byte of the first character in a wchar_t string on Linux will be interpreted as the second character of the string by the ODBC driver. And since these bytes are typically zero, the driver considers the string to be only a single character long.
In this case, the solution seems to be to modify OGRMSSQLSpatialTableLayer::AppendFieldValue() to "shorten" on affected systems each character in a wide-character string before passing it on to the ODBC driver for storage. I'll submit a pull request shortly with this change.
Steps to reproduce the problem.
Invoke ogr2ogr specifying a SQL Server database and a Geopackage file as the output and input, respectively:
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.
Expected behavior and actual behavior.
I'm loading a set of features from a GeoPackage file into a Microsoft SQL Server database and expecting the value of each feature attribute to be preserved.
However, I'm finding the value of each string attribute is being truncated to a single character. For example, an attribute with a value of "City Centre" in the source database is being stored as "C" in SQL Server.
This is another issue related to the difference between the
wchar_t
type on Windows and UNIX: The SQL Server ODBC driver expects the width ofSQLWCHAR
data to be exactly two bytes per character, which matches the definition ofwchar_t
on Windows but conflicts with Linux, where the type is four bytes long.Consequently, the third and fourth byte of the first character in a
wchar_t
string on Linux will be interpreted as the second character of the string by the ODBC driver. And since these bytes are typically zero, the driver considers the string to be only a single character long.In this case, the solution seems to be to modify
OGRMSSQLSpatialTableLayer::AppendFieldValue()
to "shorten" on affected systems each character in a wide-character string before passing it on to the ODBC driver for storage. I'll submit a pull request shortly with this change.Steps to reproduce the problem.
Invoke
ogr2ogr
specifying a SQL Server database and a Geopackage file as the output and input, respectively:Operating system
Ubuntu 16.04.5 64-bit (via Windows Subsystem for Linux on Windows 10)
Microsoft ODBC Driver 17 for SQL Server
GDAL version and provenance
GDAL 2.4.0dev, compiled from
master
The text was updated successfully, but these errors were encountered: