MSSQL provider fails to load UNIQUEIDENTIFIER fields #25284
Labels
Bug
Either a bug report, or a bug fix. Let's hope for the latter!
Data Provider
Related to specific vector, raster or mesh data providers
Author Name: Kristian Thy (@kthy)
Original Redmine Issue: 17387
Affected QGIS version: master
Redmine category:data_provider/mssql
Experienced in QGIS 2.18.12, 2.18.14 on Windows 8.1. (Code still present in master branch, but 2.99 crashes before I reach it, apparently due to an unrelated issue.)
I'm trying to load a layer from MSSQL into PostgreSQL using the DB Manager plugin (following the recipe at https://gis.stackexchange.com/a/200594/10741) but I receive this error for each row:
Source code investigation leads me to believe that this is caused by the MSSQL provider treating the @UNIQUEIDENTIFIER@ datatype as a @QVariant::String@. Problem is that MSSQL reports the length of this datatype as 16, which is the byte size of a GUID. When converted to a string, the length is actually 36 characters, so the error I'm seeing is likely caused by trying to cram a 36 character string into a field 16 characters wide.
Luckily, MSSQL reports the size of the datatype in the precision field also returned by @exec sp_columns@. My hunch is that the issue can thus be resolved by the attached patch to @src/providers/mssql/qgsmssqlprovider.cpp@. Unfortunately I can't build QGIS on Windows myself, so I have not tested the patch.
The text was updated successfully, but these errors were encountered: