QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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  Foreign = 1 << 6,
61  };
62 
63  Q_ENUMS( TableFlag )
64  Q_DECLARE_FLAGS( TableFlags, TableFlag )
65  Q_FLAG( TableFlags )
66 
67 
78  struct CORE_EXPORT TableProperty
79  {
80 
81 #ifdef SIP_RUN
82  SIP_PYOBJECT __repr__();
83  % MethodCode
84  QString str = QStringLiteral( "<QgsAbstractDatabaseProviderConnection.TableProperty: '%1'>" ).arg( sipCpp->tableName() );
85  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
86  % End
87 #endif
88 
93  struct CORE_EXPORT GeometryColumnType
94  {
95 #ifdef SIP_RUN
96  SIP_PYOBJECT __repr__();
97  % MethodCode
98  QString str = QStringLiteral( "<QgsAbstractDatabaseProviderConnection.TableProperty.GeometryColumnType: '%1, %2'>" ).arg( QgsWkbTypes::displayString( sipCpp->wkbType ), sipCpp->crs.authid() );
99  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
100  % End
101 #endif
102  QgsWkbTypes::Type wkbType;
104 
105  inline bool operator==( const GeometryColumnType &other ) const
106  {
107  return this->crs == other.crs && this->wkbType == other.wkbType;
108  }
109  };
110 
111  public:
112 
117  QString tableName() const;
118 
123  void setTableName( const QString &name );
124 
128  void addGeometryColumnType( const QgsWkbTypes::Type &type, const QgsCoordinateReferenceSystem &crs );
129 
134  QList<QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType> geometryColumnTypes() const;
135 
139  void setGeometryColumnTypes( const QList<QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType> &geometryColumnTypes );
140 
148  QString defaultName() const;
149 
154  TableProperty at( int index ) const;
155 
159  QString schema() const;
160 
164  void setSchema( const QString &schema );
165 
169  QString geometryColumn() const;
170 
174  void setGeometryColumn( const QString &geometryColumn );
175 
179  QStringList primaryKeyColumns() const;
180 
184  void setPrimaryKeyColumns( const QStringList &primaryKeyColumns );
185 
189  QList<QgsCoordinateReferenceSystem> crsList() const;
190 
194  TableFlags flags() const;
195 
199  void setFlags( const TableFlags &flags );
200 
204  QString comment() const;
205 
209  void setComment( const QString &comment );
210 
217  QVariantMap info() const;
218 
225  void setInfo( const QVariantMap &info );
226 
232  int geometryColumnCount() const;
233 
237  void setGeometryColumnCount( int geometryColumnCount );
238 
242  void setFlag( const TableFlag &flag );
243 
249  int maxCoordinateDimensions() const;
250 
252 
253  private:
254 
256  QList<GeometryColumnType> mGeometryColumnTypes;
258  QString mSchema;
260  QString mTableName;
262  QString mGeometryColumn;
264  int mGeometryColumnCount;
266  QStringList mPkColumns;
267  TableFlags mFlags;
268  QString mComment;
270  QVariantMap mInfo;
271  };
272 
276  enum Capability
277  {
278  CreateVectorTable = 1 << 1,
279  DropRasterTable = 1 << 2,
280  DropVectorTable = 1 << 3,
281  RenameVectorTable = 1 << 4,
282  RenameRasterTable = 1 << 5,
283  CreateSchema = 1 << 6,
284  DropSchema = 1 << 7,
285  RenameSchema = 1 << 8,
286  ExecuteSql = 1 << 9,
287  Vacuum = 1 << 10,
288  Tables = 1 << 11,
289  Schemas = 1 << 12,
290  SqlLayers = 1 << 13,
291  TableExists = 1 << 14,
292  Spatial = 1 << 15,
293  CreateSpatialIndex = 1 << 16,
294  SpatialIndexExists = 1 << 17,
295  DeleteSpatialIndex = 1 << 18,
296  };
297 
298  Q_ENUM( Capability )
299  Q_DECLARE_FLAGS( Capabilities, Capability )
300  Q_FLAG( Capabilities )
301 
307 
313  QgsAbstractDatabaseProviderConnection( const QString &uri, const QVariantMap &configuration );
314 
315 
316  // Public interface
317 
321  Capabilities capabilities() const;
322 
323  // Operations interface
324 
331  virtual QString tableUri( const QString &schema, const QString &name ) const SIP_THROW( QgsProviderConnectionException );
332 
338  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 );
339 
345  virtual bool tableExists( const QString &schema, const QString &name ) const SIP_THROW( QgsProviderConnectionException );
346 
353  virtual void dropVectorTable( const QString &schema, const QString &name ) const SIP_THROW( QgsProviderConnectionException );
354 
361  virtual void dropRasterTable( const QString &schema, const QString &name ) const SIP_THROW( QgsProviderConnectionException );
362 
369  virtual void renameVectorTable( const QString &schema, const QString &name, const QString &newName ) const SIP_THROW( QgsProviderConnectionException );
370 
377  virtual void renameRasterTable( const QString &schema, const QString &name, const QString &newName ) const SIP_THROW( QgsProviderConnectionException );
378 
383  virtual void createSchema( const QString &name ) const SIP_THROW( QgsProviderConnectionException );
384 
393  virtual void dropSchema( const QString &name, bool force = false ) const SIP_THROW( QgsProviderConnectionException );
394 
401  virtual void renameSchema( const QString &name, const QString &newName ) const SIP_THROW( QgsProviderConnectionException );
402 
408  virtual QList<QList<QVariant>> executeSql( const QString &sql ) const SIP_THROW( QgsProviderConnectionException );
409 
415  virtual void vacuum( const QString &schema, const QString &name ) const SIP_THROW( QgsProviderConnectionException );
416 
422  struct CORE_EXPORT SpatialIndexOptions
423  {
425  QString geometryColumnName;
426  };
427 
437  virtual void createSpatialIndex( const QString &schema, const QString &name, const QgsAbstractDatabaseProviderConnection::SpatialIndexOptions &options = QgsAbstractDatabaseProviderConnection::SpatialIndexOptions() ) const SIP_THROW( QgsProviderConnectionException );
438 
447  virtual bool spatialIndexExists( const QString &schema, const QString &name, const QString &geometryColumn ) const SIP_THROW( QgsProviderConnectionException );
448 
457  virtual void deleteSpatialIndex( const QString &schema, const QString &name, const QString &geometryColumn ) const SIP_THROW( QgsProviderConnectionException );
458 
467  virtual QList<QgsAbstractDatabaseProviderConnection::TableProperty> tables( const QString &schema = QString(), const QgsAbstractDatabaseProviderConnection::TableFlags &flags = nullptr ) const SIP_SKIP;
468 
476  virtual QgsAbstractDatabaseProviderConnection::TableProperty table( const QString &schema, const QString &table ) const;
477 
485  QList<QgsAbstractDatabaseProviderConnection::TableProperty> tablesInt( const QString &schema = QString(), const int flags = 0 ) const SIP_THROW( QgsProviderConnectionException ) SIP_PYNAME( tables );
486 
487 
488  // TODO: return more schema information and not just the name
489 
495  virtual QStringList schemas() const SIP_THROW( QgsProviderConnectionException );
496 
497  protected:
498 
500 
505  void checkCapability( Capability capability ) const;
507 
508  Capabilities mCapabilities = nullptr SIP_SKIP;
509 
510 };
511 
512 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAbstractDatabaseProviderConnection::Capabilities )
513 
514 #endif // QGSABSTRACTDATABASEPROVIDERCONNECTION_H
SIP_PYNAME
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
qgsfields.h
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:399
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsFields
Definition: qgsfields.h:44
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
QgsAbstractDatabaseProviderConnection::TableProperty
The TableProperty class represents a database table or view.
Definition: qgsabstractdatabaseproviderconnection.h:92
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
SIP_THROW
#define SIP_THROW(name)
Definition: qgis_sip.h:184
QgsProviderConnectionException
Definition: qgsexception.h:100
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsAbstractDatabaseProviderConnection::SpatialIndexOptions
Contains extra options relating to spatial index creation.
Definition: qgsabstractdatabaseproviderconnection.h:436
QgsAbstractDatabaseProviderConnection::Capability
Capability
The Capability enum represent the operations supported by the connection.
Definition: qgsabstractdatabaseproviderconnection.h:290
QgsWkbTypes::displayString
static QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
Definition: qgswkbtypes.cpp:145
QgsAbstractDatabaseProviderConnection::TableFlag
TableFlag
Flags for table properties.
Definition: qgsabstractdatabaseproviderconnection.h:67
qgsexception.h
QgsWkbTypes
Handles storage of information regarding WKB types and their properties.
Definition: qgswkbtypes.h:40
QgsAbstractProviderConnection
The QgsAbstractProviderConnection provides an interface for data provider connections.
Definition: qgsabstractproviderconnection.h:44
qgscoordinatereferencesystem.h
QgsAbstractDatabaseProviderConnection
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
Definition: qgsabstractdatabaseproviderconnection.h:40
qgsabstractproviderconnection.h