Exemplo n.º 1
0
 def update_database_version(
         connection: QgsAbstractDatabaseProviderConnection,
         plugin_version: str):
     """ Update the database version. """
     sql = ("UPDATE {}.qgis_plugin "
            "SET (version, version_date) = ( '{}', now()::timestamp(0) );".
            format(SCHEMA, plugin_version))
     try:
         connection.executeSql(sql)
     except QgsProviderConnectionException as e:
         raise QgsProcessingException(str(e))
Exemplo n.º 2
0
    def vacuum_all_tables(connection: QgsAbstractDatabaseProviderConnection,
                          feedback: QgsProcessingFeedback):
        """ Execute a vacuum to recompute the feature count. """
        for table in connection.tables('lizsync'):

            if table.tableName().startswith('v_'):
                # We can't vacuum a view
                continue

            sql = 'VACUUM ANALYSE {}.{};'.format('lizsync', table.tableName())
            feedback.pushDebugInfo(sql)
            try:
                connection.executeSql(sql)
            except QgsProviderConnectionException as e:
                feedback.reportError(str(e))
Exemplo n.º 3
0
 def database_version(
         connection: QgsAbstractDatabaseProviderConnection) -> str:
     """ Get database version. """
     sql = ("SELECT version "
            "FROM {}.qgis_plugin "
            "WHERE status = 1 "
            "ORDER BY version_date DESC "
            "LIMIT 1;").format(SCHEMA)
     try:
         data = connection.executeSql(sql)
     except QgsProviderConnectionException as e:
         raise QgsProcessingException(str(e))
     db_version = None
     for row in data:
         db_version = row[0]
     if not db_version:
         error_message = tr("No version has been found in the database !")
         raise QgsProcessingException(error_message)
     return db_version