QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsabstractdatabaseproviderconnection.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsabstractdatabaseproviderconnection.h - QgsAbstractDatabaseProviderConnection
3 
4  ---------------------
5  begin : 2.8.2019
6  copyright : (C) 2019 by Alessandro Pasotti
7  email : elpaso at itopen dot it
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSABSTRACTDATABASEPROVIDERCONNECTION_H
17 #define QGSABSTRACTDATABASEPROVIDERCONNECTION_H
18 
21 #include "qgis_core.h"
22 #include "qgsfields.h"
23 #include "qgsexception.h"
24 
25 #include <QObject>
26 
41 {
42 
43  Q_GADGET
44 
45  public:
46 
53  enum TableFlag
54  {
55  Aspatial = 1 << 1,
56  Vector = 1 << 2,
57  Raster = 1 << 3,
58  View = 1 << 4,
59  MaterializedView = 1 << 5,
60  };
61 
62  Q_ENUMS( TableFlag )
63  Q_DECLARE_FLAGS( TableFlags, TableFlag )
64  Q_FLAG( TableFlags )
65 
66 
77  struct CORE_EXPORT TableProperty
78  {
79 
80 #ifdef SIP_RUN
81  SIP_PYOBJECT __repr__();
82  % MethodCode
83  QString str = QStringLiteral( "<QgsAbstractDatabaseProviderConnection.TableProperty: '%1'>" ).arg( sipCpp->tableName() );
84  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
85  % End
86 #endif
87 
92  struct CORE_EXPORT GeometryColumnType
93  {
94 #ifdef SIP_RUN
95  SIP_PYOBJECT __repr__();
96  % MethodCode
97  QString str = QStringLiteral( "<QgsAbstractDatabaseProviderConnection.TableProperty.GeometryColumnType: '%1, %2'>" ).arg( QgsWkbTypes::displayString( sipCpp->wkbType ), sipCpp->crs.authid() );
98  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
99  % End
100 #endif
103 
104  inline bool operator==( const GeometryColumnType &other ) const
105  {
106  return this->crs == other.crs && this->wkbType == other.wkbType;
107  }
108  };
109 
110  public:
111 
116  QString tableName() const;
117 
122  void setTableName( const QString &name );
123 
127  void addGeometryColumnType( const QgsWkbTypes::Type &type, const QgsCoordinateReferenceSystem &crs );
128 
133  QList<QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType> geometryColumnTypes() const;
134 
138  void setGeometryColumnTypes( const QList<QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType> &geometryColumnTypes );
139 
147  QString defaultName() const;
148 
153  TableProperty at( int index ) const;
154 
158  QString schema() const;
159 
163  void setSchema( const QString &schema );
164 
168  QString geometryColumn() const;
169 
173  void setGeometryColumn( const QString &geometryColumn );
174 
178  QStringList primaryKeyColumns() const;
179 
183  void setPrimaryKeyColumns( const QStringList &primaryKeyColumns );
184 
188  QList<QgsCoordinateReferenceSystem> crsList() const;
189 
193  TableFlags flags() const;
194 
198  void setFlags( const TableFlags &flags );
199 
203  QString comment() const;
204 
208  void setComment( const QString &comment );
209 
216  QVariantMap info() const;
217 
224  void setInfo( const QVariantMap &info );
225 
231  int geometryColumnCount() const;
232 
236  void setGeometryColumnCount( int geometryColumnCount );
237 
241  void setFlag( const TableFlag &flag );
242 
248  int maxCoordinateDimensions() const;
249 
250 
251  private:
252 
254  QList<GeometryColumnType> mGeometryColumnTypes;
256  QString mSchema;
258  QString mTableName;
260  QString mGeometryColumn;
262  int mGeometryColumnCount;
264  QStringList mPkColumns;
265  TableFlags mFlags;
266  QString mComment;
268  QVariantMap mInfo;
269  };
270 
275  {
276  CreateVectorTable = 1 << 1,
277  DropRasterTable = 1 << 2,
278  DropVectorTable = 1 << 3,
279  RenameVectorTable = 1 << 4,
280  RenameRasterTable = 1 << 5,
281  CreateSchema = 1 << 6,
282  DropSchema = 1 << 7,
283  RenameSchema = 1 << 8,
284  ExecuteSql = 1 << 9,
285  Vacuum = 1 << 10,
286  Tables = 1 << 11,
287  Schemas = 1 << 12,
288  SqlLayers = 1 << 13,
289  TableExists = 1 << 14,
290  Spatial = 1 << 15,
291  };
292 
293  Q_ENUM( Capability )
294  Q_DECLARE_FLAGS( Capabilities, Capability )
295  Q_FLAG( Capabilities )
296 
297 
301  QgsAbstractDatabaseProviderConnection( const QString &name );
302 
308  QgsAbstractDatabaseProviderConnection( const QString &uri, const QVariantMap &configuration );
309 
310 
311  // Public interface
312 
316  Capabilities capabilities() const;
317 
318  // Operations interface
319 
325  virtual void createVectorTable( const QString &schema, const QString &name, const QgsFields &fields, QgsWkbTypes::Type wkbType, const QgsCoordinateReferenceSystem &srs, bool overwrite, const QMap<QString, QVariant> *options ) const SIP_THROW( QgsProviderConnectionException );
326 
332  virtual bool tableExists( const QString &schema, const QString &name ) const SIP_THROW( QgsProviderConnectionException );
333 
340  virtual void dropVectorTable( const QString &schema, const QString &name ) const SIP_THROW( QgsProviderConnectionException );
341 
348  virtual void dropRasterTable( const QString &schema, const QString &name ) const SIP_THROW( QgsProviderConnectionException );
349 
356  virtual void renameVectorTable( const QString &schema, const QString &name, const QString &newName ) const SIP_THROW( QgsProviderConnectionException );
357 
364  virtual void renameRasterTable( const QString &schema, const QString &name, const QString &newName ) const SIP_THROW( QgsProviderConnectionException );
365 
370  virtual void createSchema( const QString &name ) const SIP_THROW( QgsProviderConnectionException );
371 
380  virtual void dropSchema( const QString &name, bool force = false ) const SIP_THROW( QgsProviderConnectionException );
381 
388  virtual void renameSchema( const QString &name, const QString &newName ) const SIP_THROW( QgsProviderConnectionException );
389 
395  virtual QList<QList<QVariant>> executeSql( const QString &sql ) const SIP_THROW( QgsProviderConnectionException );
396 
402  virtual void vacuum( const QString &schema, const QString &name ) const SIP_THROW( QgsProviderConnectionException );
403 
412  virtual QList<QgsAbstractDatabaseProviderConnection::TableProperty> tables( const QString &schema = QString(), const QgsAbstractDatabaseProviderConnection::TableFlags &flags = nullptr ) const SIP_SKIP;
413 
421  QList<QgsAbstractDatabaseProviderConnection::TableProperty> tablesInt( const QString &schema = QString(), const int flags = 0 ) const SIP_THROW( QgsProviderConnectionException ) SIP_PYNAME( tables );
422 
423 
424  // TODO: return more schema information and not just the name
425 
431  virtual QStringList schemas() const SIP_THROW( QgsProviderConnectionException );
432 
433  protected:
434 
436 
441  void checkCapability( Capability capability ) const;
443 
444  Capabilities mCapabilities = nullptr SIP_SKIP;
445 
446 };
447 
448 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAbstractDatabaseProviderConnection::Capabilities )
449 
450 #endif // QGSABSTRACTDATABASEPROVIDERCONNECTION_H
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
Capability
The Capability enum represent the operations supported by the connection.
Container of fields for a vector layer.
Definition: qgsfields.h:42
const QgsCoordinateReferenceSystem & crs
The QgsAbstractProviderConnection provides an interface for data provider connections.
The GeometryColumnType struct represents the combination of geometry type and CRS for the table geome...
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
The TableProperty class represents a database table or view.
#define SIP_SKIP
Definition: qgis_sip.h:126
This class represents a coordinate reference system (CRS).
static QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
#define SIP_THROW(name)
Definition: qgis_sip.h:184
Custom exception class for provider connection related exceptions.
Definition: qgsexception.h:100
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81