metadata DB IO implementation.
Class for doing metadata read/write operations on the local DB
The local sqlite db is used for supporting metadata for remote datasources.
New in version 3.2.
Check if metadata should be read/written to file or our metadata db.
Determine which metadata lookup system to use (file base or cache db) based on the layer’s provider type. True indicates we should use the datasource as a file and look for a metadata file, False and we look in the metadata db.
|Parameters:||layer (QgsMapLayer) – The layer which want to know how the metadata are stored.|
|Returns:||True if metadata are stored in a file next to the dataset, else False if the dataset is remove e.g. a database.|
Close the active sqlite3 connection.
Helper to get the default path for the metadata file.
|Returns:||The path to where the default location of the metadata database is. Maps to which is ~/.inasafe/metadata.db|
Delete metadata for a URI in the metadata database.
A hash will be constructed from the supplied uri and a lookup made in a local SQLITE database for the metadata. If there is an existing record for the hash, the entire record will be erased.
|Parameters:||uri (str) – A layer uri. e.g. `dbname='osm' host=localhost port=5432 user='foo'password='bar' sslmode=disable key='id' srid=4326`|
Get a cursor for the active connection.
The cursor can be used to execute arbitrary queries against the database. This method also checks that the metadata table exists in the schema, and if not, it creates it.
|Returns:||A valid cursor opened against the connection.|
|Raises:||An sqlite.Error will be raised if anything goes wrong.|
Given a data_source, return its hash.
|Parameters:||data_source (str) – The data_source name from a layer.|
|Returns:||An md5 hash for the data source name.|
Open an sqlite connection to the metadata database.
By default the metadata database will be used in the plugin dir, unless an explicit path has been set using setmetadataDbPath, or overridden in QSettings. If the db does not exist it will be created.
|Raises:||An sqlite.Error is raised if anything goes wrong|
Try to get metadata from the DB entry associated with a URI.
This is used for layers that are non local layer (e.g. postgresql connection) and so we need to retrieve the metadata from the sqlite metadata db.
A hash will be constructed from the supplied uri and a lookup made in a local SQLITE database for the metadata. If there is an existing record it will be returned, if not and error will be thrown.
A string containing the retrieved metadata
metadataNotFoundError if the metadata is not found.
Set the path for the metadata database (sqlite).
The file will be used to search for metadata for non local datasets.
|Parameters:||path (str) – A valid path to a sqlite database. The database does not need to exist already, but the user should be able to write to the path provided.|
Helper to set the active path for the metadata.
Called at init time, you can override this path by calling set_metadata_db_path.setmetadataDbPath.
|Returns:||The path to where the metadata file is. If the user has never specified what this path is, the defaultmetadataDbPath is returned.|
Write metadata for a URI into the metadata database. All the metadata for the uri should be written in a single operation. A hash will be constructed from the supplied uri and a lookup made in a local SQLite database for the metadata. If there is an existing record it will be updated, if not, a new one will be created.
JSON str). :type json: str
|Parameters:||xml – The metadata to write (which should be provided as a|
XML str). :type xml: str