Skip to content

Commit

Permalink
Use fstrings for SQL statements in the filter by polygon about index
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Sep 3, 2024
1 parent d30f1cb commit dfda4fb
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lizmap/definitions/filter_by_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,13 @@ def has_spatial_centroid_index(cls, layer: QgsVectorLayer) -> Tuple[bool, Option

metadata = QgsProviderRegistry.instance().providerMetadata('postgres')
connection = metadata.createConnection(datasource.uri(), {})
result = connection.executeSql("""
result = connection.executeSql(f"""
SELECT tablename, indexname, indexdef
FROM pg_indexes
WHERE schemaname = '{schema}'
AND tablename = '{table}'
AND indexdef ILIKE '%{geom}%'
AND indexdef ILIKE '%st_centroid%'""".format(
schema=datasource.schema(),
table=datasource.table(),
geom=datasource.geometryColumn(),
)
WHERE schemaname = '{datasource.schema()}'
AND tablename = '{datasource.table()}'
AND indexdef ILIKE '%{datasource.geometryColumn()}%'
AND indexdef ILIKE '%st_centroid%'"""
)
if len(result) >= 1:
return True, None
Expand All @@ -156,10 +152,9 @@ def has_spatial_centroid_index(cls, layer: QgsVectorLayer) -> Tuple[bool, Option
message += tr(
'<b>Either</b> do not use this option, <b>or</b> the following query must be executed by <b>yourself</b>')
message += '\n'
message += "CREATE INDEX ON \"{schema}\".\"{table}\" USING GIST (ST_Centroid({geom}));".format(
schema=datasource.schema(),
table=datasource.table(),
geom=datasource.geometryColumn(),
message += (
f"CREATE INDEX ON \"{datasource.schema()}\".\"{datasource.table()}\" "
f"USING GIST (ST_Centroid({datasource.geometryColumn()}))"
)
return False, message

Expand Down

0 comments on commit dfda4fb

Please sign in to comment.