QGIS API Documentation  2.99.0-Master (0a63d1f)
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 
35 // (Radim Blazek 4/2012)
36 class CORE_EXPORT QgsDataSourceUri
37 {
38  public:
39  enum SslMode { SslPrefer, SslDisable, SslAllow, SslRequire, SslVerifyCa, SslVerifyFull };
40 
43 
45  QgsDataSourceUri( QString uri );
46 
48  QgsDataSourceUri( const QByteArray & uri );
49 
51  QString connectionInfo( bool expandAuthConfig = true ) const;
52 
54  QString uri( bool expandAuthConfig = true ) const;
55 
57  QByteArray encodedUri() const;
58 
60  // \note not available in python bindings
61  void setEncodedUri( const QByteArray & uri );
62 
64  void setEncodedUri( const QString & uri );
65 
67  QString quotedTablename() const;
68 
70  // \note if key exists, another is inserted
71  void setParam( const QString &key, const QString &value );
73  void setParam( const QString &key, const QStringList &value );
74 
76  // \note remove all occurrences of key, returns number of params removed
77  int removeParam( const QString &key );
78 
80  QString param( const QString &key ) const;
81 
83  QStringList params( const QString &key ) const;
84 
86  bool hasParam( const QString &key ) const;
87 
89  void setConnection( const QString& aHost,
90  const QString& aPort,
91  const QString& aDatabase,
92  const QString& aUsername,
93  const QString& aPassword,
94  SslMode sslmode = SslPrefer,
95  const QString& authConfigId = QString() );
96 
98  void setConnection( const QString& aService,
99  const QString& aDatabase,
100  const QString& aUsername,
101  const QString& aPassword,
102  SslMode sslmode = SslPrefer,
103  const QString& authConfigId = QString() );
104 
106  void setDatabase( const QString &database );
107 
109  void setDataSource( const QString& aSchema,
110  const QString& aTable,
111  const QString& aGeometryColumn,
112  const QString& aSql = QString(),
113  const QString& aKeyColumn = QString() );
114 
116  void setAuthConfigId( const QString& authcfg );
117 
119  void setUsername( const QString& username );
120 
122  void setPassword( const QString& password );
123 
125  static QString removePassword( const QString& aUri );
126 
128  QString authConfigId() const;
129 
131  QString username() const;
132 
134  QString schema() const;
135 
137  QString table() const;
138 
140  QString sql() const;
141 
143  QString geometryColumn() const;
144 
146  void setUseEstimatedMetadata( bool theFlag );
147 
149  bool useEstimatedMetadata() const;
150 
152  void disableSelectAtId( bool theFlag );
154  bool selectAtIdDisabled() const;
155 
157  void clearSchema();
158 
160  // @note added in 2.11
161  void setSchema( const QString& schema );
162 
164  void setSql( const QString& sql );
165 
167  QString host() const;
169  QString database() const;
171  QString port() const;
173  // @note added in QGIS 2.16
174  QString driver() const;
176  // @note added in QGIS 2.16
177  void setDriver( const QString& driver );
179  QString password() const;
181  enum SslMode sslMode() const;
182 
184  QString service() const;
185 
187  QString keyColumn() const;
189  void setKeyColumn( const QString& column );
190 
193  QgsWkbTypes::Type wkbType() const;
194 
196  void setWkbType( QgsWkbTypes::Type type );
197 
199  QString srid() const;
201  void setSrid( const QString& srid );
202 
203  private:
204  void skipBlanks( const QString &uri, int &i );
205  QString getValue( const QString &uri, int &i );
206  QString escape( const QString &uri, QChar delim ) const;
207 
208  /* data */
209 
211  QString mHost;
213  QString mPort;
215  QString mDriver;
217  QString mService;
219  QString mDatabase;
221  QString mSchema;
223  QString mTable;
225  QString mGeometryColumn;
227  QString mSql;
229  QString mAuthConfigId;
231  QString mUsername;
233  QString mPassword;
235  enum SslMode mSSLmode;
237  QString mKeyColumn;
239  bool mUseEstimatedMetadata;
241  bool mSelectAtIdDisabled;
243  QgsWkbTypes::Type mWkbType;
245  QString mSrid;
247  QMap<QString, QString> mParams;
248 };
249 
250 #endif //QGSDATASOURCEURI_H
251 
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:65
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.