QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
39  enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };
40 
43 
45  QgsDataSourceURI( QString uri );
46 
48  // \note added in 1.9
49  QgsDataSourceURI( const QByteArray & uri );
50 
52  QString connectionInfo() const;
53 
55  QString uri() const;
56 
58  // \note added in 1.9
59  QByteArray encodedUri() const;
60 
62  // \note added in 1.9
63  // \note not available in python bindings
64  void setEncodedUri( const QByteArray & uri );
65 
67  // \note added in 1.9
68  void setEncodedUri( const QString & uri );
69 
71  QString quotedTablename() const;
72 
74  // \note if key exists, another is inserted
75  // \note added in 1.9
76  void setParam( const QString &key, const QString &value );
77  void setParam( const QString &key, const QStringList &value );
78 
80  // \note remove all occurrences of key, returns number of params removed
81  // \note added in 1.9
82  int removeParam( const QString &key );
83 
85  // \note added in 1.9
86  QString param( const QString &key ) const;
87 
89  // \note added in 1.9
90  QStringList params( const QString &key ) const;
91 
93  // \note added in 1.9
94  bool hasParam( const QString &key ) const;
95 
98  void setConnection( const QString& aHost,
99  const QString& aPort,
100  const QString& aDatabase,
101  const QString& aUsername,
102  const QString& aPassword,
103  SSLmode sslmode = SSLprefer );
104 
107  void setConnection( const QString& aService,
108  const QString& aDatabase,
109  const QString& aUsername,
110  const QString& aPassword,
111  SSLmode sslmode = SSLprefer );
112 
114  // \note added in 1.4
115  void setDatabase( const QString &database );
116 
118  void setDataSource( const QString& aSchema,
119  const QString& aTable,
120  const QString& aGeometryColumn,
121  const QString& aSql = QString(),
122  const QString& aKeyColumn = QString() );
123 
125  // added in 1.5
126  void setUsername( QString username );
127 
129  // added in 1.5
130  void setPassword( QString password );
131 
133  static QString removePassword( const QString& aUri );
134 
135  QString username() const;
136  QString schema() const;
137  QString table() const;
138  QString sql() const;
139  QString geometryColumn() const;
140 
142  // added in 1.5
143  void setUseEstimatedMetadata( bool theFlag );
144  bool useEstimatedMetadata() const;
145 
146  void disableSelectAtId( bool theFlag );
147  bool selectAtIdDisabled() const;
148 
149  void clearSchema();
150  void setSql( QString sql );
151 
152  // added in version 1.1
153  QString host() const;
154  QString database() const;
155  QString port() const;
156  QString password() const;
157  enum SSLmode sslMode() const;
158 
159  // added in 1.7
160  QString service() const;
161 
162  // added in version 1.2
163  QString keyColumn() const;
164  void setKeyColumn( QString column );
165 
166  // added in 1.9
167  QGis::WkbType wkbType() const;
168  void setWkbType( QGis::WkbType type );
169 
170  // added in 1.9
171  QString srid() const;
172  void setSrid( QString srid );
173 
174  private:
175  void skipBlanks( const QString &uri, int &i );
176  QString getValue( const QString &uri, int &i );
177  QString escape( const QString &uri, QChar delim ) const;
178 
179  /* data */
180 
182  QString mHost;
184  QString mPort;
186  QString mService;
188  QString mDatabase;
190  QString mSchema;
192  QString mTable;
196  QString mSql;
198  QString mUsername;
200  QString mPassword;
204  QString mKeyColumn;
212  QString mSrid;
214  QMap<QString, QString> mParams;
215 };
216 
217 #endif //QGSDATASOURCEURI_H
218