1 /*************************************************************************** 2 qgspostgresproviderconnection.h - QgsPostgresProviderConnection 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 QGSPOSTGRESPROVIDERCONNECTION_H 17 #define QGSPOSTGRESPROVIDERCONNECTION_H 18 #include "qgsabstractdatabaseproviderconnection.h" 19 #include "qgspostgresconnpool.h" 20 21 struct QgsPostgresProviderResultIterator: public QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator 22 { QgsPostgresProviderResultIteratorQgsPostgresProviderResultIterator23 QgsPostgresProviderResultIterator( bool resolveTypes ) 24 : mResolveTypes( resolveTypes ) 25 {} 26 27 QMap<int, QVariant::Type> typeMap; 28 std::unique_ptr<QgsPostgresResult> result; 29 30 private: 31 32 QVariantList nextRowPrivate() override; 33 bool hasNextRowPrivate() const override; 34 long long rowCountPrivate() const override; 35 36 bool mResolveTypes = true; 37 long long mRowIndex = 0; 38 }; 39 40 class QgsPostgresProviderConnection : public QgsAbstractDatabaseProviderConnection 41 { 42 public: 43 44 QgsPostgresProviderConnection( const QString &name ); 45 QgsPostgresProviderConnection( const QString &uri, const QVariantMap &configuration ); 46 47 // QgsAbstractProviderConnection interface 48 49 public: 50 51 void createVectorTable( const QString &schema, 52 const QString &name, 53 const QgsFields &fields, 54 QgsWkbTypes::Type wkbType, 55 const QgsCoordinateReferenceSystem &srs, bool overwrite, 56 const QMap<QString, QVariant> *options ) const override; 57 58 QString tableUri( const QString &schema, const QString &name ) const override; 59 QgsFields fields( const QString &schema, const QString &table ) const override; 60 void dropVectorTable( const QString &schema, const QString &name ) const override; 61 void dropRasterTable( const QString &schema, const QString &name ) const override; 62 void renameVectorTable( const QString &schema, const QString &name, const QString &newName ) const override; 63 void renameRasterTable( const QString &schema, const QString &name, const QString &newName ) const override; 64 void createSchema( const QString &name ) const override; 65 void dropSchema( const QString &name, bool force = false ) const override; 66 void renameSchema( const QString &name, const QString &newName ) const override; 67 QgsAbstractDatabaseProviderConnection::QueryResult execSql( const QString &sql, QgsFeedback *feedback = nullptr ) const override; 68 void vacuum( const QString &schema, const QString &name ) const override; 69 void createSpatialIndex( const QString &schema, const QString &name, const QgsAbstractDatabaseProviderConnection::SpatialIndexOptions &options = QgsAbstractDatabaseProviderConnection::SpatialIndexOptions() ) const override; 70 bool spatialIndexExists( const QString &schema, const QString &name, const QString &geometryColumn ) const override; 71 void deleteSpatialIndex( const QString &schema, const QString &name, const QString &geometryColumn ) const override; 72 QList<QgsAbstractDatabaseProviderConnection::TableProperty> tables( const QString &schema, 73 const TableFlags &flags = TableFlags() ) const override; 74 QStringList schemas( ) const override; 75 void store( const QString &name ) const override; 76 void remove( const QString &name ) const override; 77 QIcon icon() const override; 78 QList<QgsVectorDataProvider::NativeType> nativeTypes() const override; 79 QgsVectorLayer *createSqlVectorLayer( const SqlVectorLayerOptions &options ) const override; 80 QMultiMap<Qgis::SqlKeywordCategory, QStringList> sqlDictionary() override; 81 SqlVectorLayerOptions sqlOptions( const QString &layerSource ) override; 82 83 private: 84 85 QList<QVariantList> executeSqlPrivate( const QString &sql, bool resolveTypes = true, QgsFeedback *feedback = nullptr, std::shared_ptr< class QgsPoolPostgresConn > pgconn = nullptr ) const; 86 QgsAbstractDatabaseProviderConnection::QueryResult execSqlPrivate( const QString &sql, bool resolveTypes = true, QgsFeedback *feedback = nullptr, std::shared_ptr< class QgsPoolPostgresConn > pgconn = nullptr ) const; 87 void setDefaultCapabilities(); 88 void dropTablePrivate( const QString &schema, const QString &name ) const; 89 void renameTablePrivate( const QString &schema, const QString &name, const QString &newName ) const; 90 91 }; 92 93 94 #endif // QGSPOSTGRESPROVIDERCONNECTION_H 95