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.
- class qgis.core.QgsDataSourceUri[source]¶
Bases:
object- __init__()
- __init__(uri: str | None)
Constructor for QgsDataSourceUri which parses an input
uristring.- 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
Trueto 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
Trueif a parameter with the specifiedkeyexists.- Parameters:
key (Optional[str])
- Return type:
bool
- httpHeader(self, key: str | None) str[source]¶
Returns the http header value according to
keyAdded 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) –
Trueto replace the password value with ‘xxxxxxxx’,Falseto 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.
setConnection(self, aService: Optional[str], aDatabase: Optional[str], aUsername: Optional[str], aPassword: Optional[str], sslmode: QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer, authConfigId: Optional[str] = ‘’) Sets all connection related members at once (for a service case).
- Parameters:
aHost (Optional[str])
aPort (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
aSqlargument 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
drivername stored in the URI.- Parameters:
driver (Optional[str])
- setEncodedUri(self, uri: str | None)[source]¶
Sets the complete encoded
urifrom a string value.- Parameters:
uri (Optional[str])
- setGeometryColumn(self, geometryColumn: str | None)[source]¶
Sets geometry column name to
geometryColumnAdded in version 3.10.
- Parameters:
geometryColumn (Optional[str])
- setHost(self, host: str | None)[source]¶
Sets the
hostname stored in the URI.See also
Added in version 3.42.
- Parameters:
host (Optional[str])
- setHttpHeaders(self, headers: QgsHttpHeaders)[source]¶
Sets headers to
headersAdded 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
valueon the URI.Note
If a parameter with the specified
keyalready 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
valueon the URI.- Parameters:
key (Optional[str])
value (Iterable[Optional[str]])
- setPassword(self, password: str | None)[source]¶
Sets the
passwordfor the URI.- Parameters:
password (Optional[str])
- setPort(self, port: str | None)[source]¶
Sets the
portstored in the URI.See also
Added in version 3.42.
- Parameters:
port (Optional[str])
- setSchema(self, schema: str | None)[source]¶
Sets the
schemefor the URI.- Parameters:
schema (Optional[str])
- setService(self, service: str | None)[source]¶
Sets the
servicename associated with the URI.See also
Added in version 3.42.
- Parameters:
service (Optional[str])
- setSql(self, sql: str | None)[source]¶
Sets the
sqlfilter for the URI.The
sqlrepresents 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
modeassociated with the URI.See also
Added in version 3.42.
- Parameters:
mode (QgsDataSourceUri.SslMode)
- setTable(self, table: str | None)[source]¶
Sets table to
tableAdded 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
usernamefor the URI.- Parameters:
username (Optional[str])
- setWkbType(self, type: Qgis.WkbType)[source]¶
Sets the WKB
typeassociated 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
Trueif 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: