Class: QgsDataSourceUri

class qgis.core.QgsDataSourceUri

Bases: sip.wrapper

default constructor

QgsDataSourceUri(uri: str) constructor which parses input URI

QgsDataSourceUri(QgsDataSourceUri)

Methods

authConfigId

Any associated authentication configuration ID

clearSchema

Clears the schema

connectionInfo

Returns connection part of URI

database

Returns the database

decodeSslMode

Decodes SSL mode string into enum value.

disableSelectAtId

Sets to true to disable selection by id

driver

rtype

str

encodeSslMode

Encodes SSL mode enum value into a string.

encodedUri

Returns complete encoded uri (generic mode)

geometryColumn

Returns the name of the geometry column

hasParam

Test if param exists (generic mode)

host

Returns the host

keyColumn

Returns the name of the (primary) key column

param

Gets generic param (generic mode)

params

Gets multiple generic param (generic mode)

password

Returns the password

port

Returns the port

quotedTablename

quoted table name

removeParam

Remove generic param (generic mode)

removePassword

Removes password element from uris

schema

Returns the schema

selectAtIdDisabled

Returns whether the selection by id is disabled

service

Returns the service name

setAuthConfigId

Sets authentication configuration ID

setConnection

Sets all connection related members at once

setDataSource

Sets all data source related members at once

setDatabase

Sets database

setDriver

param driver

setEncodedUri

Sets complete encoded uri (generic mode)

setKeyColumn

Sets the name of the (primary) key column

setParam

Set generic param (generic mode)

setParamList

setPassword

Sets password

setSchema

param schema

setSql

Sets the SQL query

setSrid

Sets the srid

setUseEstimatedMetadata

Sets use Estimated Metadata

setUsername

Sets username

setWkbType

Sets the wkb type

sql

Returns the SQL query

srid

Returns the srid

sslMode

Returns the SSL mode

table

Returns the table

uri

Returns complete uri

useEstimatedMetadata

Returns true if estimated metadata are used

username

Returns the username

wkbType

The wkb type.

Attributes

SslAllow

SslDisable

SslPrefer

SslRequire

SslVerifyCa

SslVerifyFull

staticMetaObject

SslAllow = 2
SslDisable = 1
class SslMode

Bases: int

baseClass

alias of QgsDataSourceUri

SslPrefer = 0
SslRequire = 3
SslVerifyCa = 4
SslVerifyFull = 5
authConfigId(self) → str

Any associated authentication configuration ID

Return type

str

clearSchema(self)

Clears the schema

connectionInfo(self, expandAuthConfig: bool = True) → str

Returns connection part of URI

Parameters

expandAuthConfig (bool = True) –

Return type

str

database(self) → str

Returns the database

Return type

str

decodeSslMode(sslMode: str) → QgsDataSourceUri.SslMode

Decodes SSL mode string into enum value. If the string is not recognized, SslPrefer is returned.

New in version 3.2.

Parameters

sslMode (str) –

Return type

QgsDataSourceUri.SslMode

disableSelectAtId(self, flag: bool)

Sets to true to disable selection by id

Parameters

flag (bool) –

driver(self) → str
Return type

str

encodeSslMode(sslMode: QgsDataSourceUri.SslMode) → str

Encodes SSL mode enum value into a string.

New in version 3.2.

Parameters

sslMode (QgsDataSourceUri.SslMode) –

Return type

str

encodedUri(self) → QByteArray

Returns complete encoded uri (generic mode)

Return type

QByteArray

geometryColumn(self) → str

Returns the name of the geometry column

Return type

str

hasParam(self, key: str) → bool

Test if param exists (generic mode)

Parameters

key (str) –

Return type

bool

host(self) → str

Returns the host

Return type

str

keyColumn(self) → str

Returns the name of the (primary) key column

Return type

str

param(self, key: str) → str

Gets generic param (generic mode)

Parameters

