Class: QgsAbstractDatabaseProviderConnection

class qgis.core.QgsAbstractDatabaseProviderConnection(name: str)

Bases: qgis._core.QgsAbstractProviderConnection

Creates a new connection with name by reading its configuration from the settings. If a connection with this name cannot be found, an empty connection will be returned.

QgsAbstractDatabaseProviderConnection(name: str, uri: str) Creates a new connection with name and initializes the connection from the uri. The connection is not automatically stored in the settings.

See also

store()

QgsAbstractDatabaseProviderConnection(QgsAbstractDatabaseProviderConnection)

The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connections.

This class performs low level DB operations without asking the user for confirmation or handling currently opened layers and the registry entries, it is responsibility of the client code to keep layers in sync. The class methods will throw exceptions in case the requested operation is not supported or cannot be performed without errors.

New in version 3.10: Enums

Methods

capabilities

Returns connection capabilities

checkCapability

Checks if capability is supported and throws and exception if it’s not

createSchema

Creates a new schema with the specified name

createVectorTable

Creates an empty table with name in the given schema (schema is ignored if not supported by the backend).

dropRasterTable

Drops a raster table with given schema (schema is ignored if not supported by the backend) and name.

dropSchema

Drops an entire schema with the specified name.

dropVectorTable

Drops a vector (or aspatial) table with given schema (schema is ignored if not supported by the backend) and name.

executeSql

Executes raw sql and returns the (possibly empty) list of results in a multi-dimensional array.

renameRasterTable

Renames a raster table with given schema (schema is ignored if not supported by the backend) and name.

renameSchema

Renames a schema with the specified name.

renameVectorTable

Renames a vector or aspatial table with given schema (schema is ignored if not supported by the backend) and name.

schemas

Returns information about the existing schemas.

tableExists

Checks whether a table name exists in the given schema.

tables

Returns information on the tables in the given schema.

vacuum

Vacuum the database table with given schema and name (schema is ignored if not supported by the backend).

Signals

Attributes

Aspatial

CreateSchema

CreateVectorTable

DropRasterTable

DropSchema

DropVectorTable

ExecuteSql

MaterializedView

Raster

RenameRasterTable

RenameSchema

RenameVectorTable

Schemas

Spatial

SqlLayers

TableExists

Tables

Vacuum

Vector

View

staticMetaObject

Aspatial = 2
class Capabilities

Bases: sip.wrapper

QgsAbstractDatabaseProviderConnection.Capabilities(Union[QgsAbstractDatabaseProviderConnection.Capabilities, QgsAbstractDatabaseProviderConnection.Capability]) QgsAbstractDatabaseProviderConnection.Capabilities(QgsAbstractDatabaseProviderConnection.Capabilities)

baseClass

alias of QgsAbstractDatabaseProviderConnection

class Capability

Bases: int

baseClass

alias of QgsAbstractDatabaseProviderConnection

CreateSchema = 64
CreateVectorTable = 2
DropRasterTable = 4
DropSchema = 128
DropVectorTable = 8
ExecuteSql = 512
MaterializedView = 32
Raster = 8
RenameRasterTable = 32
RenameSchema = 256
RenameVectorTable = 16
Schemas = 4096
Spatial = 32768
SqlLayers = 8192
TableExists = 16384
class TableFlag

Bases: int

class TableFlags

Bases: sip.wrapper

QgsAbstractDatabaseProviderConnection.TableFlags(Union[QgsAbstractDatabaseProviderConnection.TableFlags, QgsAbstractDatabaseProviderConnection.TableFlag]) QgsAbstractDatabaseProviderConnection.TableFlags(QgsAbstractDatabaseProviderConnection.TableFlags)

baseClass

alias of QgsAbstractDatabaseProviderConnection

class TableProperty

Bases: sip.wrapper

QgsAbstractDatabaseProviderConnection.TableProperty(QgsAbstractDatabaseProviderConnection.TableProperty)

class GeometryColumnType

Bases: sip.wrapper

QgsAbstractDatabaseProviderConnection.TableProperty.GeometryColumnType(QgsAbstractDatabaseProviderConnection.TableProperty.GeometryColumnType)

crs
wkbType
addGeometryColumnType(self, type: QgsWkbTypes.Type, crs: QgsCoordinateReferenceSystem)

Appends the geometry column type with the given srid to the geometry column types list

at(self, index: int) → QgsAbstractDatabaseProviderConnection.TableProperty

Returns the table property corresponding to the geometry type at the given index

comment(self) → str

Returns the table comment

crsList(self) → List[QgsCoordinateReferenceSystem]

Returns the list of CRSs supported by the geometry column

defaultName(self) → str

Returns the default name for the table entry

It is usually the table name but in case there are multiple geometry columns, the geometry column name is appendend to the table name.

flags(self) → QgsAbstractDatabaseProviderConnection.TableFlags

Returns the table flags

geometryColumn(self) → str

Returns the geometry column name

geometryColumnCount(self) → int

Returns the number of geometry columns in the original table this entry refers to

This information is used internally to build the defaultName()

geometryColumnTypes(self) → List[QgsAbstractDatabaseProviderConnection.TableProperty.GeometryColumnType]

Returns the list of geometry column types and CRSs. The method returns a list of GeometryColumnType

info(self) → Dict[str, Any]

Returns additional information about the table

Provider classes may use this property to store custom bits of information.

maxCoordinateDimensions(self) → int

Returns the maximum coordinate dimensions of the geometries of a vector table. This information is calculated from the geometry columns types.

