QGIS API Documentation  2.15.0-Master (af20121)
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.h"
23 
24 #include <QMap>
25 
35 class CORE_EXPORT QgsDataSourceURI
36 {
37  public:
38  enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire, SSLverifyCA, SSLverifyFull };
39 
42 
45 
47  QgsDataSourceURI( const QByteArray & uri );
48 
50  QString connectionInfo( bool expandAuthConfig = true ) const;
51 
53  QString uri( bool expandAuthConfig = true ) const;
54 
56  QByteArray encodedUri() const;
57 
59  // \note not available in python bindings
60  void setEncodedUri( const QByteArray & uri );
61 
63  void setEncodedUri( const QString & uri );
64 
66  QString quotedTablename() const;
67 
69  // \note if key exists, another is inserted
70  void setParam( const QString &key, const QString &value );
72  void setParam( const QString &key, const QStringList &value );
73 
75  // \note remove all occurrences of key, returns number of params removed
76  int removeParam( const QString &key );
77 
79  QString param( const QString &key ) const;
80 
82  QStringList params( const QString &key ) const;
83 
85  bool hasParam( const QString &key ) const;
86 
88  void setConnection( const QString& aHost,
89  const QString& aPort,
90  const QString& aDatabase,
91  const QString& aUsername,
92  const QString& aPassword,
93  SSLmode sslmode = SSLprefer,
94  const QString& authConfigId = QString() );
95 
97  void setConnection( const QString& aService,
98  const QString& aDatabase,
99  const QString& aUsername,
100  const QString& aPassword,
101  SSLmode sslmode = SSLprefer,
102  const QString& authConfigId = QString() );
103 
105  void setDatabase( const QString &database );
106 
108  void setDataSource( const QString& aSchema,
109  const QString& aTable,
110  const QString& aGeometryColumn,
111  const QString& aSql = QString(),
112  const QString& aKeyColumn = QString() );
113 
115  void setAuthConfigId( const QString& authcfg );
116 
118  void setUsername( const QString& username );
119 
121  void setPassword( const QString& password );
122 
124  static QString removePassword( const QString& aUri );
125 
127  QString authConfigId() const;
128 
130  QString username() const;
131 
133  QString schema() const;
134 
136  QString table() const;
137 
139  QString sql() const;
140 
142  QString geometryColumn() const;
143 
145  void setUseEstimatedMetadata( bool theFlag );
146 
148  bool useEstimatedMetadata() const;
149 
151  void disableSelectAtId( bool theFlag );
153  bool selectAtIdDisabled() const;
154 
156  void clearSchema();
157 
159  // @note added in 2.11
160  void setSchema( const QString& schema );
161 
163  void setSql( const QString& sql );
164 
166  QString host() const;
168  QString database() const;
170  QString port() const;
172  // @note added in QGIS 2.16
173  QString driver() const;
175  // @note added in QGIS 2.16
176  void setDriver( const QString& driver );
178  QString password() const;
180  enum SSLmode sslMode() const;
181 
183  QString service() const;
184 
186  QString keyColumn() const;
188  void setKeyColumn( const QString& column );
189 
192  Q_DECL_DEPRECATED QGis::WkbType wkbType() const;
193 
196  QgsWKBTypes::Type newWkbType() const;
197 
199  Q_DECL_DEPRECATED void setWkbType( QGis::WkbType type );
200 
202  void setWkbType( QgsWKBTypes::Type type );
203 
205  QString srid() const;
207  void setSrid( const QString& srid );
208 
209  private:
210  void skipBlanks( const QString &uri, int &i );
211  QString getValue( const QString &uri, int &i );
212  QString escape( const QString &uri, QChar delim ) const;
213 
214  /* data */
215 
217  QString mHost;
219  QString mPort;
221  QString mDriver;
223  QString mService;
225  QString mDatabase;
227  QString mSchema;
229  QString mTable;
231  QString mGeometryColumn;
233  QString mSql;
235  QString mAuthConfigId;
237  QString mUsername;
239  QString mPassword;
241  enum SSLmode mSSLmode;
243  QString mKeyColumn;
245  bool mUseEstimatedMetadata;
247  bool mSelectAtIdDisabled;
249  QgsWKBTypes::Type mWkbType;
251  QString mSrid;
253  QMap<QString, QString> mParams;
254 };
255 
256 #endif //QGSDATASOURCEURI_H
257 
WkbType
Used for symbology operations.
Definition: qgis.h:61
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.