QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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 "qgswkbtypes.h"
25#include "qgshttpheaders.h"
26
27#include <QMap>
28#include <QSet>
29
37class CORE_EXPORT QgsDataSourceUri
38{
39 Q_GADGET
40 public:
41
46 {
52 SslVerifyFull
53 };
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
191 static QString removePassword( const QString &aUri );
192
196 QString authConfigId() const;
197
199 QString username() const;
200
202 QString schema() const;
203
205 QString table() const;
206
215 QString sql() const;
216
218 QString geometryColumn() const;
219
221 void setUseEstimatedMetadata( bool flag );
222
224 bool useEstimatedMetadata() const;
225
227 void disableSelectAtId( bool flag );
228
230 bool selectAtIdDisabled() const;
231
233 void clearSchema();
234
239 void setSchema( const QString &schema );
240
249 void setSql( const QString &sql );
250
252 QString host() const;
254 QString database() const;
256 QString port() const;
257
262 QString driver() const;
263
268 void setDriver( const QString &driver );
269
271 QString password() const;
272
274 SslMode sslMode() const;
275
277 QString service() const;
278
280 QString keyColumn() const;
281
283 void setKeyColumn( const QString &column );
284
288 Qgis::WkbType wkbType() const;
289
291 void setWkbType( Qgis::WkbType type );
292
294 QString srid() const;
295
297 void setSrid( const QString &srid );
298
303 static SslMode decodeSslMode( const QString &sslMode );
304
309 static QString encodeSslMode( SslMode sslMode );
310
315 void setTable( const QString &table );
316
321 void setGeometryColumn( const QString &geometryColumn );
322
327 QSet<QString> parameterKeys() const;
328
329#ifndef SIP_RUN
331 QgsHttpHeaders httpHeaders() const { return mHttpHeaders; }
332#endif
333
338 QgsHttpHeaders &httpHeaders() { return mHttpHeaders; }
339
344 QString httpHeader( const QString &key ) { return mHttpHeaders[key].toString(); }
345
350 void setHttpHeaders( const QgsHttpHeaders &headers ) { mHttpHeaders = headers; }
351
352#ifdef SIP_RUN
353 SIP_PYOBJECT __repr__();
354 % MethodCode
355 QString str = QStringLiteral( "<QgsDataSourceUri: %1>" ).arg( sipCpp->uri( false ) );
356 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
357 % End
358#endif
359
360 private:
361 void skipBlanks( const QString &uri, int &i );
362 QString getValue( const QString &uri, int &i );
363 QString escape( const QString &uri, QChar delim ) const;
364
365 /* data */
366
368 QString mHost;
370 QString mPort;
372 QString mDriver;
374 QString mService;
376 QString mDatabase;
378 QString mSchema;
380 QString mTable;
382 QString mGeometryColumn;
384 QString mSql;
386 QString mAuthConfigId;
388 QString mUsername;
390 QString mPassword;
392 SslMode mSSLmode = SslPrefer;
394 QString mKeyColumn;
396 bool mUseEstimatedMetadata = false;
398 bool mSelectAtIdDisabled = false;
400 bool mSelectAtIdDisabledSet = false;
404 QString mSrid;
406 QMultiMap<QString, QString> mParams;
408 QgsHttpHeaders mHttpHeaders;
409};
410
411#endif //QGSDATASOURCEURI_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition: qgis.h:154
@ Unknown
Unknown.
Class for storing the component parts of a RDBMS data source URI (e.g.
SslMode
Available SSL connection modes.
QgsDataSourceUri(const QByteArray &uri)
Constructor for QgsDataSourceUri which parses an input encoded uri).
QgsHttpHeaders httpHeaders() const
Returns http headers.
QgsHttpHeaders & httpHeaders()
Returns http headers.
void setHttpHeaders(const QgsHttpHeaders &headers)
Sets headers to headers.
QString httpHeader(const QString &key)
Returns the http header value according to key.
This class implements simple http header management.
#define str(x)
Definition: qgis.cpp:38
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81