primaryKeyColumns(self) → List[str]

Returns the list of primary key column names

schema(self) → str

Returns the schema or an empty string for backends that do not support a schema

setComment(self, comment: str)

Sets the table comment

setFlag(self, flag: QgsAbstractDatabaseProviderConnection.TableFlag)

Sets a flag

setFlags(self, flags: Union[QgsAbstractDatabaseProviderConnection.TableFlags, QgsAbstractDatabaseProviderConnection.TableFlag])

Sets the table flags

setGeometryColumn(self, geometryColumn: str)

Sets the geometry column name to geometryColumn

setGeometryColumnCount(self, geometryColumnCount: int)

Sets the geometryColumnCount

setGeometryColumnTypes(self, geometryColumnTypes: Iterable[QgsAbstractDatabaseProviderConnection.TableProperty.GeometryColumnType])

Sets the geometry column types to geometryColumnTypes

setInfo(self, info: Dict[str, Any])

Sets additional information about the table to info

Provider classes may use this property to store custom bits of information.

setPrimaryKeyColumns(self, primaryKeyColumns: Iterable[str])

Sets the primary key column names to primaryKeyColumns

setSchema(self, schema: str)

Sets the schema

setTableName(self, name: str)

Sets the table name to name

See also

defaultName()

tableName(self) → str

Returns the table name

See also

defaultName()

Tables = 2048
Vacuum = 1024
Vector = 4
View = 16
capabilities(self) → QgsAbstractDatabaseProviderConnection.Capabilities

Returns connection capabilities

checkCapability(self, capability: QgsAbstractDatabaseProviderConnection.Capability)

Checks if capability is supported and throws and exception if it’s not

Raises

: – py:class:QgsProviderConnectionException

createSchema(self, name: str)

Creates a new schema with the specified name

Raises

: – py:class:QgsProviderConnectionException

createVectorTable(self, schema: str, name: str, fields: QgsFields, wkbType: QgsWkbTypes.Type, srs: QgsCoordinateReferenceSystem, overwrite: bool, options: Dict[str, Any])

Creates an empty table with name in the given schema (schema is ignored if not supported by the backend). Raises a QgsProviderConnectionException if any errors are encountered.

Raises

: – py:class:QgsProviderConnectionException

dropRasterTable(self, schema: str, name: str)

Drops a raster table with given schema (schema is ignored if not supported by the backend) and name. Raises a QgsProviderConnectionException if any errors are encountered.

Note

it is responsibility of the caller to handle open layers and registry entries.

Raises

: – py:class:QgsProviderConnectionException

dropSchema(self, name: str, force: bool = False)

Drops an entire schema with the specified name. Raises a QgsProviderConnectionException if any errors are encountered.

Parameters
  • name – name of the schema to be dropped

  • force – if True, a DROP CASCADE will drop all related objects

Note

it is responsibility of the caller to handle open layers and registry entries.

Raises

: – py:class:QgsProviderConnectionException

dropVectorTable(self, schema: str, name: str)

Drops a vector (or aspatial) table with given schema (schema is ignored if not supported by the backend) and name. Raises a QgsProviderConnectionException if any errors are encountered.

Note

it is responsibility of the caller to handle open layers and registry entries.

Raises

: – py:class:QgsProviderConnectionException

executeSql(self, sql: str) → object

Executes raw sql and returns the (possibly empty) list of results in a multi-dimensional array. Raises a QgsProviderConnectionException if any errors are encountered.

Raises

: – py:class:QgsProviderConnectionException

renameRasterTable(self, schema: str, name: str, newName: str)

Renames a raster table with given schema (schema is ignored if not supported by the backend) and name. Raises a QgsProviderConnectionException if any errors are encountered.

Note

it is responsibility of the caller to handle open layers and registry entries.

Raises

: – py:class:QgsProviderConnectionException

renameSchema(self, name: str, newName: str)

Renames a schema with the specified name. Raises a QgsProviderConnectionException if any errors are encountered.

Note

it is responsibility of the caller to handle open layers and registry entries.

Raises

: – py:class:QgsProviderConnectionException

renameVectorTable(self, schema: str, name: str, newName: str)

Renames a vector or aspatial table with given schema (schema is ignored if not supported by the backend) and name. Raises a QgsProviderConnectionException if any errors are encountered.

Note

it is responsibility of the caller to handle open layers and registry entries.

Raises

: – py:class:QgsProviderConnectionException

schemas(self) → List[str]

Returns information about the existing schemas. Raises a QgsProviderConnectionException if any errors are encountered.

Raises

: – py:class:QgsProviderConnectionException

staticMetaObject = <PyQt5.QtCore.QMetaObject object>
tableExists(self, schema: str, name: str) → bool

Checks whether a table name exists in the given schema. Raises a QgsProviderConnectionException if any errors are encountered.

Raises

: – py:class:QgsProviderConnectionException

tables(self, schema: str = '', flags: int = 0) → List[QgsAbstractDatabaseProviderConnection.TableProperty]

Returns information on the tables in the given schema. Raises a QgsProviderConnectionException if any errors are encountered.

Parameters
  • schema – name of the schema (ignored if not supported by the backend)

  • flags – filter tables by flags, this option completely overrides search options stored in the connection

Raises

: – py:class:QgsProviderConnectionException

vacuum(self, schema: str, name: str)

Vacuum the database table with given schema and name (schema is ignored if not supported by the backend). Raises a QgsProviderConnectionException if any errors are encountered.

Raises

: – py:class:QgsProviderConnectionException