QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
37class CORE_EXPORT QgsDataSourceUri
38{
39 Q_GADGET
40 public:
41
54 Q_ENUM( SslMode )
55
57
61 QgsDataSourceUri( const QString &uri );
62
67 QgsDataSourceUri( const QByteArray &uri ) SIP_SKIP;
68
72 QString connectionInfo( bool expandAuthConfig = true ) const;
73
77 QString uri( bool expandAuthConfig = true ) const;
78
82 QByteArray encodedUri() const;
83
89 void setEncodedUri( const QByteArray &uri ) SIP_SKIP;
90
94 void setEncodedUri( const QString &uri );
95
99 QString quotedTablename() const;
100
106 void setParam( const QString &key, const QString &value );
107
112 void setParam( const QString &key, const QStringList &value ) SIP_PYNAME( setParamList );
113
118 int removeParam( const QString &key );
119
123 QString param( const QString &key ) const;
124
128 QStringList params( const QString &key ) const;
129
133 bool hasParam( const QString &key ) const;
134
138 void setConnection( const QString &aHost,
139 const QString &aPort,
140 const QString &aDatabase,
141 const QString &aUsername,
142 const QString &aPassword,
143 SslMode sslmode = SslPrefer,
144 const QString &authConfigId = QString() );
145
149 void setConnection( const QString &aService,
150 const QString &aDatabase,
151 const QString &aUsername,
152 const QString &aPassword,
153 SslMode sslmode = SslPrefer,
154 const QString &authConfigId = QString() );
155
159 void setDatabase( const QString &database );
160
167 void setDataSource( const QString &aSchema,
168 const QString &aTable,
169 const QString &aGeometryColumn,
170 const QString &aSql = QString(),
171 const QString &aKeyColumn = QString() );
172
176 void setAuthConfigId( const QString &authcfg );
177
181 void setUsername( const QString &username );
182
186 void setPassword( const QString &password );
187
196 static QString removePassword( const QString &aUri, bool hide = false );
197
201 QString authConfigId() const;
202
204 QString username() const;
205
207 QString schema() const;
208
210 QString table() const;
211
220 QString sql() const;
221
223 QString geometryColumn() const;
224
226 void setUseEstimatedMetadata( bool flag );
227
229 bool useEstimatedMetadata() const;
230
232 void disableSelectAtId( bool flag );
233
235 bool selectAtIdDisabled() const;
236
238 void clearSchema();
239
243 void setSchema( const QString &schema );
244
253 void setSql( const QString &sql );
254
261 void setHost( const QString &host );
262
268 QString host() const;
269
271 QString database() const;
272
279 void setPort( const QString &port );
280
286 QString port() const;
287
291 QString driver() const;
292
296 void setDriver( const QString &driver );
297
299 QString password() const;
300
307 void setSslMode( SslMode mode );
308
314 SslMode sslMode() const;
315
322 void setService( const QString &service );
323
329 QString service() const;
330
332 QString keyColumn() const;
333
335 void setKeyColumn( const QString &column );
336
340 Qgis::WkbType wkbType() const;
341
343 void setWkbType( Qgis::WkbType type );
344
346 QString srid() const;
347
349 void setSrid( const QString &srid );
350
355 static SslMode decodeSslMode( const QString &sslMode );
356
361 static QString encodeSslMode( SslMode sslMode );
362
367 void setTable( const QString &table );
368
373 void setGeometryColumn( const QString &geometryColumn );
374
379 QSet<QString> parameterKeys() const;
380
381#ifndef SIP_RUN
383 QgsHttpHeaders httpHeaders() const { return mHttpHeaders; }
384#endif
385
390 QgsHttpHeaders &httpHeaders() { return mHttpHeaders; }
391
396 QString httpHeader( const QString &key ) { return mHttpHeaders[key].toString(); }
397
402 void setHttpHeaders( const QgsHttpHeaders &headers ) { mHttpHeaders = headers; }
403
404#ifdef SIP_RUN
405 SIP_PYOBJECT __repr__();
406 % MethodCode
407 QString str = QStringLiteral( "<QgsDataSourceUri: %1>" ).arg( sipCpp->uri( false ) );
408 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
409 % End
410#endif
411
412 bool operator==( const QgsDataSourceUri &other ) const;
413 bool operator!=( const QgsDataSourceUri &other ) const;
414
415 private:
416 void skipBlanks( const QString &uri, int &i );
417 QString getValue( const QString &uri, int &i );
418 QString escape( const QString &uri, QChar delim ) const;
419
420 /* data */
421
423 QString mHost;
425 QString mPort;
427 QString mDriver;
429 QString mService;
431 QString mDatabase;
433 QString mSchema;
435 QString mTable;
437 QString mGeometryColumn;
439 QString mSql;
441 QString mAuthConfigId;
443 QString mUsername;
445 QString mPassword;
447 SslMode mSSLmode = SslPrefer;
449 QString mKeyColumn;
451 bool mUseEstimatedMetadata = false;
453 bool mSelectAtIdDisabled = false;
455 bool mSelectAtIdDisabledSet = false;
459 QString mSrid;
461 QMultiMap<QString, QString> mParams;
463 QgsHttpHeaders mHttpHeaders;
464};
465
466#endif //QGSDATASOURCEURI_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
@ Unknown
Unknown.
Definition qgis.h:278
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:134
#define SIP_PYNAME(name)
Definition qgis_sip.h:89
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)