Class: QgsDataSourceUri¶
- class qgis.core.QgsDataSourceUri¶
Bases:
sip.wrapper
Class for storing the component parts of a RDBMS data source URI (e.g. a Postgres data source).
This structure stores the database connection information, including host, database, user name, password, schema, password, and SQL where clause.
QgsDataSourceUri()
QgsDataSourceUri(uri: str) Constructor for
QgsDataSourceUri
which parses an inputuri
string.QgsDataSourceUri(
QgsDataSourceUri
)Methods
Returns any associated authentication configuration ID stored in the URI.
Clears the schema stored in the URI.
Returns the connection part of the URI.
Returns the database name stored in the URI.
Decodes SSL mode string into enum value.
Set to
True
to disable selection by feature ID.Returns the driver name stored in the URI
Encodes SSL mode enum value into a string.
Returns the complete encoded URI as a byte array.
Returns the name of the geometry column stored in the URI, if set.
Returns
True
if a parameter with the specifiedkey
exists.Returns the host name stored in the URI.
Returns the http header value according to
key
Returns http headers
Returns the name of the (primary) key column for the referenced table.
Returns a generic parameter value corresponding to the specified
key
.Returns parameter keys used in the uri: specialized ones ("table", "schema", etc.) or generic parameters.
Returns multiple generic parameter values corresponding to the specified
key
.Returns the password stored in the URI.
Returns the port stored in the URI.
Returns the URI's table name, escaped and quoted.
Removes a generic parameter by
key
.Removes the password element from a URI.
Returns the schema stored in the URI.
Returns whether the selection by feature ID is disabled.
Returns the service name associated with the URI.
Sets the authentication configuration ID for the URI.
Sets all connection related members at once.
Sets all data source related members at once.
Sets the URI database name.
Sets the
driver
name stored in the URI.Sets the complete encoded
uri
from a string value.Sets geometry column name to
geometryColumn
Sets headers to
headers
Sets the name of the (primary) key
column
.Sets a generic parameter
value
on the URI.Sets a generic parameter list
value
on the URI.Sets the
password
for the URI.Sets the
scheme
for the URI.Sets the
sql
filter for the URI.Sets the spatial reference ID associated with the URI.
Sets table to
table
Sets whether estimated metadata should be used for the connection.
Sets the
username
for the URI.Sets the WKB
type
associated with the URI.Returns the SQL filter stored in the URI, if set.
Returns the spatial reference ID associated with the URI.
Returns the SSL mode associated with the URI.
Returns the table name stored in the URI.
Returns the complete URI as a string.
Returns
True
if estimated metadata should be used for the connection.Returns the username stored in the URI.
Returns the WKB type associated with the URI.
Attributes
- SslAllow = 2¶
- SslDisable = 1¶
- class SslMode¶
Bases:
int
- baseClass¶
alias of
QgsDataSourceUri
- SslPrefer = 0¶
- SslRequire = 3¶
- SslVerifyCa = 4¶
- SslVerifyFull = 5¶
- authConfigId(self) str ¶
Returns any associated authentication configuration ID stored in the URI.
- Return type:
str
- clearSchema(self)¶
Clears the schema stored in the URI.
- connectionInfo(self, expandAuthConfig: bool = True) str ¶
Returns the connection part of the URI.
- Parameters:
expandAuthConfig (bool = True) –
- Return type:
str
- database(self) str ¶
Returns the database name stored in the URI.
- 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:
- disableSelectAtId(self, flag: bool)¶
Set to
True
to disable selection by feature ID.- Parameters:
flag (bool) –
- driver(self) str ¶
Returns the driver name stored in the URI
New in version 2.16.
- 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 the complete encoded URI as a byte array.
- Return type:
QByteArray
- geometryColumn(self) str ¶
Returns the name of the geometry column stored in the URI, if set.
- Return type:
str
- hasParam(self, key: str) bool ¶
Returns
True
if a parameter with the specifiedkey
exists.- Parameters:
key (str) –
- Return type:
bool
- host(self) str ¶
Returns the host name stored in the URI.
- Return type:
str
- httpHeader(self, key: str) str ¶
Returns the http header value according to
key
New in version 3.26.
- Parameters:
key (str) –
- Return type:
str
- httpHeaders(self) QgsHttpHeaders ¶
Returns http headers
New in version 3.26.
- Return type:
- keyColumn(self) str ¶
Returns the name of the (primary) key column for the referenced table.
- Return type:
str
- param(self, key: str) str ¶
Returns a generic parameter value corresponding to the specified
key
.- Parameters:
key (str) –
- Return type:
str
- parameterKeys(self) Set[str] ¶
Returns parameter keys used in the uri: specialized ones (“table”, “schema”, etc.) or generic parameters.
New in version 3.26.
- Return type:
Set[str]
- params(self, key: str) List[str] ¶
Returns multiple generic parameter values corresponding to the specified
key
.- Parameters:
key (str) –
- Return type:
List[str]
- password(self) str ¶
Returns the password stored in the URI.
- Return type:
str
- port(self) str ¶
Returns the port stored in the URI.
- Return type:
str
- quotedTablename(self) str ¶
Returns the URI’s table name, escaped and quoted.
- Return type:
str
- removeParam(self, key: str) int ¶
Removes a generic parameter by
key
.Note
Calling this method removes all the occurrences of key, and returns the number of parameters removed.
- Parameters:
key (str) –
- Return type:
int
- removePassword(aUri: str, hide: bool = False) str ¶
Removes the password element from a URI.
- Parameters:
aUri (str) – A data source uri
hide (bool = False) –
True
to replace the password value with ‘xxxxxxxx’,False
to remove password (key and value) (since QGIS 3.34)
- Return type:
str
- Returns:
The data source uri without the password
- schema(self) str ¶
Returns the schema stored in the URI.
- Return type:
str
- selectAtIdDisabled(self) bool ¶
Returns whether the selection by feature ID is disabled.
- Return type:
bool
- service(self) str ¶
Returns the service name associated with the URI.
- Return type:
str
- setAuthConfigId(self, authcfg: str)¶
Sets the authentication configuration ID for the URI.
- 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 a 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.
The
aSql
argument represents a subset filter string to be applied to the source, and should take the form of a SQL “where” clause (e.g. “VALUE > 5”, “CAT IN (1,2,3)”).- Parameters:
aSchema (str) –
aTable (str) –
aGeometryColumn (str) –
aSql (str = '') –
aKeyColumn (str = '') –
- setDatabase(self, database: str)¶
Sets the URI database name.
- Parameters:
database (str) –
- setDriver(self, driver: str)¶
Sets the
driver
name stored in the URI.New in version 2.16.
- Parameters:
driver (str) –
- setEncodedUri(self, uri: str)¶
Sets the complete encoded
uri
from a string value.- Parameters:
uri (str) –
- setGeometryColumn(self, geometryColumn: str)¶
Sets geometry column name to
geometryColumn
New in version 3.10.
- Parameters:
geometryColumn (str) –
- setHttpHeaders(self, headers: QgsHttpHeaders)¶
Sets headers to
headers
New in version 3.26.
- Parameters:
headers (QgsHttpHeaders) –
- setKeyColumn(self, column: str)¶
Sets the name of the (primary) key
column
.- Parameters:
column (str) –
- setParam(self, key: str, value: str)¶
Sets a generic parameter
value
on the URI.Note
If a parameter with the specified
key
already exists, another is inserted and the existing value is left unchanged.- Parameters:
key (str) –
value (str) –
- setParamList(self, key: str, value: Iterable[str])¶
Sets a generic parameter list
value
on the URI.Note
available in Python as setParamList
- Parameters:
key (str) –
value (Iterable[str]) –
- setPassword(self, password: str)¶
Sets the
password
for the URI.- Parameters:
password (str) –
- setSchema(self, schema: str)¶
Sets the
scheme
for the URI.New in version 2.12.
- Parameters:
schema (str) –
- setSql(self, sql: str)¶
Sets the
sql
filter for the URI.The
sql
represents a subset filter string to be applied to the source, and should take the form of a SQL “where” clause (e.g. “VALUE > 5”, “CAT IN (1,2,3)”).See also
- Parameters:
sql (str) –
- setSrid(self, srid: str)¶
Sets the spatial reference ID associated with the URI.
- Parameters:
srid (str) –
- setTable(self, table: str)¶
Sets table to
table
New in version 3.10.
- Parameters:
table (str) –
- setUseEstimatedMetadata(self, flag: bool)¶
Sets whether estimated metadata should be used for the connection.
- Parameters:
flag (bool) –
- setUsername(self, username: str)¶
Sets the
username
for the URI.- Parameters:
username (str) –
- setWkbType(self, type: Qgis.WkbType)¶
Sets the WKB
type
associated with the URI.- Parameters:
type (Qgis.WkbType) –
- sql(self) str ¶
Returns the SQL filter stored in the URI, if set.
This represents a subset filter string to be applied to the source, and takes the form of a SQL “where” clause (e.g. “VALUE > 5”, “CAT IN (1,2,3)”).
See also
- Return type:
str
- srid(self) str ¶
Returns the spatial reference ID associated with the URI.
- Return type:
str
- sslMode(self) QgsDataSourceUri.SslMode ¶
Returns the SSL mode associated with the URI.
- Return type:
- staticMetaObject = <PyQt5.QtCore.QMetaObject object>¶
- table(self) str ¶
Returns the table name stored in the URI.
- Return type:
str
- uri(self, expandAuthConfig: bool = True) str ¶
Returns the complete URI as a string.
- Parameters:
expandAuthConfig (bool = True) –
- Return type:
str
- useEstimatedMetadata(self) bool ¶
Returns
True
if estimated metadata should be used for the connection.- Return type:
bool
- username(self) str ¶
Returns the username stored in the URI.
- Return type:
str
- wkbType(self) Qgis.WkbType ¶
Returns the WKB type associated with the URI.
- Return type: