[Qgis-user] Doubt with qgis_projects table
Jorge Lopez
jorgelopez.physics at gmail.com
Mon Feb 13 10:25:18 PST 2023
HI Jurgen
Thanks a lot for the answer, I will have to deep on this because I tried
but it seems that I am not updating the data by replacing <old_database>
with <new database>
That is what I did,
for m in iz.namelist():
data = iz.read(m)
print(type(data))
if m.endswith(".qgs"):
data = data.decode('UTF-8')
print(type(data))
# modify projects XML in data
data2 = data.replace('nbi_test', 'nbi_testings_12_02_2023')
print(data2)
oz.writestr(m, data2.encode("UTF-8"))
else:
oz.writestr(m, data)
It seems that when I did in console, the data is replaced but then when
execute this
q.prepare("UPDATE adare_prod.qgis_projects SET
content=:content,metadata=:metadata WHERE name=:name")
v = QByteArray(outzip.getvalue())
q.bindValue(":content", v, QSql.In | QSql.Binary)
q.bindValue(":metadata", metadata)
q.bindValue(":name", name)
q.exec_()
answer is True (more than once QGIS crashed) but then after reoening again,
it still remains the same
Thanks you again
On Sun, Feb 12, 2023 at 7:09 PM Jürgen E. Fischer via QGIS-User <
qgis-user at lists.osgeo.org> wrote:
> Hi Jorge,
>
> On Sun, 12. Feb 2023 at 17:18:20 +0000, Jorge Lopez via QGIS-User wrote:
> > What I presume is that I need the way that column was generated, Martin
> > Dobias created this in the core qgis and maybe he can provide some light
> on
> > this.
>
> The content column contains the qgz file. To decode and update it you
> could do
> something like this:
>
> from PyQt5.QtCore import QByteArray
> from PyQt5.QtSql import QSqlDatabase, QSqlQuery, QSql
> from io import BytesIO
> from zipfile import ZipFile, ZIP_DEFLATED
>
> db = QSqlDatabase.addDatabase("QPSQL")
> db.setConnectOptions("service=…")
> db.open()
>
> q = QSqlQuery(db)
> q.exec_("SELECT content,metadata,name FROM qgis_projects WHERE
> name='project-name'")
> q.next()
>
> inzip = BytesIO(q.value(0))
> outzip = BytesIO()
>
> metadata = q.value(1)
> name = q.value(2)
>
> iz = ZipFile(inzip)
> oz = ZipFile(outzip, mode='w', compression=ZIP_DEFLATED)
>
> for m in iz.namelist():
> data = iz.read(m)
> if m.endswith(".qgs"):
> data = data.decode('UTF-8')
>
> # modify projects XML in data
>
> oz.writestr(m, data.encode("UTF-8"))
> else:
> oz.writestr(m, data)
>
> oz.close()
>
> q.prepare("UPDATE qgis_projects SET content=:content,metadata=:metadata
> WHERE name=:name")
> v = QByteArray(outzip.getvalue())
> q.bindValue(":content", v, QSql.In | QSql.Binary)
> q.bindValue(":metadata", metadata)
> q.bindValue(":name", name)
> q.exec_()
>
>
> Jürgen
>
> --
> Jürgen E. Fischer norBIT GmbH Tel. +49-4931-918175-31
> Dipl.-Inf. (FH) Rheinstraße 13 Fax. +49-4931-918175-50
> Software Engineer D-26506 Norden
> https://www.norbit.de
> QGIS release manager (PSC) Germany IRC: jef on Libera|OFTC
> _______________________________________________
> QGIS-User mailing list
> QGIS-User at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
--
=========================================
Jorge López Pérez
*Web/GIS programmer*
webpage.: http://jorgelopezph.herokuapp.com
mobile: +34 606 98 70 84
skype: jorgelopez.ph
=========================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20230213/d19c7031/attachment.htm>
More information about the QGIS-User
mailing list