Commit 4a7758d7 authored by Alice Salsé's avatar Alice Salsé
Browse files

👌 related tables VM

parent eef01f59
...@@ -7,8 +7,9 @@ from qgis.core import QgsDataSourceUri, QgsWkbTypes, QgsMapLayerType,QgsFeature ...@@ -7,8 +7,9 @@ from qgis.core import QgsDataSourceUri, QgsWkbTypes, QgsMapLayerType,QgsFeature
# initialize Qt resources from file resources.py # initialize Qt resources from file resources.py
# execute : pyrcc5 -o resources.py resources.qrc # execute : pyrcc5 -o resources.py resources.qrc
from . import resources from . import resources
import csv
qconst = """select * from utils.related_table qconst = """select * from utils.vm_related_table
where pt_schema='{0}' where pt_schema='{0}'
and pt_name='{1}';""" and pt_name='{1}';"""
...@@ -126,7 +127,7 @@ class NetworkTools: ...@@ -126,7 +127,7 @@ class NetworkTools:
def activeLayerSelection(self) : def activeLayerSelection(self) :
layer = self.iface.activeLayer() layer = self.iface.activeLayer()
if not layer: if not layer :
self.iface.messageBar().pushMessage("Veuillez sélectionner une couche d'abord", Qgis.Warning) self.iface.messageBar().pushMessage("Veuillez sélectionner une couche d'abord", Qgis.Warning)
return return
else : else :
...@@ -278,7 +279,7 @@ class NetworkTools: ...@@ -278,7 +279,7 @@ class NetworkTools:
column_names, records = executeQuery(layer.dataProvider(), qconst.format(_schema, typ)) column_names, records = executeQuery(layer.dataProvider(), qconst.format(_schema, typ))
for rec in records : for rec in records :
self.selectLayerFromTable(rec[0], rec[1], 'id in ({0})'.format(','.join([str(i) for i in ids] or '0'))) self.selectLayerFromTable(rec[0], rec[1], 'id in ({0})'.format(','.join([str(i) for i in ids] or '0')))
self.selectLayerFromTable(rec[0], typ, 'id in ({0})'.format(','.join([str(i) for i in ids] or '0'))) self.selectLayerFromTable(_schema, typ, 'id in ({0})'.format(','.join([str(i) for i in ids] or '0')))
else : else :
self.iface.messageBar().pushMessage("La couche sélectionnée n'est pas de type ligne", Qgis.Warning) self.iface.messageBar().pushMessage("La couche sélectionnée n'est pas de type ligne", Qgis.Warning)
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
set search_path to utils, public; set search_path to utils, public;
-- VUE recensant les tables reliées -- VUE recensant les tables reliées
CREATE OR REPLACE VIEW utils.related_table AS DROP MATERIALIZED VIEW IF EXISTS utils.vm_related_table;
CREATE MATERIALIZED VIEW utils.vm_related_table AS
select kcu.table_schema as ft_schema, select kcu.table_schema as ft_schema,
kcu.table_name as ft_name, kcu.table_name as ft_name,
kcu.table_schema || '.' || kcu.table_name as foreign_table, kcu.table_schema || '.' || kcu.table_name as foreign_table,
......
...@@ -6,7 +6,7 @@ SET tmpvar.schemaname TO :'schemaname'; ...@@ -6,7 +6,7 @@ SET tmpvar.schemaname TO :'schemaname';
DO $$ DO $$
DECLARE DECLARE
_relations CURSOR FOR _relations CURSOR FOR
select * from utils.related_table select * from utils.vm_related_table
where ft_schema=current_setting('tmpvar.schemaname', true) where ft_schema=current_setting('tmpvar.schemaname', true)
and no=1; and no=1;
l record; l record;
......
...@@ -8,7 +8,7 @@ CREATE OR REPLACE FUNCTION fnc_duplicate_attributes( ...@@ -8,7 +8,7 @@ CREATE OR REPLACE FUNCTION fnc_duplicate_attributes(
RETURNS void AS $BODY$ RETURNS void AS $BODY$
DECLARE DECLARE
_relations CURSOR FOR _relations CURSOR FOR
select * from utils.related_table select * from utils.vm_related_table
where foreign_table = i_nw_regclass::text; where foreign_table = i_nw_regclass::text;
_new_obj jsonb; _new_obj jsonb;
BEGIN BEGIN
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment