QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
26 #include <QMap>
27 
35 class CORE_EXPORT QgsDataSourceUri
36 {
37  Q_GADGET
38  public:
39 
43  enum SslMode
44  {
50  SslVerifyFull
51  };
52  Q_ENUM( SslMode )
53 
55 
59  QgsDataSourceUri( const QString &uri );
60 
65  QgsDataSourceUri( const QByteArray &uri ) SIP_SKIP;
66 
70  QString connectionInfo( bool expandAuthConfig = true ) const;
71 
75  QString uri( bool expandAuthConfig = true ) const;
76 
80  QByteArray encodedUri() const;
81 
87  void setEncodedUri( const QByteArray &uri ) SIP_SKIP;
88 
92  void setEncodedUri( const QString &uri );
93 
97  QString quotedTablename() const;
98 
104  void setParam( const QString &key, const QString &value );
105 
110  void setParam( const QString &key, const QStringList &value ) SIP_PYNAME( setParamList );
111 
116  int removeParam( const QString &key );
117 
121  QString param( const QString &key ) const;
122 
126  QStringList params( const QString &key ) const;
127 
131  bool hasParam( const QString &key ) const;
132 
136  void setConnection( const QString &aHost,
137  const QString &aPort,
138  const QString &aDatabase,
139  const QString &aUsername,
140  const QString &aPassword,
141  SslMode sslmode = SslPrefer,
142  const QString &authConfigId = QString() );
143 
147  void setConnection( const QString &aService,
148  const QString &aDatabase,
149  const QString &aUsername,
150  const QString &aPassword,
151  SslMode sslmode = SslPrefer,
152  const QString &authConfigId = QString() );
153 
157  void setDatabase( const QString &database );
158 
165  void setDataSource( const QString &aSchema,
166  const QString &aTable,
167  const QString &aGeometryColumn,
168  const QString &aSql = QString(),
169  const QString &aKeyColumn = QString() );
170 
174  void setAuthConfigId( const QString &authcfg );
175 
179  void setUsername( const QString &username );
180 
184  void setPassword( const QString &password );
185 
189  static QString removePassword( const QString &aUri );
190 
194  QString authConfigId() const;
195 
197  QString username() const;
198 
200  QString schema() const;
201 
203  QString table() const;
204 
213  QString sql() const;
214 
216  QString geometryColumn() const;
217 
219  void setUseEstimatedMetadata( bool flag );
220 
222  bool useEstimatedMetadata() const;
223 
225  void disableSelectAtId( bool flag );
226 
228  bool selectAtIdDisabled() const;
229 
231  void clearSchema();
232 
237  void setSchema( const QString &schema );
238 
247  void setSql( const QString &sql );
248 
250  QString host() const;
252  QString database() const;
254  QString port() const;
255 
260  QString driver() const;
261 
266  void setDriver( const QString &driver );
267 
269  QString password() const;
270 
272  SslMode sslMode() const;
273 
275  QString service() const;
276 
278  QString keyColumn() const;
279 
281  void setKeyColumn( const QString &column );
282 
286  QgsWkbTypes::Type wkbType() const;
287 
289  void setWkbType( QgsWkbTypes::Type type );
290 
292  QString srid() const;
293 
295  void setSrid( const QString &srid );
296 
301  static SslMode decodeSslMode( const QString &sslMode );
302 
307  static QString encodeSslMode( SslMode sslMode );
308 
313  void setTable( const QString &table );
314 
319  void setGeometryColumn( const QString &geometryColumn );
320 
321 #ifdef SIP_RUN
322  SIP_PYOBJECT __repr__();
323  % MethodCode
324  QString str = QStringLiteral( "<QgsDataSourceUri: %1>" ).arg( sipCpp->uri( false ) );
325  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
326  % End
327 #endif
328 
329  private:
330  void skipBlanks( const QString &uri, int &i );
331  QString getValue( const QString &uri, int &i );
332  QString escape( const QString &uri, QChar delim ) const;
333 
334  /* data */
335 
337  QString mHost;
339  QString mPort;
341  QString mDriver;
343  QString mService;
345  QString mDatabase;
347  QString mSchema;
349  QString mTable;
351  QString mGeometryColumn;
353  QString mSql;
355  QString mAuthConfigId;
357  QString mUsername;
359  QString mPassword;
361  SslMode mSSLmode = SslPrefer;
363  QString mKeyColumn;
365  bool mUseEstimatedMetadata = false;
367  bool mSelectAtIdDisabled = false;
371  QString mSrid;
373  QMultiMap<QString, QString> mParams;
374 };
375 
376 #endif //QGSDATASOURCEURI_H
377 
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).
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
#define str(x)
Definition: qgis.cpp:37
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81