QGIS API Documentation  3.6.0-Noosa (5873452)
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 
37 // (Radim Blazek 4/2012)
38 class CORE_EXPORT QgsDataSourceUri
39 {
40  Q_GADGET
41  public:
42  enum SslMode
43  {
49  SslVerifyFull
50  };
51  Q_ENUM( SslMode )
52 
53 
55 
57  QgsDataSourceUri( QString uri );
58 
63  QgsDataSourceUri( const QByteArray &uri ) SIP_SKIP;
64 
66  QString connectionInfo( bool expandAuthConfig = true ) const;
67 
69  QString uri( bool expandAuthConfig = true ) const;
70 
72  QByteArray encodedUri() const;
73 
78  void setEncodedUri( const QByteArray &uri ) SIP_SKIP;
79 
81  void setEncodedUri( const QString &uri );
82 
84  QString quotedTablename() const;
85 
90  void setParam( const QString &key, const QString &value );
92  void setParam( const QString &key, const QStringList &value ) SIP_PYNAME( setParamList );
93 
98  int removeParam( const QString &key );
99 
101  QString param( const QString &key ) const;
102 
104  QStringList params( const QString &key ) const;
105 
107  bool hasParam( const QString &key ) const;
108 
110  void setConnection( const QString &aHost,
111  const QString &aPort,
112  const QString &aDatabase,
113  const QString &aUsername,
114  const QString &aPassword,
115  SslMode sslmode = SslPrefer,
116  const QString &authConfigId = QString() );
117 
119  void setConnection( const QString &aService,
120  const QString &aDatabase,
121  const QString &aUsername,
122  const QString &aPassword,
123  SslMode sslmode = SslPrefer,
124  const QString &authConfigId = QString() );
125 
127  void setDatabase( const QString &database );
128 
130  void setDataSource( const QString &aSchema,
131  const QString &aTable,
132  const QString &aGeometryColumn,
133  const QString &aSql = QString(),
134  const QString &aKeyColumn = QString() );
135 
137  void setAuthConfigId( const QString &authcfg );
138 
140  void setUsername( const QString &username );
141 
143  void setPassword( const QString &password );
144 
146  static QString removePassword( const QString &aUri );
147 
149  QString authConfigId() const;
150 
152  QString username() const;
153 
155  QString schema() const;
156 
158  QString table() const;
159 
161  QString sql() const;
162 
164  QString geometryColumn() const;
165 
167  void setUseEstimatedMetadata( bool flag );
168 
170  bool useEstimatedMetadata() const;
171 
173  void disableSelectAtId( bool flag );
175  bool selectAtIdDisabled() const;
176 
178  void clearSchema();
179 
181  // \since QGIS 2.11
182  void setSchema( const QString &schema );
183 
185  void setSql( const QString &sql );
186 
188  QString host() const;
190  QString database() const;
192  QString port() const;
194  // \since QGIS 2.16
195  QString driver() const;
197  // \since QGIS 2.16
198  void setDriver( const QString &driver );
200  QString password() const;
202  SslMode sslMode() const;
203 
205  QString service() const;
206 
208  QString keyColumn() const;
210  void setKeyColumn( const QString &column );
211 
215  QgsWkbTypes::Type wkbType() const;
216 
218  void setWkbType( QgsWkbTypes::Type type );
219 
221  QString srid() const;
223  void setSrid( const QString &srid );
224 
229  static SslMode decodeSslMode( const QString &sslMode );
230 
235  static QString encodeSslMode( SslMode sslMode );
236 
237  private:
238  void skipBlanks( const QString &uri, int &i );
239  QString getValue( const QString &uri, int &i );
240  QString escape( const QString &uri, QChar delim ) const;
241 
242  /* data */
243 
245  QString mHost;
247  QString mPort;
249  QString mDriver;
251  QString mService;
253  QString mDatabase;
255  QString mSchema;
257  QString mTable;
259  QString mGeometryColumn;
261  QString mSql;
263  QString mAuthConfigId;
265  QString mUsername;
267  QString mPassword;
269  SslMode mSSLmode = SslPrefer;
271  QString mKeyColumn;
273  bool mUseEstimatedMetadata = false;
275  bool mSelectAtIdDisabled = false;
279  QString mSrid;
281  QMap<QString, QString> mParams;
282 };
283 
284 #endif //QGSDATASOURCEURI_H
285 
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
#define SIP_SKIP
Definition: qgis_sip.h:119
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:74