Class: QgsAuxiliaryStorage

Providing some utility methods to manage auxiliary storage.

Methods

createAuxiliaryLayer

Creates an auxiliary layer for a vector layer.

currentFileName

Returns the path of the current database used.

errorString

Returns the underlying error string describing potential errors happening in saveAs().

fileName

Returns the target filename of the database.

isValid

Returns the status of the auxiliary storage currently defined.

save

Saves the current database.

saveAs

Saves the current database to a new path.

Static Methods

deleteTable

Removes a table from the auxiliary storage.

duplicateTable

Duplicates a table and its content.

exists

Returns True if the auxiliary database yet exists for a project, False otherwise.

extension

Returns the extension used for auxiliary databases.

class qgis.core.QgsAuxiliaryStorage[source]

Bases: object

__init__(project: QgsProject, copy: bool = True)

Constructor.

The project filename is used to build a database path at the same location, but with a different extension. Then, it’s the same logic as described for QgsAuxiliaryStorage.

Parameters:
  • project (QgsProject) – The project for which the auxiliary storage has to be used

  • copy (bool = True) – Parameter indicating if a copy of the database has to be used

__init__(filename: str | None = '', copy: bool = True)

Constructor.

If a valid database path is given in parameter and copy mode is deactivated, then every changes is directly committed on the original database. But if the copy mode is activated, then changes are committed on a copy of the database (a temporary file) and a save action is therefore necessary to keep modifications in the original file.

If an empty string for the database path is given in parameter, then a database is created in a temporary file whatever the copy mode.

If the database path given in parameter is not empty but does not exist, then a database is created at this location when copy mode is deactivated. When copy mode is activated, a temporary database is used instead and a save action will be necessary to create the database at the original location given in parameter.

Parameters:
  • filename (Optional[str] = '') – The path of the database

  • copy (bool = True) – Parameter indicating if a copy of the database has to be used

__init__(a0: QgsAuxiliaryStorage)
Parameters:

a0 (QgsAuxiliaryStorage)

createAuxiliaryLayer(self, field: QgsField, layer: QgsVectorLayer | None) QgsAuxiliaryLayer | None[source]

Creates an auxiliary layer for a vector layer. A new table is created if necessary. The primary key to use to construct the auxiliary layer is given in parameter.

Parameters:
  • field (QgsField) – The primary key to join

  • layer (Optional[QgsVectorLayer]) – The vector layer for which the auxiliary layer has to be created

Return type:

Optional[QgsAuxiliaryLayer]

Returns:

A new auxiliary layer or None if an error happened.

currentFileName(self) str[source]

Returns the path of the current database used. It may be different from the target filename if the auxiliary storage is opened in copy mode.

Return type:

str

static deleteTable(uri: QgsDataSourceUri) bool[source]

Removes a table from the auxiliary storage.

Parameters:

uri (QgsDataSourceUri) – The uri of the table to remove

Return type:

bool

Returns:

True if the table is well deleted, False otherwise

static duplicateTable(uri: QgsDataSourceUri, newTable: str | None) bool[source]

Duplicates a table and its content.

Parameters:
  • uri (QgsDataSourceUri) – The uri of the table to duplicate

  • newTable (Optional[str]) – The name of the new table

Return type:

bool

Returns:

True if the table is well duplicated, False otherwise

errorString(self) str[source]

Returns the underlying error string describing potential errors happening in saveAs(). Empty by default.

Added in version 3.4.

Return type:

str

static exists(project: QgsProject) bool[source]

Returns True if the auxiliary database yet exists for a project, False otherwise.

Parameters:

project (QgsProject) – The project for which the database is checked

Added in version 3.2.

Return type:

bool

static extension() str[source]

Returns the extension used for auxiliary databases.

Return type:

str

fileName(self) str[source]

Returns the target filename of the database.

Return type:

str

isValid(self) bool[source]

Returns the status of the auxiliary storage currently defined.

Return type:

bool

Returns:

True if the auxiliary storage is valid, False otherwise

save(self) bool[source]

Saves the current database.

Return type:

bool

Returns:

True if everything is saved, False otherwise

saveAs(self, filename: str | None) bool[source]

Saves the current database to a new path.

Return type:

bool

Returns:

True if everything is saved, False otherwise

Parameters:

filename (Optional[str])

saveAs(self, project: QgsProject) bool[source]

Saves the current database to a new path for a specific project. Actually, the current filename of the project is used to deduce the path of the database to save.

Return type:

bool

Returns:

True if everything is saved, False otherwise

Parameters:

project (QgsProject)