Skip to content

Commit

Permalink
Add additional check if raster table has raster BLOB column type
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi committed Sep 27, 2023
1 parent a995328 commit f76ec52
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions gui/wxpython/gui_core/gselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2688,11 +2688,56 @@ def _getRasterliteDBRasters(self, dsn):
database=dsn,
parse=(
self._rasterliteDBRastersParser,
{"raster_tables_suffix": raster_tables_suffix},
{
"raster_tables_suffix": raster_tables_suffix,
"dsn": dsn,
},
),
)

def _rasterliteDBRastersParser(self, raster_tables, raster_tables_suffix):
def _checkRasterliteDBRasterBlobColumnExists(
self,
database,
tables,
raster_suffix,
):
"""Check if Rasterlite DB raster table has raster BLOB column
:param str database: database path
:param list tables: raster tables
:param str raster_suffix: Rasterlite DB raster table suffix,
which is _rasters usually
:return list other_tables: list of Rasterlite DB tables which
aren't rasters
"""
other_tables = []
tabs_with_quotes = [f"'{t}'" for t in tables]
ret = grass.read_command(
"db.select",
flags="c",
sql=(
"SELECT sql FROM sqlite_master"
f" WHERE tbl_name IN ({', '.join(tabs_with_quotes)})"
" AND type = 'table'"
),
database=database,
)
for line in ret.split(os.linesep):
if "raster BLOB" not in line:
for table in tables:
if table in line:
other_tables.append(
table.replace(raster_suffix, ""),
)
return other_tables

def _rasterliteDBRastersParser(
self,
raster_tables,
raster_tables_suffix,
dsn,
):
"""Rasterlite DB raster tables names parser
:param str raster_tables: raster tables names (output of the
Expand All @@ -2702,6 +2747,7 @@ def _rasterliteDBRastersParser(self, raster_tables, raster_tables_suffix):
there are 2 corresponding SQLite
tables, suffixed with _rasters
and _metadata
:param str dsn: Rasterlite DB data source name
:return list: list of Rasterlite raster names
"""
Expand Down Expand Up @@ -2729,6 +2775,14 @@ def _rasterliteDBRastersParser(self, raster_tables, raster_tables_suffix):
]
for table in other_tables:
del raster_tables_count[table]
# Check if raster BLOB column type exists
raster_suffix = raster_tables_suffix["table_suffix1"]
for table in self._checkRasterliteDBRasterBlobColumnExists(
database=dsn,
tables=[f"{t}{raster_suffix}" for t in raster_tables_count],
raster_suffix=raster_suffix,
):
del raster_tables_count[table]
return list(raster_tables_count.keys())


Expand Down

0 comments on commit f76ec52

Please sign in to comment.