QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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  {
45  SslPrefer,
46  SslDisable,
47  SslAllow,
48  SslRequire,
49  SslVerifyCa,
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 
162  void setDataSource( const QString &aSchema,
163  const QString &aTable,
164  const QString &aGeometryColumn,
165  const QString &aSql = QString(),
166  const QString &aKeyColumn = QString() );
167 
171  void setAuthConfigId( const QString &authcfg );
172 
176  void setUsername( const QString &username );
177 
181  void setPassword( const QString &password );
182 
186  static QString removePassword( const QString &aUri );
187 
191  QString authConfigId() const;
192 
194  QString username() const;
195 
197  QString schema() const;
198 
200  QString table() const;
201 
203  QString sql() const;
204 
206  QString geometryColumn() const;
207 
209  void setUseEstimatedMetadata( bool flag );
210 
212  bool useEstimatedMetadata() const;
213 
215  void disableSelectAtId( bool flag );
216 
218  bool selectAtIdDisabled() const;
219 
221  void clearSchema();
222 
227  void setSchema( const QString &schema );
228 
230  void setSql( const QString &sql );
231 
233  QString host() const;
235  QString database() const;
237  QString port() const;
238 
243  QString driver() const;
244 
249  void setDriver( const QString &driver );
250 
252  QString password() const;
253 
255  SslMode sslMode() const;
256 
258  QString service() const;
259 
261  QString keyColumn() const;
262 
264  void setKeyColumn( const QString &column );
265 
269  QgsWkbTypes::Type wkbType() const;
270 
272  void setWkbType( QgsWkbTypes::Type type );
273 
275  QString srid() const;
276 
278  void setSrid( const QString &srid );
279 
284  static SslMode decodeSslMode( const QString &sslMode );
285 
290  static QString encodeSslMode( SslMode sslMode );
291 
296  void setTable( const QString &table );
297 
302  void setGeometryColumn( const QString &geometryColumn );
303 
304  private:
305  void skipBlanks( const QString &uri, int &i );
306  QString getValue( const QString &uri, int &i );
307  QString escape( const QString &uri, QChar delim ) const;
308 
309  /* data */
310 
312  QString mHost;
314  QString mPort;
316  QString mDriver;
318  QString mService;
320  QString mDatabase;
322  QString mSchema;
324  QString mTable;
326  QString mGeometryColumn;
328  QString mSql;
330  QString mAuthConfigId;
332  QString mUsername;
334  QString mPassword;
336  SslMode mSSLmode = SslPrefer;
338  QString mKeyColumn;
340  bool mUseEstimatedMetadata = false;
342  bool mSelectAtIdDisabled = false;
346  QString mSrid;
348  QMap<QString, QString> mParams;
349 };
350 
351 #endif //QGSDATASOURCEURI_H
352 
SIP_PYNAME
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
QgsDataSourceUri
Definition: qgsdatasourceuri.h:35
QgsDataSourceUri::SslMode
SslMode
Available SSQL connection modes.
Definition: qgsdatasourceuri.h:57
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:70
qgis_sip.h
qgswkbtypes.h