From c1d194c138b7d5e5cf8de294802c68bf75b2f312 Mon Sep 17 00:00:00 2001 From: Arnaud Poncet-Montanges Date: Fri, 30 Aug 2024 12:11:53 +0200 Subject: [PATCH 1/2] fix_text_type_sql fix_text_type_sql for sqlalchemy v1 --- qgepqwat2ili/postimport.py | 18 ++++++++++-------- qgepqwat2ili/qgep/import_.py | 5 +++-- qgepqwat2ili/qgepdss/import_.py | 5 +++-- qgepqwat2ili/qgepsia405/import_.py | 5 +++-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/qgepqwat2ili/postimport.py b/qgepqwat2ili/postimport.py index 52fa3320..b6db1b2e 100644 --- a/qgepqwat2ili/postimport.py +++ b/qgepqwat2ili/postimport.py @@ -5,6 +5,7 @@ from geoalchemy2.functions import ST_Force3D from sqlalchemy.orm import Session from sqlalchemy.orm.attributes import flag_dirty +from sqlalchemy.sql import text #31.5.2024 pfade anpassen #from .. import utils @@ -28,33 +29,34 @@ def qgep_postimport(): post_session = Session(utils.sqlalchemy.create_engine(), autocommit=False, autoflush=False) logger.info("re-enabling symbology triggers (postimport.py)") - post_session.execute("SELECT qgep_sys.create_symbology_triggers();") + post_session.execute(text("SELECT qgep_sys.create_symbology_triggers();")) logger.info("symbology triggers successfully created! (postimport.py)") # add queries for main_cover and main_node as in TEKSI, add to symbology functions # see teksi ww https://github.com/teksi/wastewater/blob/3acfba249866d299f8a22e249d9f1e475fe7b88d/datamodel/app/symbology_functions.sql#L290 # needs delta_1.6.3_functions_update_fk_main_cover_main_wastewater_node.sql logger.info("Update wastewater structure fk_main_cover") - post_session.execute("SELECT qgep_od.wastewater_structure_update_fk_main_cover('', True);") + post_session.execute(text("SELECT qgep_od.wastewater_structure_update_fk_main_cover('', True);")) logger.info("Update wastewater structure fk_main_wastewater_node") - post_session.execute("SELECT qgep_od.wastewater_structure_update_fk_main_wastewater_node('', True);" + post_session.execute(text("SELECT qgep_od.wastewater_structure_update_fk_main_wastewater_node('', True));" ) # add symbology update queries - backporting from tww https://github.com/teksi/wastewater/pull/263 logger.info("update_wastewater_node_symbology for all datasets - please be patient") - post_session.execute("SELECT qgep_od.update_wastewater_node_symbology(NULL, True);") + post_session.execute(text("SELECT qgep_od.update_wastewater_node_symbology(NULL, True);")) + logger.info("update_wastewater_node_symbology for all datasets - please be patient") logger.info("update_wastewater_structure_label for all datasets - please be patient") - post_session.execute("SELECT qgep_od.update_wastewater_structure_label(NULL, True);") + post_session.execute(text("SELECT qgep_od.update_wastewater_structure_label(NULL, True);")) + logger.info("update_wastewater_node_symbology for all datasets - please be patient") # update_wastewater_structure_symbology instead of update_wn_symbology_by_overflow (tww) logger.info("update_wastewater_structure_symbology for all datasets - please be patient") - post_session.execute("SELECT qgep_od.update_wastewater_structure_symbology(NULL, True);") - + post_session.execute(text("SELECT qgep_od.update_wastewater_structure_symbology(NULL, True);")) logger.info("Refresh materialized views") - post_session.execute("SELECT qgep_network.refresh_network_simple();") + post_session.execute(text("SELECT qgep_network.refresh_network_simple();")) post_session.commit() post_session.close() \ No newline at end of file diff --git a/qgepqwat2ili/qgep/import_.py b/qgepqwat2ili/qgep/import_.py index 71963e98..0beaac74 100644 --- a/qgepqwat2ili/qgep/import_.py +++ b/qgepqwat2ili/qgep/import_.py @@ -3,6 +3,7 @@ from geoalchemy2.functions import ST_Force3D from sqlalchemy.orm import Session from sqlalchemy.orm.attributes import flag_dirty +from sqlalchemy.sql import text from .. import utils from ..utils.various import logger @@ -27,7 +28,7 @@ def qgep_import(precommit_callback=None): # We also drop symbology triggers as they badly affect performance. This must be done in a separate session as it # would deadlock other sessions. - pre_session.execute("SELECT qgep_sys.drop_symbology_triggers();") + pre_session.execute(text("SELECT qgep_sys.drop_symbology_triggers();")) pre_session.commit() pre_session.close() @@ -39,7 +40,7 @@ def qgep_import(precommit_callback=None): # Allow to insert rows with cyclic dependencies at once, needs data modell version 1.6.2 https://github.com/QGEP/datamodel/pull/235 to work properly logger.info("SET CONSTRAINTS ALL DEFERRED;") - qgep_session.execute("SET CONSTRAINTS ALL DEFERRED;") + qgep_session.execute(text("SET CONSTRAINTS ALL DEFERRED;")) def get_vl_instance(vl_table, value): """ diff --git a/qgepqwat2ili/qgepdss/import_.py b/qgepqwat2ili/qgepdss/import_.py index bb80eb4d..1bec98e5 100644 --- a/qgepqwat2ili/qgepdss/import_.py +++ b/qgepqwat2ili/qgepdss/import_.py @@ -5,6 +5,7 @@ from geoalchemy2.functions import ST_Force3D from sqlalchemy.orm import Session from sqlalchemy.orm.attributes import flag_dirty +from sqlalchemy.sql import text from .. import utils from ..utils.various import logger @@ -30,7 +31,7 @@ def qgep_import(precommit_callback=None): # We also drop symbology triggers as they badly affect performance. This must be done in a separate session as it # would deadlock other sessions. logger.info("drop symbology triggers") - pre_session.execute("SELECT qgep_sys.drop_symbology_triggers();") + pre_session.execute(text"SELECT qgep_sys.drop_symbology_triggers();")) pre_session.commit() pre_session.close() @@ -44,7 +45,7 @@ def qgep_import(precommit_callback=None): # Allow to insert rows with cyclic dependencies at once, needs data modell version 1.6.2 https://github.com/QGEP/datamodel/pull/235 to work properly logger.info("SET CONSTRAINTS ALL DEFERRED;") - qgep_session.execute("SET CONSTRAINTS ALL DEFERRED;") + qgep_session.execute(text("SET CONSTRAINTS ALL DEFERRED;")) diff --git a/qgepqwat2ili/qgepsia405/import_.py b/qgepqwat2ili/qgepsia405/import_.py index 46900360..d4d385ac 100644 --- a/qgepqwat2ili/qgepsia405/import_.py +++ b/qgepqwat2ili/qgepsia405/import_.py @@ -3,6 +3,7 @@ from geoalchemy2.functions import ST_Force3D from sqlalchemy.orm import Session from sqlalchemy.orm.attributes import flag_dirty +from sqlalchemy.sql import text from .. import utils from ..utils.various import logger @@ -27,7 +28,7 @@ def qgep_import(precommit_callback=None): # We also drop symbology triggers as they badly affect performance. This must be done in a separate session as it # would deadlock other sessions. - pre_session.execute("SELECT qgep_sys.drop_symbology_triggers();") + pre_session.execute(text("SELECT qgep_sys.drop_symbology_triggers();")) pre_session.commit() pre_session.close() @@ -39,7 +40,7 @@ def qgep_import(precommit_callback=None): # Allow to insert rows with cyclic dependencies at once, needs data modell version 1.6.2 https://github.com/QGEP/datamodel/pull/235 to work properly logger.info("SET CONSTRAINTS ALL DEFERRED;") - qgep_session.execute("SET CONSTRAINTS ALL DEFERRED;") + qgep_session.execute(text("SET CONSTRAINTS ALL DEFERRED;")) def get_vl_instance(vl_table, value): """ From 1fa33e10a2562dcd067f1615d98401ea4b92f411 Mon Sep 17 00:00:00 2001 From: Arnaud Poncet-Montanges Date: Fri, 30 Aug 2024 12:14:19 +0200 Subject: [PATCH 2/2] Fix typo on import.py Fix typo --- qgepqwat2ili/qgepdss/import_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qgepqwat2ili/qgepdss/import_.py b/qgepqwat2ili/qgepdss/import_.py index 1bec98e5..27b1cece 100644 --- a/qgepqwat2ili/qgepdss/import_.py +++ b/qgepqwat2ili/qgepdss/import_.py @@ -31,7 +31,7 @@ def qgep_import(precommit_callback=None): # We also drop symbology triggers as they badly affect performance. This must be done in a separate session as it # would deadlock other sessions. logger.info("drop symbology triggers") - pre_session.execute(text"SELECT qgep_sys.drop_symbology_triggers();")) + pre_session.execute(text("SELECT qgep_sys.drop_symbology_triggers();")) pre_session.commit() pre_session.close()