QGIS API Documentation 3.99.0-Master (d270888f95f)
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:
44
57 Q_ENUM( SslMode )
58
60
64 QgsDataSourceUri( const QString &uri );
65
70 QgsDataSourceUri( const QByteArray &uri ) SIP_SKIP;
71
75 QString connectionInfo( bool expandAuthConfig = true ) const;
76
80 QString uri( bool expandAuthConfig = true ) const;
81
85 QByteArray encodedUri() const;
86
92 void setEncodedUri( const QByteArray &uri ) SIP_SKIP;
93
97 void setEncodedUri( const QString &uri );
98
102 QString quotedTablename() const;
103
109 void setParam( const QString &key, const QString &value );
110
115 void setParam( const QString &key, const QStringList &value ) SIP_PYNAME( setParamList );
116
121 int removeParam( const QString &key );
122
126 QString param( const QString &key ) const;
127
131 QStringList params( const QString &key ) const;
132
136 bool hasParam( const QString &key ) const;
137
141 void setConnection( const QString &aHost,
142 const QString &aPort,
143 const QString &aDatabase,
144 const QString &aUsername,
145 const QString &aPassword,
146 SslMode sslmode = SslPrefer,
147 const QString &authConfigId = QString() );
148
152 void setConnection( const QString &aService,
153 const QString &aDatabase,
154 const QString &aUsername,
155 const QString &aPassword,
156 SslMode sslmode = SslPrefer,
157 const QString &authConfigId = QString() );
158
162 void setDatabase( const QString &database );
163
170 void setDataSource( const QString &aSchema,
171 const QString &aTable,
172 const QString &aGeometryColumn,
173 const QString &aSql = QString(),
174 const QString &aKeyColumn = QString() );
175
179 void setAuthConfigId( const QString &authcfg );
180
184 void setUsername( const QString &username );
185
189 void setPassword( const QString &password );
190
199 static QString removePassword( const QString &aUri, bool hide = false );
200
204 QString authConfigId() const;
205
207 QString username() const;
208
210 QString schema() const;
211
213 QString table() const;
214
223 QString sql() const;
224
226 QString geometryColumn() const;
227
229 void setUseEstimatedMetadata( bool flag );
230
232 bool useEstimatedMetadata() const;
233
235 void disableSelectAtId( bool flag );
236
238 bool selectAtIdDisabled() const;
239
241 void clearSchema();
242
246 void setSchema( const QString &schema );
247
256 void setSql( const QString &sql );
257
264 void setHost( const QString &host );
265
271 QString host() const;
272
274 QString database() const;
275
282 void setPort( const QString &port );
283
289 QString port() const;
290
294 QString driver() const;
295
299 void setDriver( const QString &driver );
300
302 QString password() const;
303
310 void setSslMode( SslMode mode );
311
317 SslMode sslMode() const;
318
325 void setService( const QString &service );
326
332 QString service() const;
333
335 QString keyColumn() const;
336
338 void setKeyColumn( const QString &column );
339
343 Qgis::WkbType wkbType() const;
344
346 void setWkbType( Qgis::WkbType type );
347
349 QString srid() const;
350
352 void setSrid( const QString &srid );
353
358 static SslMode decodeSslMode( const QString &sslMode );
359
364 static QString encodeSslMode( SslMode sslMode );
365
370 void setTable( const QString &table );
371
376 void setGeometryColumn( const QString &geometryColumn );
377
382 QSet<QString> parameterKeys() const;
383
384#ifndef SIP_RUN
386 QgsHttpHeaders httpHeaders() const { return mHttpHeaders; }
387#endif
388
393 QgsHttpHeaders &httpHeaders() { return mHttpHeaders; }
394
399 QString httpHeader( const QString &key ) { return mHttpHeaders[key].toString(); }
400
405 void setHttpHeaders( const QgsHttpHeaders &headers ) { mHttpHeaders = headers; }
406
407#ifdef SIP_RUN
408 SIP_PYOBJECT __repr__();
409 % MethodCode
410 QString str = u"<QgsDataSourceUri: %1>"_s.arg( sipCpp->uri( false ) );
411 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
412 % End
413#endif
414
415 bool operator==( const QgsDataSourceUri &other ) const;
416 bool operator!=( const QgsDataSourceUri &other ) const;
417
418 private:
419 void skipBlanks( const QString &uri, int &i );
420 QString getValue( const QString &uri, int &i );
421 QString escape( const QString &uri, QChar delim ) const;
422
423 /* data */
424
426 QString mHost;
428 QString mPort;
430 QString mDriver;
432 QString mService;
434 QString mDatabase;
436 QString mSchema;
438 QString mTable;
440 QString mGeometryColumn;
442 QString mSql;
444 QString mAuthConfigId;
446 QString mUsername;
448 QString mPassword;
450 SslMode mSSLmode = SslPrefer;
452 QString mKeyColumn;
454 bool mUseEstimatedMetadata = false;
456 bool mSelectAtIdDisabled = false;
458 bool mSelectAtIdDisabledSet = false;
462 QString mSrid;
464 QMultiMap<QString, QString> mParams;
466 QgsHttpHeaders mHttpHeaders;
467};
468
469#endif //QGSDATASOURCEURI_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
@ Unknown
Unknown.
Definition qgis.h:281
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)