QGIS API Documentation  3.2.0-Bonn (bc43194)
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.h"
24 
25 #include <QMap>
26 
36 // (Radim Blazek 4/2012)
37 class CORE_EXPORT QgsDataSourceUri
38 {
39  Q_GADGET
40  public:
41  enum SslMode
42  {
48  SslVerifyFull
49  };
50  Q_ENUM( SslMode )
51 
52 
54 
56  QgsDataSourceUri( QString uri );
57 
62  QgsDataSourceUri( const QByteArray &uri ) SIP_SKIP;
63 
65  QString connectionInfo( bool expandAuthConfig = true ) const;
66 
68  QString uri( bool expandAuthConfig = true ) const;
69 
71  QByteArray encodedUri() const;
72 
77  void setEncodedUri( const QByteArray &uri ) SIP_SKIP;
78 
80  void setEncodedUri( const QString &uri );
81 
83  QString quotedTablename() const;
84 
89  void setParam( const QString &key, const QString &value );
91  void setParam( const QString &key, const QStringList &value ) SIP_PYNAME( setParamList );
92 
97  int removeParam( const QString &key );
98 
100  QString param( const QString &key ) const;
101 
103  QStringList params( const QString &key ) const;
104 
106  bool hasParam( const QString &key ) const;
107 
109  void setConnection( const QString &aHost,
110  const QString &aPort,
111  const QString &aDatabase,
112  const QString &aUsername,
113  const QString &aPassword,
114  SslMode sslmode = SslPrefer,
115  const QString &authConfigId = QString() );
116 
118  void setConnection( const QString &aService,
119  const QString &aDatabase,
120  const QString &aUsername,
121  const QString &aPassword,
122  SslMode sslmode = SslPrefer,
123  const QString &authConfigId = QString() );
124 
126  void setDatabase( const QString &database );
127 
129  void setDataSource( const QString &aSchema,
130  const QString &aTable,
131  const QString &aGeometryColumn,
132  const QString &aSql = QString(),
133  const QString &aKeyColumn = QString() );
134 
136  void setAuthConfigId( const QString &authcfg );
137 
139  void setUsername( const QString &username );
140 
142  void setPassword( const QString &password );
143 
145  static QString removePassword( const QString &aUri );
146 
148  QString authConfigId() const;
149 
151  QString username() const;
152 
154  QString schema() const;
155 
157  QString table() const;
158 
160  QString sql() const;
161 
163  QString geometryColumn() const;
164 
166  void setUseEstimatedMetadata( bool flag );
167 
169  bool useEstimatedMetadata() const;
170 
172  void disableSelectAtId( bool flag );
174  bool selectAtIdDisabled() const;
175 
177  void clearSchema();
178 
180  // \since QGIS 2.11
181  void setSchema( const QString &schema );
182 
184  void setSql( const QString &sql );
185 
187  QString host() const;
189  QString database() const;
191  QString port() const;
193  // \since QGIS 2.16
194  QString driver() const;
196  // \since QGIS 2.16
197  void setDriver( const QString &driver );
199  QString password() const;
201  SslMode sslMode() const;
202 
204  QString service() const;
205 
207  QString keyColumn() const;
209  void setKeyColumn( const QString &column );
210 
214  QgsWkbTypes::Type wkbType() const;
215 
217  void setWkbType( QgsWkbTypes::Type type );
218 
220  QString srid() const;
222  void setSrid( const QString &srid );
223 
228  static SslMode decodeSslMode( const QString &sslMode );
229 
234  static QString encodeSslMode( SslMode sslMode );
235 
236  private:
237  void skipBlanks( const QString &uri, int &i );
238  QString getValue( const QString &uri, int &i );
239  QString escape( const QString &uri, QChar delim ) const;
240 
241  /* data */
242 
244  QString mHost;
246  QString mPort;
248  QString mDriver;
250  QString mService;
252  QString mDatabase;
254  QString mSchema;
256  QString mTable;
258  QString mGeometryColumn;
260  QString mSql;
262  QString mAuthConfigId;
264  QString mUsername;
266  QString mPassword;
268  SslMode mSSLmode = SslPrefer;
270  QString mKeyColumn;
272  bool mUseEstimatedMetadata = false;
274  bool mSelectAtIdDisabled = false;
278  QString mSrid;
280  QMap<QString, QString> mParams;
281 };
282 
283 #endif //QGSDATASOURCEURI_H
284 
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:67
#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