QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgsdatasourceuri.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdatasourceuri.h - Structure to contain the component parts
3 of a data source URI
4 -------------------
5 begin : Dec 5, 2004
6 copyright : (C) 2004 by Gary E.Sherman
7 email : sherman at mrcc.com
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19#ifndef QGSDATASOURCEURI_H
20#define QGSDATASOURCEURI_H
21
22#include "qgis_core.h"
23#include "qgis_sip.h"
24#include "qgshttpheaders.h"
25#include "qgswkbtypes.h"
26
27#include <QMap>
28#include <QSet>
29#include <QString>
30
31using namespace Qt::StringLiterals;
32
40class CORE_EXPORT QgsDataSourceUri
41{
42 Q_GADGET
43 public:
56 Q_ENUM( SslMode )
57
59
63 QgsDataSourceUri( const QString &uri );
64
69 QgsDataSourceUri( const QByteArray &uri ) SIP_SKIP;
70
74 QString connectionInfo( bool expandAuthConfig = true ) const;
75
79 QString uri( bool expandAuthConfig = true ) const;
80
84 QByteArray encodedUri() const;
85
91 void setEncodedUri( const QByteArray &uri ) SIP_SKIP;
92
96 void setEncodedUri( const QString &uri );
97
101 QString quotedTablename() const;
102
108 void setParam( const QString &key, const QString &value );
109
114 void setParam( const QString &key, const QStringList &value ) SIP_PYNAME( setParamList );
115
120 int removeParam( const QString &key );
121
125 QString param( const QString &key ) const;
126
130 QStringList params( const QString &key ) const;
131
135 bool hasParam( const QString &key ) const;
136
140 void setConnection(
141 const QString &aHost, const QString &aPort, const QString &aDatabase, const QString &aUsername, const QString &aPassword, SslMode sslmode = SslPrefer, const QString &authConfigId = QString()
142 );
143
147 void setConnection( const QString &aService, const QString &aDatabase, const QString &aUsername, const QString &aPassword, SslMode sslmode = SslPrefer, const QString &authConfigId = QString() );
148
152 void setDatabase( const QString &database );
153
160 void setDataSource( const QString &aSchema, const QString &aTable, const QString &aGeometryColumn, const QString &aSql = QString(), const QString &aKeyColumn = QString() );
161
165 void setAuthConfigId( const QString &authcfg );
166
170 void setUsername( const QString &username );
171
175 void setPassword( const QString &password );
176
185 static QString removePassword( const QString &aUri, bool hide = false );
186
190 QString authConfigId() const;
191
193 QString username() const;
194
196 QString schema() const;
197
199 QString table() const;
200
209 QString sql() const;
210
212 QString geometryColumn() const;
213
215 void setUseEstimatedMetadata( bool flag );
216
218 bool useEstimatedMetadata() const;
219
221 void disableSelectAtId( bool flag );
222
224 bool selectAtIdDisabled() const;
225
227 void clearSchema();
228
232 void setSchema( const QString &schema );
233
242 void setSql( const QString &sql );
243
250 void setHost( const QString &host );
251
257 QString host() const;
258
260 QString database() const;
261
268 void setPort( const QString &port );
269
275 QString port() const;
276
280 QString driver() const;
281
285 void setDriver( const QString &driver );
286
288 QString password() const;
289
296 void setSslMode( SslMode mode );
297
303 SslMode sslMode() const;
304
311 void setService( const QString &service );
312
318 QString service() const;
319
321 QString keyColumn() const;
322
324 void setKeyColumn( const QString &column );
325
329 Qgis::WkbType wkbType() const;
330
332 void setWkbType( Qgis::WkbType type );
333
335 QString srid() const;
336
338 void setSrid( const QString &srid );
339
344 static SslMode decodeSslMode( const QString &sslMode );
345
350 static QString encodeSslMode( SslMode sslMode );
351
356 void setTable( const QString &table );
357
362 void setGeometryColumn( const QString &geometryColumn );
363
368 QSet<QString> parameterKeys() const;
369
370#ifndef SIP_RUN
372 QgsHttpHeaders httpHeaders() const { return mHttpHeaders; }
373#endif
374
379 QgsHttpHeaders &httpHeaders() { return mHttpHeaders; }
380
385 QString httpHeader( const QString &key ) { return mHttpHeaders[key].toString(); }
386
391 void setHttpHeaders( const QgsHttpHeaders &headers ) { mHttpHeaders = headers; }
392
393#ifdef SIP_RUN
394 // clang-format off
395 SIP_PYOBJECT __repr__();
396 % MethodCode
397 QString str = u"<QgsDataSourceUri: %1>"_s.arg( sipCpp->uri( false ) );
398 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
399 % End
400// clang-format on
401#endif
402
403 bool operator==( const QgsDataSourceUri &other ) const;
404 bool operator!=( const QgsDataSourceUri &other ) const;
405
406 private:
407 void skipBlanks( const QString &uri, int &i );
408 QString getValue( const QString &uri, int &i );
409 QString escape( const QString &uri, QChar delim ) const;
410
411 /* data */
412
414 QString mHost;
416 QString mPort;
418 QString mDriver;
420 QString mService;
422 QString mDatabase;
424 QString mSchema;
426 QString mTable;
428 QString mGeometryColumn;
430 QString mSql;
432 QString mAuthConfigId;
434 QString mUsername;
436 QString mPassword;
438 SslMode mSSLmode = SslPrefer;
440 QString mKeyColumn;
442 bool mUseEstimatedMetadata = false;
444 bool mSelectAtIdDisabled = false;
446 bool mSelectAtIdDisabledSet = false;
450 QString mSrid;
452 QMultiMap<QString, QString> mParams;
454 QgsHttpHeaders mHttpHeaders;
455};
456
457#endif //QGSDATASOURCEURI_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
@ Unknown
Unknown.
Definition qgis.h:295
Stores the component parts of a data source URI (e.g.
QString srid() const
Returns the spatial reference ID associated with the URI.
SslMode
Available SSL connection modes.
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.
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
QStringList params(const QString &key) const
Returns multiple generic parameter values corresponding to the specified key.
void setSchema(const QString &schema)
Sets the scheme for the URI.
bool hasParam(const QString &key) const
Returns true if a parameter with the specified key exists.
int removeParam(const QString &key)
Removes a generic parameter by key.
static SslMode decodeSslMode(const QString &sslMode)
Decodes SSL mode string into enum value.
void setSql(const QString &sql)
Sets the sql filter for the URI.
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
QgsDataSourceUri(const QByteArray &uri)
Constructor for QgsDataSourceUri which parses an input encoded uri).
QString table() const
Returns the table name stored in the URI.
void setTable(const QString &table)
Sets table to table.
void setAuthConfigId(const QString &authcfg)
Sets the authentication configuration ID for the URI.
QString quotedTablename() const
Returns the URI's table name, escaped and quoted.
void setGeometryColumn(const QString &geometryColumn)
Sets geometry column name to geometryColumn.
QString schema() const
Returns the schema stored in the URI.
void setUseEstimatedMetadata(bool flag)
Sets whether estimated metadata should be used for the connection.
QString connectionInfo(bool expandAuthConfig=true) const
Returns the connection part of the URI.
QgsHttpHeaders httpHeaders() const
Returns http headers.
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
void setUsername(const QString &username)
Sets the username for the URI.
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
void disableSelectAtId(bool flag)
Set to true to disable selection by feature ID.
bool selectAtIdDisabled() const
Returns whether the selection by feature ID is disabled.
void setHost(const QString &host)
Sets the host name stored in the URI.
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.
QString username() const
Returns the username stored in the URI.
void setService(const QString &service)
Sets the service name associated with the URI.
static QString encodeSslMode(SslMode sslMode)
Encodes SSL mode enum value into a string.
Qgis::WkbType wkbType() const
Returns the WKB type associated with the URI.
void setSslMode(SslMode mode)
Sets the SSL mode associated with the URI.
void setWkbType(Qgis::WkbType type)
Sets the WKB type associated with the URI.
QString driver() const
Returns the driver name stored in the URI.
QString host() const
Returns the host name stored in the URI.
void setPort(const QString &port)
Sets the port stored in the URI.
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
QString service() const
Returns the service name associated with the URI.
void setKeyColumn(const QString &column)
Sets the name of the (primary) key column.
bool useEstimatedMetadata() const
Returns true if estimated metadata should be used for the connection.
QgsHttpHeaders & httpHeaders()
Returns http headers.
SslMode sslMode() const
Returns the SSL mode associated with the URI.
QString password() const
Returns the password stored in the URI.
QString keyColumn() const
Returns the name of the (primary) key column for the referenced table.
QString authConfigId() const
Returns any associated authentication configuration ID stored in the URI.
QString port() const
Returns the port stored in the URI.
QSet< QString > parameterKeys() const
Returns parameter keys used in the uri: specialized ones ("table", "schema", etc.) or generic paramet...
QString database() const
Returns the database name stored in the URI.
void clearSchema()
Clears the schema stored in the URI.
void setDriver(const QString &driver)
Sets the driver name stored in the URI.
static QString removePassword(const QString &aUri, bool hide=false)
Removes the password element from a URI.
void setHttpHeaders(const QgsHttpHeaders &headers)
Sets headers to headers.
void setDatabase(const QString &database)
Sets the URI database name.
QString geometryColumn() const
Returns the name of the geometry column stored in the URI, if set.
void setSrid(const QString &srid)
Sets the spatial reference ID associated with the URI.
QString httpHeader(const QString &key)
Returns the http header value according to key.
QString sql() const
Returns the SQL filter stored in the URI, if set.
void setPassword(const QString &password)
Sets the password for the URI.
Implements simple HTTP header management.
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_PYNAME(name)
Definition qgis_sip.h:88
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)