QGIS API Documentation  2.8.2-Wien
 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:
38  enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };
39 
42 
44  QgsDataSourceURI( QString uri );
45 
47  QgsDataSourceURI( const QByteArray & uri );
48 
50  QString connectionInfo() const;
51 
53  QString uri() 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 );
71  void setParam( const QString &key, const QStringList &value );
72 
74  // \note remove all occurrences of key, returns number of params removed
75  int removeParam( const QString &key );
76 
78  QString param( const QString &key ) const;
79 
81  QStringList params( const QString &key ) const;
82 
84  bool hasParam( const QString &key ) const;
85 
87  void setConnection( const QString& aHost,
88  const QString& aPort,
89  const QString& aDatabase,
90  const QString& aUsername,
91  const QString& aPassword,
92  SSLmode sslmode = SSLprefer );
93 
95  void setConnection( const QString& aService,
96  const QString& aDatabase,
97  const QString& aUsername,
98  const QString& aPassword,
99  SSLmode sslmode = SSLprefer );
100 
102  void setDatabase( const QString &database );
103 
105  void setDataSource( const QString& aSchema,
106  const QString& aTable,
107  const QString& aGeometryColumn,
108  const QString& aSql = QString(),
109  const QString& aKeyColumn = QString() );
110 
112  void setUsername( QString username );
113 
115  void setPassword( QString password );
116 
118  static QString removePassword( const QString& aUri );
119 
120  QString username() const;
121  QString schema() const;
122  QString table() const;
123  QString sql() const;
124  QString geometryColumn() const;
125 
127  void setUseEstimatedMetadata( bool theFlag );
128  bool useEstimatedMetadata() const;
129 
130  void disableSelectAtId( bool theFlag );
131  bool selectAtIdDisabled() const;
132 
133  void clearSchema();
134  void setSql( QString sql );
135 
136  QString host() const;
137  QString database() const;
138  QString port() const;
139  QString password() const;
140  enum SSLmode sslMode() const;
141 
142  QString service() const;
143 
144  QString keyColumn() const;
145  void setKeyColumn( QString column );
146 
147  QGis::WkbType wkbType() const;
148  void setWkbType( QGis::WkbType type );
149 
150  QString srid() const;
151  void setSrid( QString srid );
152 
153  private:
154  void skipBlanks( const QString &uri, int &i );
155  QString getValue( const QString &uri, int &i );
156  QString escape( const QString &uri, QChar delim ) const;
157 
158  /* data */
159 
161  QString mHost;
163  QString mPort;
165  QString mService;
167  QString mDatabase;
169  QString mSchema;
171  QString mTable;
173  QString mGeometryColumn;
175  QString mSql;
177  QString mUsername;
179  QString mPassword;
181  enum SSLmode mSSLmode;
183  QString mKeyColumn;
185  bool mUseEstimatedMetadata;
187  bool mSelectAtIdDisabled;
189  QGis::WkbType mWkbType;
191  QString mSrid;
193  QMap<QString, QString> mParams;
194 };
195 
196 #endif //QGSDATASOURCEURI_H
197