Skip to content

Commit

Permalink
Fixed identification of the spatialite schema version (issue #241).
Browse files Browse the repository at this point in the history
  • Loading branch information
ldebek committed Jun 27, 2024
1 parent 98c6749 commit aa5c5a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ History
1.11.1 (unreleased)
-------------------

- Nothing changed yet.
- Fixes/enhancements: #241


1.11.0 (2024-06-21)
Expand Down
22 changes: 15 additions & 7 deletions threedi_schematisation_editor/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@ def report_conversion_errors(self, report_limit=25):
def spatialite_schema_version(sqlite_path):
"""Getting Spatialite 3Di model database schema version."""
schema_version_table = sqlite_layer(sqlite_path, "schema_version", geom_column=None)
if not schema_version_table.isValid():
return None
try:
schema_row = next(iter(schema_version_table.getFeatures()))
spatialite_schema_id = int(schema_row["version_num"])
except (StopIteration, TypeError):
spatialite_schema_id = 1
if schema_version_table.isValid():
try:
schema_row = next(iter(schema_version_table.getFeatures()))
spatialite_schema_id = int(schema_row["version_num"])
except (StopIteration, TypeError):
spatialite_schema_id = 1
else:
schema_version_table = sqlite_layer(sqlite_path, "south_migrationhistory", geom_column=None)
if not schema_version_table.isValid() or schema_version_table.featureCount() == 0:
return None
schema_row = list(schema_version_table.getFeatures())[-1]
try:
spatialite_schema_id = int(schema_row["migration"].split("_", 1)[0])
except (AttributeError, IndexError, TypeError, ValueError):
spatialite_schema_id = 1
return spatialite_schema_id

def set_epsg_from_sqlite(self):
Expand Down

0 comments on commit aa5c5a3

Please sign in to comment.