Bug report #19578

MSSQL: Setting geometry type to "Polygon" makes layer unselectable

Added by Simon South over 5 years ago. Updated over 5 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Data Provider/MSSQL
Affected QGIS version:3.2.1 Regression?:No
Operating System:Windows 10 Easy fix?:Yes
Pull Request or Patch supplied:No Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:27405

Description

In QGIS 3.2.1 on Windows 10, when attempting to add an empty layer from a SQL Server database using the Data Source Manager, the table's entry in the dialog becomes unselectable if its geometry type is set to "Polygon". As a result, the layer cannot be added.

No other geometry type seems to be affected.

To reproduce:

  1. Create a basic table in SQL Server like the following. Importantly, do not add any records to the table, so the geometry type cannot be inferred by QGIS.
    CREATE TABLE [dbo].[Polygon] (
        [PolygonID] [int] IDENTITY(1, 1) NOT NULL,
        [Shape] [geometry]
    )
    
  2. In QGIS, open the Data Source Manager (Ctrl-L), select "MSSQL" from the list on the left and connect to the database containing the table just created.
  3. In the list of tables that appears, set the "Polygon" table's SRID to "4326" and its geometry type to "Polygon".
  4. Attempt to select the table and add it to the project.

The issue appears to be a disagreement in the code on the meaning of the "Type" combo box's value: QgsMssqlSourceSelectDelegate::createEditor() populates it with values from the QgsWkbTypes::Type enum, while QgsMssqlTableModel::setData() interprets its value as belonging to the QgsWkbTypes::GeometryType enum. And since the value of QgsWkbTypes::Polygon happens to equal that of QgsWkbTypes::UnknownGeometry, setData() makes the table's entry unselectable when the "Polygon" type is selected in the UI.

This is probably the result of an edit accidentally left out of commit 4945611, which changed the enum used by QgsMssqlSourceSelectDelegate::createEditor().

I'll submit a pull request shortly.

Associated revisions

Revision a9ca69b7
Added by Simon South over 5 years ago

[MSSQL] Correctly interpret geometry-type setting

Interpret a table's geometry type (as selected in the Data Source Manager) as a
value from the QgsWkbTypes::Type enum, matching the values used to populate the
combo box in QgsMssqlSourceSelectDelegate::createEditor().

This allows an empty table whose geometry type is set to "Polygon" to be
selected and added using the dialog.

Fixes #19578.

Revision 25587f64
Added by Simon South over 5 years ago

[MSSQL] Correctly interpret geometry-type setting

Interpret a table's geometry type (as selected in the Data Source Manager) as a
value from the QgsWkbTypes::Type enum, matching the values used to populate the
combo box in QgsMssqlSourceSelectDelegate::createEditor().

This allows an empty table whose geometry type is set to "Polygon" to be
selected and added using the dialog.

Fixes #19578.

(cherry-picked from a9ca69b7)

History

#1 Updated by Simon South over 5 years ago

I've submitted pull request 7583 to fix this.

#2 Updated by Simon South over 5 years ago

  • % Done changed from 0 to 100
  • Status changed from Open to Closed

#3 Updated by Giovanni Manghi over 5 years ago

  • Resolution set to fixed/implemented

Also available in: Atom PDF