I tried to create a QGIS action in order to refresh several materialized views at once. for that I wanted to execute a simple loop in my action in order to recover the database where the view will be refreshed at each iteration. I then did an if / else because the path is not the same depending on the database. However, n executing the code in the python console nothing happens, the code is read well, without errors, but it looks like the loop is not executed. when I run a simpler refresh, from a single view the code works, but at the slightest loop nothing, even with a very simple code in the loop. I would like to understand what mistakes I made in this action.
Here is the full action:
import psycopg2
databases = ['RIP_FTTH_17', 'RIP_FTTH_24', 'RIP_FTTH_33', 'RIP_FTTH_40', 'RIP_FTTH_47', 'RIP_FTTH_79', 'CEM_ORANGE', 'AMEL_47']
for db in databases:
conn = psycopg2.connect(dbname=db,user="postgres",password="INEO_Infracom_33",host="bordeaux04")
cur = conn.cursor()
if db not in ['CEM_ORANGE', 'AMEL_47']:
sql = "REFRESH MATERIALIZED VIEW genie_civil.vm_appui_avancement;"
else:
sql = "REFRESH MATERIALIZED VIEW geofibre_cem.vm_appui_avancement;"
cur.execute(sql)
iface.messageBar().pushMessage("Success ", " Mise à jour reussie !")
conn.commit()
cur.close()
conn.close()
here's the action with a simpler loop that doesn't work either:
import psycopg2
databases = ["RIP_FTTH_17", "RIP_FTTH_24", "RIP_FTTH_33", "RIP_FTTH_40", "RIP_FTTH_47", "RIP_FTTH_79", "CEM_ORANGE", "AMEL_47"]
for db in databases:
conn = psycopg2.connect(dbname="RIP_FTTH_17",user="postgres",password="INEO_Infracom_33",host="bordeaux04")
cur = conn.cursor()
sql = "REFRESH MATERIALIZED VIEW genie_civil.vm_appui_avancement;"
cur.execute(sql)
iface.messageBar().pushMessage("Success ", " Mise à jour reussie !")
conn.commit()
cur.close()
conn.close()