Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSSQLSpatial: String values truncated when loading from GeoPackage #843

Closed
ghost opened this issue Aug 12, 2018 · 0 comments
Closed

MSSQLSpatial: String values truncated when loading from GeoPackage #843

ghost opened this issue Aug 12, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Aug 12, 2018

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 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:

ogr2ogr -f MSSQLSpatial "MSSQL:Driver={ODBC Driver 17 for SQL Server};Server=.;Database=DatabaseName;UID=Username;PWD=Password" ~/(…)/Geopackage.gpkg -lco "DIM=2" -progress

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

rouault pushed a commit that referenced this issue Aug 13, 2018
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants