QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
QgsDataSourceUri Class Reference

Class for storing the component parts of a RDBMS data source URI (e.g. More...

#include <qgsdatasourceuri.h>

Public Types

enum  SslMode {
  SslPrefer , SslDisable , SslAllow , SslRequire ,
  SslVerifyCa , SslVerifyFull
}
 Available SSL connection modes. More...
 

Public Member Functions

 QgsDataSourceUri ()
 
 QgsDataSourceUri (const QByteArray &uri)
 Constructor for QgsDataSourceUri which parses an input encoded uri).
 
 QgsDataSourceUri (const QString &uri)
 Constructor for QgsDataSourceUri which parses an input uri string.
 
QString authConfigId () const
 Returns any associated authentication configuration ID stored in the URI.
 
void clearSchema ()
 Clears the schema stored in the URI.
 
QString connectionInfo (bool expandAuthConfig=true) const
 Returns the connection part of the URI.
 
QString database () const
 Returns the database name stored in the URI.
 
void disableSelectAtId (bool flag)
 Set to true to disable selection by feature ID.
 
QString driver () const
 Returns the driver name stored in the URI.
 
QByteArray encodedUri () const
 Returns the complete encoded URI as a byte array.
 
QString geometryColumn () const
 Returns the name of the geometry column stored in the URI, if set.
 
bool hasParam (const QString &key) const
 Returns true if a parameter with the specified key exists.
 
QString host () const
 Returns the host name stored in the URI.
 
QString httpHeader (const QString &key)
 Returns the http header value according to key.
 
QgsHttpHeadershttpHeaders ()
 Returns http headers.
 
QgsHttpHeaders httpHeaders () const
 Returns http headers.
 
QString keyColumn () const
 Returns the name of the (primary) key column for the referenced table.
 
QString param (const QString &key) const
 Returns a generic parameter value corresponding to the specified key.
 
QSet< QString > parameterKeys () const
 Returns parameter keys used in the uri: specialized ones ("table", "schema", etc.) or generic parameters.
 
QStringList params (const QString &key) const
 Returns multiple generic parameter values corresponding to the specified key.
 
QString password () const
 Returns the password stored in the URI.
 
QString port () const
 Returns the port stored in the URI.
 
QString quotedTablename () const
 Returns the URI's table name, escaped and quoted.
 
int removeParam (const QString &key)
 Removes a generic parameter by key.
 
QString schema () const
 Returns the schema stored in the URI.
 
bool selectAtIdDisabled () const
 Returns whether the selection by feature ID is disabled.
 
QString service () const
 Returns the service name associated with the URI.
 
void setAuthConfigId (const QString &authcfg)
 Sets the authentication configuration ID for the URI.
 
void setConnection (const QString &aHost, const QString &aPort, const QString &aDatabase, const QString &aUsername, const QString &aPassword, SslMode sslmode=SslPrefer, const QString &authConfigId=QString())
 Sets all connection related members at once.
 
void setConnection (const QString &aService, const QString &aDatabase, const QString &aUsername, const QString &aPassword, SslMode sslmode=SslPrefer, const QString &authConfigId=QString())
 Sets all connection related members at once (for a service case).
 
void setDatabase (const QString &database)
 Sets the URI database name.
 
void setDataSource (const QString &aSchema, const QString &aTable, const QString &aGeometryColumn, const QString &aSql=QString(), const QString &aKeyColumn=QString())
 Sets all data source related members at once.
 
void setDriver (const QString &driver)
 Sets the driver name stored in the URI.
 
void setEncodedUri (const QByteArray &uri)
 Sets the complete encoded uri.
 
void setEncodedUri (const QString &uri)
 Sets the complete encoded uri from a string value.
 
void setGeometryColumn (const QString &geometryColumn)
 Sets geometry column name to geometryColumn.
 
void setHttpHeaders (const QgsHttpHeaders &headers)
 Sets headers to headers.
 
void setKeyColumn (const QString &column)
 Sets the name of the (primary) key column.
 
void setParam (const QString &key, const QString &value)
 Sets a generic parameter value on the URI.
 
void setParam (const QString &key, const QStringList &value)
 Sets a generic parameter list value on the URI.
 
void setPassword (const QString &password)
 Sets the password for the URI.
 
void setSchema (const QString &schema)
 Sets the scheme for the URI.
 
void setSql (const QString &sql)
 Sets the sql filter for the URI.
 
void setSrid (const QString &srid)
 Sets the spatial reference ID associated with the URI.
 
void setTable (const QString &table)
 Sets table to table.
 
void setUseEstimatedMetadata (bool flag)
 Sets whether estimated metadata should be used for the connection.
 
void setUsername (const QString &username)
 Sets the username for the URI.
 
void setWkbType (Qgis::WkbType type)
 Sets the WKB type associated with the URI.
 
QString sql () const
 Returns the SQL filter stored in the URI, if set.
 
QString srid () const
 Returns the spatial reference ID associated with the URI.
 
SslMode sslMode () const
 Returns the SSL mode associated with the URI.
 
QString table () const
 Returns the table name stored in the URI.
 
QString uri (bool expandAuthConfig=true) const
 Returns the complete URI as a string.
 
bool useEstimatedMetadata () const
 Returns true if estimated metadata should be used for the connection.
 
QString username () const
 Returns the username stored in the URI.
 
Qgis::WkbType wkbType () const
 Returns the WKB type associated with the URI.
 

Static Public Member Functions

static SslMode decodeSslMode (const QString &sslMode)
 Decodes SSL mode string into enum value.
 
static QString encodeSslMode (SslMode sslMode)
 Encodes SSL mode enum value into a string.
 
static QString removePassword (const QString &aUri, bool hide=false)
 Removes the password element from a URI.
 

Detailed Description

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.

Definition at line 37 of file qgsdatasourceuri.h.

Member Enumeration Documentation

◆ SslMode

Available SSL connection modes.

Enumerator
SslPrefer 
SslDisable 
SslAllow 
SslRequire 
SslVerifyCa 
SslVerifyFull 

Definition at line 45 of file qgsdatasourceuri.h.

Constructor & Destructor Documentation

◆ QgsDataSourceUri() [1/3]

QgsDataSourceUri::QgsDataSourceUri ( )

Definition at line 33 of file qgsdatasourceuri.cpp.

◆ QgsDataSourceUri() [2/3]

QgsDataSourceUri::QgsDataSourceUri ( const QString &  uri)

Constructor for QgsDataSourceUri which parses an input uri string.

Definition at line 38 of file qgsdatasourceuri.cpp.

◆ QgsDataSourceUri() [3/3]

QgsDataSourceUri::QgsDataSourceUri ( const QByteArray &  uri)

Constructor for QgsDataSourceUri which parses an input encoded uri).

Note
not available in Python bindings

Member Function Documentation

◆ authConfigId()

QString QgsDataSourceUri::authConfigId ( ) const

Returns any associated authentication configuration ID stored in the URI.

Definition at line 320 of file qgsdatasourceuri.cpp.

◆ clearSchema()

void QgsDataSourceUri::clearSchema ( )

Clears the schema stored in the URI.

Definition at line 439 of file qgsdatasourceuri.cpp.

◆ connectionInfo()

QString QgsDataSourceUri::connectionInfo ( bool  expandAuthConfig = true) const

Returns the connection part of the URI.

Definition at line 543 of file qgsdatasourceuri.cpp.

◆ database()

QString QgsDataSourceUri::database ( ) const

Returns the database name stored in the URI.

Definition at line 345 of file qgsdatasourceuri.cpp.

◆ decodeSslMode()

QgsDataSourceUri::SslMode QgsDataSourceUri::decodeSslMode ( const QString &  sslMode)
static

Decodes SSL mode string into enum value.

If the string is not recognized, SslPrefer is returned.

Since
QGIS 3.2

Definition at line 824 of file qgsdatasourceuri.cpp.

◆ disableSelectAtId()

void QgsDataSourceUri::disableSelectAtId ( bool  flag)

Set to true to disable selection by feature ID.

Definition at line 423 of file qgsdatasourceuri.cpp.

◆ driver()

QString QgsDataSourceUri::driver ( ) const

Returns the driver name stored in the URI.

Definition at line 365 of file qgsdatasourceuri.cpp.

◆ encodedUri()

QByteArray QgsDataSourceUri::encodedUri ( ) const

Returns the complete encoded URI as a byte array.

Definition at line 679 of file qgsdatasourceuri.cpp.

◆ encodeSslMode()

QString QgsDataSourceUri::encodeSslMode ( QgsDataSourceUri::SslMode  sslMode)
static

Encodes SSL mode enum value into a string.

Since
QGIS 3.2

Definition at line 842 of file qgsdatasourceuri.cpp.

◆ geometryColumn()

QString QgsDataSourceUri::geometryColumn ( ) const

Returns the name of the geometry column stored in the URI, if set.

Definition at line 390 of file qgsdatasourceuri.cpp.

◆ hasParam()

bool QgsDataSourceUri::hasParam ( const QString &  key) const

Returns true if a parameter with the specified key exists.

Definition at line 927 of file qgsdatasourceuri.cpp.

◆ host()

QString QgsDataSourceUri::host ( ) const

Returns the host name stored in the URI.

Definition at line 340 of file qgsdatasourceuri.cpp.

◆ httpHeader()

QString QgsDataSourceUri::httpHeader ( const QString &  key)
inline

Returns the http header value according to key.

Since
QGIS 3.26

Definition at line 346 of file qgsdatasourceuri.h.

◆ httpHeaders() [1/2]

QgsHttpHeaders & QgsDataSourceUri::httpHeaders ( )
inline

Returns http headers.

Since
QGIS 3.26

Definition at line 340 of file qgsdatasourceuri.h.

◆ httpHeaders() [2/2]

QgsHttpHeaders QgsDataSourceUri::httpHeaders ( ) const
inline

Returns http headers.

Definition at line 333 of file qgsdatasourceuri.h.

◆ keyColumn()

QString QgsDataSourceUri::keyColumn ( ) const

Returns the name of the (primary) key column for the referenced table.

Definition at line 395 of file qgsdatasourceuri.cpp.

◆ param()

QString QgsDataSourceUri::param ( const QString &  key) const

Returns a generic parameter value corresponding to the specified key.

Definition at line 901 of file qgsdatasourceuri.cpp.

◆ parameterKeys()

QSet< QString > QgsDataSourceUri::parameterKeys ( ) const

Returns parameter keys used in the uri: specialized ones ("table", "schema", etc.) or generic parameters.

Since
QGIS 3.26

Definition at line 940 of file qgsdatasourceuri.cpp.

◆ params()

QStringList QgsDataSourceUri::params ( const QString &  key) const

Returns multiple generic parameter values corresponding to the specified key.

Definition at line 914 of file qgsdatasourceuri.cpp.

◆ password()

QString QgsDataSourceUri::password ( ) const

Returns the password stored in the URI.

Definition at line 350 of file qgsdatasourceuri.cpp.

◆ port()

QString QgsDataSourceUri::port ( ) const

Returns the port stored in the URI.

Definition at line 360 of file qgsdatasourceuri.cpp.

◆ quotedTablename()

QString QgsDataSourceUri::quotedTablename ( ) const

Returns the URI's table name, escaped and quoted.

Definition at line 738 of file qgsdatasourceuri.cpp.

◆ removeParam()

int QgsDataSourceUri::removeParam ( const QString &  key)

Removes a generic parameter by key.

Note
Calling this method removes all the occurrences of key, and returns the number of parameters removed.

Definition at line 880 of file qgsdatasourceuri.cpp.

◆ removePassword()

QString QgsDataSourceUri::removePassword ( const QString &  aUri,
bool  hide = false 
)
static

Removes the password element from a URI.

Parameters
aUriA data source uri
hidetrue to replace the password value with 'xxxxxxxx', false to remove password (key and value) (since QGIS 3.34)
Returns
The data source uri without the password

Definition at line 234 of file qgsdatasourceuri.cpp.

◆ schema()

QString QgsDataSourceUri::schema ( ) const

Returns the schema stored in the URI.

Definition at line 375 of file qgsdatasourceuri.cpp.

◆ selectAtIdDisabled()

bool QgsDataSourceUri::selectAtIdDisabled ( ) const

Returns whether the selection by feature ID is disabled.

Definition at line 429 of file qgsdatasourceuri.cpp.

◆ service()

QString QgsDataSourceUri::service ( ) const

Returns the service name associated with the URI.

Definition at line 335 of file qgsdatasourceuri.cpp.

◆ setAuthConfigId()

void QgsDataSourceUri::setAuthConfigId ( const QString &  authcfg)

Sets the authentication configuration ID for the URI.

Definition at line 794 of file qgsdatasourceuri.cpp.

◆ setConnection() [1/2]

void QgsDataSourceUri::setConnection ( const QString &  aHost,
const QString &  aPort,
const QString &  aDatabase,
const QString &  aUsername,
const QString &  aPassword,
SslMode  sslmode = SslPrefer,
const QString &  authConfigId = QString() 
)

Sets all connection related members at once.

Definition at line 749 of file qgsdatasourceuri.cpp.

◆ setConnection() [2/2]

void QgsDataSourceUri::setConnection ( const QString &  aService,
const QString &  aDatabase,
const QString &  aUsername,
const QString &  aPassword,
SslMode  sslmode = SslPrefer,
const QString &  authConfigId = QString() 
)

Sets all connection related members at once (for a service case).

Definition at line 766 of file qgsdatasourceuri.cpp.

◆ setDatabase()

void QgsDataSourceUri::setDatabase ( const QString &  database)

Sets the URI database name.

Definition at line 799 of file qgsdatasourceuri.cpp.

◆ setDataSource()

void QgsDataSourceUri::setDataSource ( const QString &  aSchema,
const QString &  aTable,
const QString &  aGeometryColumn,
const QString &  aSql = QString(),
const QString &  aKeyColumn = QString() 
)

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)").

Definition at line 781 of file qgsdatasourceuri.cpp.

◆ setDriver()

void QgsDataSourceUri::setDriver ( const QString &  driver)

Sets the driver name stored in the URI.

Definition at line 401 of file qgsdatasourceuri.cpp.

◆ setEncodedUri() [1/2]

void QgsDataSourceUri::setEncodedUri ( const QByteArray &  uri)

Sets the complete encoded uri.

Note
not available in Python bindings

Definition at line 701 of file qgsdatasourceuri.cpp.

◆ setEncodedUri() [2/2]

void QgsDataSourceUri::setEncodedUri ( const QString &  uri)

Sets the complete encoded uri from a string value.

Definition at line 731 of file qgsdatasourceuri.cpp.

◆ setGeometryColumn()

void QgsDataSourceUri::setGeometryColumn ( const QString &  geometryColumn)

Sets geometry column name to geometryColumn.

Since
QGIS 3.10

Definition at line 459 of file qgsdatasourceuri.cpp.

◆ setHttpHeaders()

void QgsDataSourceUri::setHttpHeaders ( const QgsHttpHeaders headers)
inline

Sets headers to headers.

Since
QGIS 3.26

Definition at line 352 of file qgsdatasourceuri.h.

◆ setKeyColumn()

void QgsDataSourceUri::setKeyColumn ( const QString &  column)

Sets the name of the (primary) key column.

Definition at line 407 of file qgsdatasourceuri.cpp.

◆ setParam() [1/2]

void QgsDataSourceUri::setParam ( const QString &  key,
const QString &  value 
)

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.

Definition at line 856 of file qgsdatasourceuri.cpp.

◆ setParam() [2/2]

void QgsDataSourceUri::setParam ( const QString &  key,
const QStringList &  value 
)

Sets a generic parameter list value on the URI.

Note
available in Python as setParamList

Definition at line 872 of file qgsdatasourceuri.cpp.

◆ setPassword()

void QgsDataSourceUri::setPassword ( const QString &  password)

Sets the password for the URI.

Definition at line 355 of file qgsdatasourceuri.cpp.

◆ setSchema()

void QgsDataSourceUri::setSchema ( const QString &  schema)

Sets the scheme for the URI.

Definition at line 444 of file qgsdatasourceuri.cpp.

◆ setSql()

void QgsDataSourceUri::setSql ( const QString &  sql)

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
sql()

Definition at line 434 of file qgsdatasourceuri.cpp.

◆ setSrid()

void QgsDataSourceUri::setSrid ( const QString &  srid)

Sets the spatial reference ID associated with the URI.

Definition at line 819 of file qgsdatasourceuri.cpp.

◆ setTable()

void QgsDataSourceUri::setTable ( const QString &  table)

Sets table to table.

Since
QGIS 3.10

Definition at line 464 of file qgsdatasourceuri.cpp.

◆ setUseEstimatedMetadata()

void QgsDataSourceUri::setUseEstimatedMetadata ( bool  flag)

Sets whether estimated metadata should be used for the connection.

Definition at line 413 of file qgsdatasourceuri.cpp.

◆ setUsername()

void QgsDataSourceUri::setUsername ( const QString &  username)

Sets the username for the URI.

Definition at line 330 of file qgsdatasourceuri.cpp.

◆ setWkbType()

void QgsDataSourceUri::setWkbType ( Qgis::WkbType  type)

Sets the WKB type associated with the URI.

Definition at line 809 of file qgsdatasourceuri.cpp.

◆ sql()

QString QgsDataSourceUri::sql ( ) const

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
setSql()

Definition at line 385 of file qgsdatasourceuri.cpp.

◆ srid()

QString QgsDataSourceUri::srid ( ) const

Returns the spatial reference ID associated with the URI.

Definition at line 814 of file qgsdatasourceuri.cpp.

◆ sslMode()

QgsDataSourceUri::SslMode QgsDataSourceUri::sslMode ( ) const

Returns the SSL mode associated with the URI.

Definition at line 370 of file qgsdatasourceuri.cpp.

◆ table()

QString QgsDataSourceUri::table ( ) const

Returns the table name stored in the URI.

Definition at line 380 of file qgsdatasourceuri.cpp.

◆ uri()

QString QgsDataSourceUri::uri ( bool  expandAuthConfig = true) const

Returns the complete URI as a string.

Definition at line 605 of file qgsdatasourceuri.cpp.

◆ useEstimatedMetadata()

bool QgsDataSourceUri::useEstimatedMetadata ( ) const

Returns true if estimated metadata should be used for the connection.

Definition at line 418 of file qgsdatasourceuri.cpp.

◆ username()

QString QgsDataSourceUri::username ( ) const

Returns the username stored in the URI.

Definition at line 325 of file qgsdatasourceuri.cpp.

◆ wkbType()

Qgis::WkbType QgsDataSourceUri::wkbType ( ) const

Returns the WKB type associated with the URI.

Definition at line 804 of file qgsdatasourceuri.cpp.


The documentation for this class was generated from the following files: