Class: QgsDataSourceUri¶
Stores the component parts of a 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.
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. |
|
Set to |
|
Returns the driver name stored in the URI |
|
Returns the complete encoded URI as a byte array. |
|
Returns the name of the geometry column stored in the URI, if set. |
|
Returns |
|
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. |
|
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 the host name stored in the URI. |
|
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 port stored in the URI. |
|
Sets the scheme for the URI. |
|
Sets the service name associated with the URI. |
|
Sets the sql filter for the URI. |
|
Sets the spatial reference ID associated with the URI. |
|
Sets the SSL mode 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 |
|
Returns the username stored in the URI. |
|
Returns the WKB type associated with the URI. |
Static Methods
Decodes SSL mode string into enum value. |
|
Encodes SSL mode enum value into a string. |
|
Removes the password element from a URI. |
Attributes
- class qgis.core.QgsDataSourceUri[source]¶
Bases:
object
- __init__()
- __init__(uri: str | None)
Constructor for QgsDataSourceUri which parses an input
uri
string.- Parameters:
uri (Optional[str])
- __init__(a0: QgsDataSourceUri)
- Parameters:
a0 (QgsDataSourceUri)
- SslAllow = 2¶
- SslDisable = 1¶
- class SslMode¶
Bases:
int
- SslPrefer = 0¶
- SslRequire = 3¶
- SslVerifyCa = 4¶
- SslVerifyFull = 5¶
- authConfigId(self) str [source]¶
Returns any associated authentication configuration ID stored in the URI.
- Return type:
str
- connectionInfo(self, expandAuthConfig: bool = True) str [source]¶
Returns the connection part of the URI.
- Parameters:
expandAuthConfig (bool = True)
- Return type:
str
- static decodeSslMode(sslMode: str | None) QgsDataSourceUri.SslMode [source]¶
Decodes SSL mode string into enum value. If the string is not recognized, SslPrefer is returned.
Added in version 3.2.
- Parameters:
sslMode (Optional[str])
- Return type:
- disableSelectAtId(self, flag: bool)[source]¶
Set to
True
to disable selection by feature ID.- Parameters:
flag (bool)
- static encodeSslMode(sslMode: QgsDataSourceUri.SslMode) str [source]¶
Encodes SSL mode enum value into a string.
Added in version 3.2.
- Parameters:
sslMode (QgsDataSourceUri.SslMode)
- Return type:
str
- encodedUri(self) QByteArray [source]¶
Returns the complete encoded URI as a byte array.
- Return type:
QByteArray
- geometryColumn(self) str [source]¶
Returns the name of the geometry column stored in the URI, if set.
- Return type:
str
- hasParam(self, key: str | None) bool [source]¶
Returns
True
if a parameter with the specifiedkey
exists.- Parameters:
key (Optional[str])
- Return type:
bool
- httpHeader(self, key: str | None) str [source]¶
Returns the http header value according to
key
Added in version 3.26.
- Parameters:
key (Optional[str])
- Return type:
str
- httpHeaders(self) QgsHttpHeaders ¶
Returns http headers
Added in version 3.26.
- Return type:
- keyColumn(self) str [source]¶
Returns the name of the (primary) key column for the referenced table.
- Return type:
str
- param(self, key: str | None) str [source]¶
Returns a generic parameter value corresponding to the specified
key
.- Parameters:
key (Optional[str])
- Return type:
str
- parameterKeys(self) Set[str] ¶
Returns parameter keys used in the uri: specialized ones (“table”, “schema”, etc.) or generic parameters.
Added in version 3.26.
- Return type:
Set[str]
- params(self, key: str | None) List[str] [source]¶
Returns multiple generic parameter values corresponding to the specified
key
.- Parameters:
key (Optional[str])
- Return type:
List[str]
- quotedTablename(self) str [source]¶
Returns the URI’s table name, escaped and quoted.
- Return type:
str
- removeParam(self, key: str | None) int [source]¶
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 (Optional[str])
- Return type:
int
- static removePassword(aUri: str | None, hide: bool = False) str [source]¶
Removes the password element from a URI.
- Parameters:
aUri (Optional[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
- selectAtIdDisabled(self) bool [source]¶
Returns whether the selection by feature ID is disabled.
- Return type:
bool
- service(self) str [source]¶
Returns the service name associated with the URI.
See also
- Return type:
str
- setAuthConfigId(self, authcfg: str | None)[source]¶
Sets the authentication configuration ID for the URI.
- Parameters:
authcfg (Optional[str])
- setConnection(self, aHost: str | None, aPort: str | None, aDatabase: str | None, aUsername: str | None, aPassword: str | None, sslmode: QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer, authConfigId: str | None = '')[source]¶
Sets all connection related members at once.
- Parameters:
aHost (Optional[str])
aPort (Optional[str])
aDatabase (Optional[str])
aUsername (Optional[str])
aPassword (Optional[str])
sslmode (QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer)
authConfigId (Optional[str] = '')
- setConnection(self, aService: str | None, aDatabase: str | None, aUsername: str | None, aPassword: str | None, sslmode: QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer, authConfigId: str | None = '')[source]
Sets all connection related members at once (for a service case).
- Parameters:
aService (Optional[str])
aDatabase (Optional[str])
aUsername (Optional[str])
aPassword (Optional[str])
sslmode (QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer)
authConfigId (Optional[str] = '')
- setDataSource(self, aSchema: str | None, aTable: str | None, aGeometryColumn: str | None, aSql: str | None = '', aKeyColumn: str | None = '')[source]¶
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 (Optional[str])
aTable (Optional[str])
aGeometryColumn (Optional[str])
aSql (Optional[str] = '')
aKeyColumn (Optional[str] = '')
- setDatabase(self, database: str | None)[source]¶
Sets the URI database name.
- Parameters:
database (Optional[str])
- setDriver(self, driver: str | None)[source]¶
Sets the
driver
name stored in the URI.- Parameters:
driver (Optional[str])
- setEncodedUri(self, uri: str | None)[source]¶
Sets the complete encoded
uri
from a string value.- Parameters:
uri (Optional[str])
- setGeometryColumn(self, geometryColumn: str | None)[source]¶
Sets geometry column name to
geometryColumn
Added in version 3.10.
- Parameters:
geometryColumn (Optional[str])
- setHost(self, host: str | None)[source]¶
Sets the
host
name stored in the URI.See also
Added in version 3.42.
- Parameters:
host (Optional[str])
- setHttpHeaders(self, headers: QgsHttpHeaders)[source]¶
Sets headers to
headers
Added in version 3.26.
- Parameters:
headers (QgsHttpHeaders)
- setKeyColumn(self, column: str | None)[source]¶
Sets the name of the (primary) key
column
.- Parameters:
column (Optional[str])
- setParam(self, key: str | None, value: str | None)[source]¶
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 (Optional[str])
value (Optional[str])
- setParamList(self, key: str | None, value: Iterable[str | None])¶
Sets a generic parameter list
value
on the URI.- Parameters:
key (Optional[str])
value (Iterable[Optional[str]])
- setPassword(self, password: str | None)[source]¶
Sets the
password
for the URI.- Parameters:
password (Optional[str])
- setPort(self, port: str | None)[source]¶
Sets the
port
stored in the URI.See also
Added in version 3.42.
- Parameters:
port (Optional[str])
- setSchema(self, schema: str | None)[source]¶
Sets the
scheme
for the URI.- Parameters:
schema (Optional[str])
- setService(self, service: str | None)[source]¶
Sets the
service
name associated with the URI.See also
Added in version 3.42.
- Parameters:
service (Optional[str])
- setSql(self, sql: str | None)[source]¶
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 (Optional[str])
- setSrid(self, srid: str | None)[source]¶
Sets the spatial reference ID associated with the URI.
- Parameters:
srid (Optional[str])
- setSslMode(self, mode: QgsDataSourceUri.SslMode)[source]¶
Sets the SSL
mode
associated with the URI.See also
Added in version 3.42.
- Parameters:
mode (QgsDataSourceUri.SslMode)
- setTable(self, table: str | None)[source]¶
Sets table to
table
Added in version 3.10.
- Parameters:
table (Optional[str])
- setUseEstimatedMetadata(self, flag: bool)[source]¶
Sets whether estimated metadata should be used for the connection.
- Parameters:
flag (bool)
- setUsername(self, username: str | None)[source]¶
Sets the
username
for the URI.- Parameters:
username (Optional[str])
- setWkbType(self, type: Qgis.WkbType)[source]¶
Sets the WKB
type
associated with the URI.- Parameters:
type (Qgis.WkbType)
- sql(self) str [source]¶
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
- sslMode(self) QgsDataSourceUri.SslMode [source]¶
Returns the SSL mode associated with the URI.
See also
- Return type:
- uri(self, expandAuthConfig: bool = True) str [source]¶
Returns the complete URI as a string.
- Parameters:
expandAuthConfig (bool = True)
- Return type:
str
- useEstimatedMetadata(self) bool [source]¶
Returns
True
if estimated metadata should be used for the connection.- Return type:
bool
- wkbType(self) Qgis.WkbType [source]¶
Returns the WKB type associated with the URI.
- Return type: