[QGIS-Developer] pyqgis: no update data into table sqlite !

Enzo Cocca enzo.ccc at gmail.com
Tue May 4 10:59:37 PDT 2021


Hi people:
I'm trying to update an table sqlite not geometric but the update does not
take place.

this is my code:

def convert_table(self):
        cfg_rel_path = os.path.join(os.sep, 'HFF_DB_folder', 'config.cfg')
        file_path = '{}{}'.format(self.HOME, cfg_rel_path)
        conf = open(file_path, "r")
        con_sett = conf.read()
        conf.close()
        settings = Settings(con_sett)
        settings.set_configuration()
        if settings.SERVER == 'sqlite':
            sqliteDB_path = os.path.join(os.sep, 'HFF_DB_folder',
settings.DATABASE)
            db_file_path = '{}{}'.format(self.HOME, sqliteDB_path)
            uri = QgsDataSourceUri()
            uri.setDatabase(db_file_path)
            uri.setDataSource('','eamena_table', None,'')
            layerEamena=QgsVectorLayer(uri.uri(), 'eamena_table',
'spatialite')
            QgsProject.instance().addMapLayers([layerEamena], True)
            layer =
QgsProject.instance().mapLayersByName('eamena_table')[0]
            with edit(layer):
                for feat in layer.getFeatures():
                    a=str(feat['assessment_investigator_actor'])
                    if "[['" not in a and a!='NULL':
                        t=a.replace(a[0],"[['"+a[0]).replace("|","'],
['").replace(a[-1],a[-1]+"']]")
            layer.updateFeature(feat)
        QgsProject.instance().removeMapLayer(layer.id())

If I print the results it's ok but into table doesn't update.
Some one has some suggestions?

Best
E

-- 
Enzo Cocca PhD
in "Science and Technology for Archaeology and Cultural Heritage"

ISMEO
International Association of Mediterranean and Oriental Studies


mail: enzo.ccc at gmail.com
cell: +393495087014
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210504/ec04cc16/attachment-0001.html>


More information about the QGIS-Developer mailing list