key (str) –

Return type

str

params(self, key: str) → List[str]

Gets multiple generic param (generic mode)

Parameters

key (str) –

Return type

List[str]

password(self) → str

Returns the password

Return type

str

port(self) → str

Returns the port

Return type

str

quotedTablename(self) → str

quoted table name

Return type

str

removeParam(self, key: str) → int

Remove generic param (generic mode)

Note

remove all occurrences of key, returns number of params removed

Parameters

key (str) –

Return type

int

removePassword(aUri: str) → str

Removes password element from uris

Parameters

aUri (str) –

Return type

str

schema(self) → str

Returns the schema

Return type

str

selectAtIdDisabled(self) → bool

Returns whether the selection by id is disabled

Return type

bool

service(self) → str

Returns the service name

Return type

str

setAuthConfigId(self, authcfg: str)

Sets authentication configuration ID

Parameters

authcfg (str) –

setConnection(self, aHost: str, aPort: str, aDatabase: str, aUsername: str, aPassword: str, sslmode: QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer, authConfigId: str = '')

Sets all connection related members at once

setConnection(self, aService: str, aDatabase: str, aUsername: str, aPassword: str, sslmode: QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer, authConfigId: str = ‘’) Sets all connection related members at once (for the service case)

Parameters
  • aHost (str) –

  • aPort (str) –

  • aDatabase (str) –

  • aUsername (str) –

  • aPassword (str) –

  • sslmode (QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer) –

  • authConfigId (str = '') –

setDataSource(self, aSchema: str, aTable: str, aGeometryColumn: str, aSql: str = '', aKeyColumn: str = '')

Sets all data source related members at once

Parameters
  • aSchema (str) –

  • aTable (str) –

  • aGeometryColumn (str) –

  • aSql (str = '') –

  • aKeyColumn (str = '') –

setDatabase(self, database: str)

Sets database

Parameters

database (str) –

setDriver(self, driver: str)
Parameters

driver (str) –

setEncodedUri(self, uri: str)

Sets complete encoded uri (generic mode)

Parameters

uri (str) –

setKeyColumn(self, column: str)

Sets the name of the (primary) key column

Parameters

column (str) –

setParam(self, key: str, value: str)

Set generic param (generic mode)

Note

if key exists, another is inserted

Parameters
  • key (str) –

  • value (str) –

setParamList(self, key: str, value: Iterable[str])

Note

available in Python as setParamList

Parameters
  • key (str) –

  • value (Iterable[str]) –

setPassword(self, password: str)

Sets password

Parameters

password (str) –

setSchema(self, schema: str)
Parameters

schema (str) –

setSql(self, sql: str)

Sets the SQL query

Parameters

sql (str) –

setSrid(self, srid: str)

Sets the srid

Parameters

srid (str) –

setUseEstimatedMetadata(self, flag: bool)

Sets use Estimated Metadata

Parameters

flag (bool) –

setUsername(self, username: str)

Sets username

Parameters

username (str) –

setWkbType(self, type: QgsWkbTypes.Type)

Sets the wkb type

Parameters

type (QgsWkbTypes.Type) –

sql(self) → str

Returns the SQL query

Return type

str

srid(self) → str

Returns the srid

Return type

str

sslMode(self) → QgsDataSourceUri.SslMode

Returns the SSL mode

Return type

QgsDataSourceUri.SslMode

staticMetaObject = <PyQt5.QtCore.QMetaObject object>
table(self) → str

Returns the table

Return type

str

uri(self, expandAuthConfig: bool = True) → str

Returns complete uri

Parameters

expandAuthConfig (bool = True) –

Return type

str

useEstimatedMetadata(self) → bool

Returns true if estimated metadata are used

Return type

bool

username(self) → str

Returns the username

Return type

str

wkbType(self) → QgsWkbTypes.Type

The wkb type.

Return type

QgsWkbTypes.Type