16#ifndef QGSABSTRACTDATABASEPROVIDERCONNECTION_H
17#define QGSABSTRACTDATABASEPROVIDERCONNECTION_H
65 MaterializedView = 1 << 5,
67 IncludeSystemTables = 1 << 7,
141 SIP_PYOBJECT __next__();
143 QList<QVariant> result;
144 Py_BEGIN_ALLOW_THREADS
145 result = sipCpp->nextRow( );
147 if ( ! result.isEmpty() )
149 const sipTypeDef *qvariantlist_type = sipFindType(
"QList<QVariant>" );
150 sipRes = sipConvertFromNewType(
new QList<QVariant>( result ), qvariantlist_type, Py_None );
154 PyErr_SetString( PyExc_StopIteration,
"" );
166 struct CORE_EXPORT QueryResultIterator
SIP_SKIP
169 QVariantList nextRow();
172 bool hasNextRow()
const;
175 long long fetchedRowCount();
178 long long rowCount();
180 virtual ~QueryResultIterator() =
default;
184 virtual QVariantList nextRowPrivate() = 0;
185 virtual bool hasNextRowPrivate()
const = 0;
186 virtual long long rowCountPrivate()
const = 0;
188 mutable qlonglong mFetchedRowCount = 0;
189 mutable QMutex mMutex;
198 void appendColumn(
const QString &columnName )
SIP_SKIP;
205 QueryResult( std::shared_ptr<QueryResultIterator> iterator )
SIP_SKIP;
216 double queryExecutionTime( )
const;
221 void setQueryExecutionTime(
double queryExecutionTime );
227 mutable std::shared_ptr<QueryResultIterator> mResultIterator;
228 QStringList mColumns;
230 double mQueryExecutionTime = 0;
285 SIP_PYOBJECT __repr__();
287 QString str = QStringLiteral(
"<QgsAbstractDatabaseProviderConnection.TableProperty: '%1'>" ).arg( sipCpp->tableName() );
288 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
299 SIP_PYOBJECT __repr__();
301 QString str = QStringLiteral(
"<QgsAbstractDatabaseProviderConnection.TableProperty.GeometryColumnType: '%1, %2'>" ).arg(
QgsWkbTypes::displayString( sipCpp->wkbType ), sipCpp->crs.authid() );
302 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
311 return this->crs == other.
crs && this->wkbType == other.
wkbType;
322 QString tableName()
const;
329 void setTableName(
const QString &name );
341 QList<QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType> geometryColumnTypes()
const;
346 void setGeometryColumnTypes(
const QList<QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType> &geometryColumnTypes );
355 QString defaultName()
const;
366 QString schema()
const;
371 void setSchema(
const QString &schema );
376 QString geometryColumn()
const;
381 void setGeometryColumn(
const QString &geometryColumn );
386 QStringList primaryKeyColumns()
const;
391 void setPrimaryKeyColumns(
const QStringList &primaryKeyColumns );
396 QList<QgsCoordinateReferenceSystem> crsList()
const;
411 QString comment()
const;
416 void setComment(
const QString &comment );
424 QVariantMap info()
const;
432 void setInfo(
const QVariantMap &info );
439 int geometryColumnCount()
const;
444 void setGeometryColumnCount(
int geometryColumnCount );
457 int maxCoordinateDimensions()
const;
464 QList<GeometryColumnType> mGeometryColumnTypes;
470 QString mGeometryColumn;
472 int mGeometryColumnCount = 0;
474 QStringList mPkColumns;
553 Q_ENUM( GeometryColumnCapability )
1115 PyObject *l = PyList_New( cppRes.size() );
1121 for (
int i = 0; i < cppRes.size(); ++i )
1123 PyObject *eobj = sipConvertFromEnum(
static_cast<int>( cppRes.at( i ) ),
1124 sipType_Qgis_RelationshipCardinality );
1131 PyList_SetItem( l, i, eobj );
1152 virtual QList< Qgis::RelationshipStrength > supportedRelationshipStrengths()
const;
1154 SIP_PYOBJECT supportedRelationshipStrengths() const
SIP_TYPEHINT( List[Qgis.RelationshipStrength] );
1158 const QList< Qgis::RelationshipStrength > cppRes = sipCpp->supportedRelationshipStrengths();
1160 PyObject *l = PyList_New( cppRes.size() );
1166 for (
int i = 0; i < cppRes.size(); ++i )
1168 PyObject *eobj = sipConvertFromEnum(
static_cast<int>( cppRes.at( i ) ),
1169 sipType_Qgis_RelationshipStrength );
1176 PyList_SetItem( l, i, eobj );
1208 virtual QStringList relatedTableTypes()
const;
1222 virtual QList< QgsWeakRelation > relationships(
const QString &schema = QString(),
const QString &tableName = QString() ) const
SIP_THROW( QgsProviderConnectionException );
1230 virtual
void addRelationship( const QgsWeakRelation &relationship ) const
SIP_THROW( QgsProviderConnectionException );
1238 virtual
void updateRelationship( const QgsWeakRelation &relationship ) const
SIP_THROW( QgsProviderConnectionException );
1246 virtual
void deleteRelationship( const QgsWeakRelation &relationship ) const
SIP_THROW( QgsProviderConnectionException );
1255 virtual QgsProviderSqlQueryBuilder *queryBuilder() const
SIP_FACTORY;
1277 virtual QList<QgsLayerMetadataProviderResult> searchLayerMetadata( const QgsMetadataSearchContext &searchContext, const QString &searchString = QString(), const QgsRectangle &geographicExtent = QgsRectangle(), QgsFeedback *feedback =
nullptr ) const
SIP_THROW( QgsProviderConnectionException, QgsNotSupportedException );
1288 void checkCapability( Capability capability ) const;
1295 void checkCapability( Qgis::DatabaseProviderConnectionCapability2 capability ) const;
1298 QString sanitizeSqlForQueryLayer( const QString &sql ) const
SIP_SKIP;
Provides global constants and enumerations for use throughout the application.
QFlags< RelationshipCapability > RelationshipCapabilities
Relationship capabilities.
WkbType
The WKB type describes the number of dimensions a geometry has.
virtual QString defaultGeometryColumnName() const
Returns the default name to use for a geometry column for the connection.
virtual void setFieldComment(const QString &fieldName, const QString &schema, const QString &tableName, const QString &comment) const
Sets the comment for the existing field with the specified name.
virtual Qgis::DatabaseProviderTableImportCapabilities tableImportCapabilities() const =0
Represents capabilities of the database provider connection when importing table data.
virtual void createVectorTable(const QString &schema, const QString &name, const QgsFields &fields, Qgis::WkbType wkbType, const QgsCoordinateReferenceSystem &srs, bool overwrite, const QMap< QString, QVariant > *options) const
Creates an empty table with name in the given schema (schema is ignored if not supported by the backe...
virtual QgsVectorLayer * createSqlVectorLayer(const SqlVectorLayerOptions &options) const
Creates and returns a (possibly invalid) vector layer based on a SQL statement and options.
virtual bool tableExists(const QString &schema, const QString &name) const
Checks whether a table name exists in the given schema.
TableFlag
Flags for table properties.
QList< QgsAbstractDatabaseProviderConnection::TableProperty > tablesInt(const QString &schema=QString(), const int flags=0) const
Returns information on the tables in the given schema.
virtual void renameField(const QString &schema, const QString &tableName, const QString &name, const QString &newName) const
Renames an existing field.
GeometryColumnCapability
The GeometryColumnCapability enum represents the geometry column features supported by the connection...
@ PolyhedralSurfaces
Supports polyhedral surfaces (PolyhedralSurface, TIN) types (as distinct from multi polygon types).
@ SinglePart
Multi and single part types are distinct types. Deprecated since QGIS 3.28 – use the granular SingleP...
@ SinglePolygon
Supports single polygon types (as distinct from multi polygon types).
@ SinglePoint
Supports single point types (as distinct from multi point types).
@ SingleLineString
Supports single linestring types (as distinct from multi line types).
virtual void deleteFieldDomain(const QString &name, const QString &schema) const
Deletes the field domain with the specified name from the provider.
virtual void dropSchema(const QString &name, bool force=false) const
Drops an entire schema with the specified name.
Qgis::SqlLayerDefinitionCapabilities mSqlLayerDefinitionCapabilities
virtual void addField(const QgsField &field, const QString &schema, const QString &tableName) const
Adds a field.
virtual QList< QgsAbstractDatabaseProviderConnection::TableProperty > tables(const QString &schema=QString(), const QgsAbstractDatabaseProviderConnection::TableFlags &flags=QgsAbstractDatabaseProviderConnection::TableFlags(), QgsFeedback *feedback=nullptr) const
Returns information on the tables in the given schema.
Qgis::DatabaseProviderConnectionCapabilities2 mCapabilities2
Capabilities mCapabilities
virtual void vacuum(const QString &schema, const QString &name) const
Vacuum the database table with given schema and name (schema is ignored if not supported by the backe...
QSet< QString > mIllegalFieldNames
virtual QList< Qgis::FieldDomainType > supportedFieldDomainTypes() const
Returns a list of field domain types which are supported by the provider.
virtual void renameVectorTable(const QString &schema, const QString &name, const QString &newName) const
Renames a vector or aspatial table with given schema (schema is ignored if not supported by the backe...
QString providerKey() const
Returns the provider key.
virtual void createSchema(const QString &name) const
Creates a new schema with the specified name.
virtual void deleteSpatialIndex(const QString &schema, const QString &name, const QString &geometryColumn) const
Deletes the existing spatial index for the database table with given schema, name and geometryColumn ...
virtual void dropRasterTable(const QString &schema, const QString &name) const
Drops a raster table with given schema (schema is ignored if not supported by the backend) and name.
Qgis::DatabaseProviderConnectionCapabilities2 capabilities2() const
Returns extended connection capabilities.
virtual QueryResult execSql(const QString &sql, QgsFeedback *feedback=nullptr) const
Executes raw sql and returns the (possibly empty) query results, optionally feedback can be provided.
virtual void setFieldDomainName(const QString &fieldName, const QString &schema, const QString &tableName, const QString &domainName) const
Sets the field domain name for the existing field with the specified name.
virtual void deleteField(const QString &fieldName, const QString &schema, const QString &tableName, bool force=false) const
Deletes the field with the specified name.
virtual QString tableUri(const QString &schema, const QString &name) const
Returns the URI string for the given table and schema.
QFlags< TableFlag > TableFlags
QFlags< GeometryColumnCapability > GeometryColumnCapabilities
Capability
The Capability enum represents the operations supported by the connection.
@ RetrieveFieldDomain
Can retrieve field domain details from provider via fieldDomain().
@ CreateSpatialIndex
The connection can create spatial indices.
@ AddRelationship
Can add new relationships to the database via addRelationship().
@ SqlLayers
Can create vector layers from SQL SELECT queries.
@ RenameSchema
Can RENAME a schema.
@ CreateVectorTable
Can CREATE a vector (or aspatial) table/layer.
@ DropVectorTable
Can DROP a vector (or aspatial) table/layer.
@ DeleteSpatialIndex
The connection can delete spatial indices for tables.
@ RetrieveRelationships
Can retrieve relationships from the database.
@ RenameRasterTable
Can RENAME a raster table/layer.
@ SetFieldDomain
Can set the domain for an existing field via setFieldDomainName().
@ DropSchema
Can DROP a schema.
@ AddFieldDomain
Can add new field domains to the database via addFieldDomain().
@ DeleteRelationship
Can delete existing relationships from the database via deleteRelationship().
@ CreateSchema
Can CREATE a schema.
@ DropRasterTable
Can DROP a raster table/layer.
@ DeleteField
Can delete an existing field/column.
@ AddField
Can add a new field/column.
@ Spatial
The connection supports spatial tables.
@ TableExists
Can check if table exists.
@ RenameVectorTable
Can RENAME a vector (or aspatial) table/layer.
@ RenameField
Can rename existing fields via renameField().
@ MoveTableToSchema
Can move table to another schema via moveTableToAnotherSchema().
@ ExecuteSql
Can execute raw SQL queries (without returning results).
@ UpdateRelationship
Can update existing relationships in the database via updateRelationship().
@ SpatialIndexExists
The connection can determine if a spatial index exists.
@ ListFieldDomains
Can return a list of field domain names via fieldDomainNames().
@ DeleteFieldCascade
Can delete an existing field/column with cascade.
@ Schemas
Can list schemas (if not set, the connection does not support schemas).
virtual void createSpatialIndex(const QString &schema, const QString &name, const QgsAbstractDatabaseProviderConnection::SpatialIndexOptions &options=QgsAbstractDatabaseProviderConnection::SpatialIndexOptions()) const
Creates a spatial index for the database table with given schema and name (schema is ignored if not s...
static bool splitSimpleQuery(const QString &sql, QStringList &columns, QStringList &tables, QString &where)
Splits a simple query in the form "SELECT column(s) FROM table(s) [WHERE ...]" into its components.
GeometryColumnCapabilities mGeometryColumnCapabilities
virtual GeometryColumnCapabilities geometryColumnCapabilities()
Returns connection geometry column capabilities (Z, M, SinglePart, Curves).
virtual Qgis::SqlLayerDefinitionCapabilities sqlLayerDefinitionCapabilities()
Returns SQL layer definition capabilities (Filters, GeometryColumn, PrimaryKeys).
virtual void renameRasterTable(const QString &schema, const QString &name, const QString &newName) const
Renames a raster table with given schema (schema is ignored if not supported by the backend) and name...
virtual void dropVectorTable(const QString &schema, const QString &name) const
Drops a vector (or aspatial) table with given schema (schema is ignored if not supported by the backe...
virtual QStringList fieldDomainNames() const
Returns a list of field domain names present on the provider.
virtual void setFieldAlias(const QString &fieldName, const QString &schema, const QString &tableName, const QString &alias) const
Sets the alias for the existing field with the specified name.
virtual void renameSchema(const QString &name, const QString &newName) const
Renames a schema with the specified name.
virtual void addFieldDomain(const QgsFieldDomain &domain, const QString &schema) const
Adds a new field domain to the database.
virtual QList< QList< QVariant > > executeSql(const QString &sql, QgsFeedback *feedback=nullptr) const
Executes raw sql and returns the (possibly empty) list of results in a multi-dimensional array,...
virtual bool spatialIndexExists(const QString &schema, const QString &name, const QString &geometryColumn) const
Determines whether a spatial index exists for the database table with given schema,...
virtual QgsAbstractDatabaseProviderConnection::TableProperty table(const QString &schema, const QString &table, QgsFeedback *feedback=nullptr) const
Returns information on a table in the given schema.
virtual QMultiMap< Qgis::SqlKeywordCategory, QStringList > sqlDictionary()
Returns a dictionary of SQL keywords supported by the provider.
virtual SqlVectorLayerOptions sqlOptions(const QString &layerSource)
Returns the SQL layer options from a layerSource.
QFlags< Capability > Capabilities
virtual QSet< QString > illegalFieldNames() const
Returns a list of field names which are considered illegal by the connection and should not be used w...
virtual QStringList schemas() const
Returns information about the existing schemas.
virtual QList< Qgis::RelationshipCardinality > supportedRelationshipCardinalities() const
Returns a list of relationship cardinalities which are supported by the provider.
virtual QString createVectorLayerExporterDestinationUri(const QgsAbstractDatabaseProviderConnection::VectorLayerExporterOptions &options, QVariantMap &providerOptions) const
Creates a URI for use with QgsVectorLayerExporter corresponding to given destination table options fo...
virtual void moveTableToSchema(const QString &sourceSchema, const QString &tableName, const QString &targetSchema) const
Move table to a different schema.
virtual void updateFieldDomain(QgsFieldDomain *domain, const QString &schema) const
Update an existing field domain in the database, the domain is identified by name.
virtual QgsFieldDomain * fieldDomain(const QString &name) const
Returns the field domain with the specified name from the provider.
QgsAbstractDatabaseProviderConnection(const QString &name)
Creates a new connection with name by reading its configuration from the settings.
virtual void setTableComment(const QString &schema, const QString &tableName, const QString &comment) const
Sets the comment for the existing table with the specified name.
virtual QList< QgsVectorDataProvider::NativeType > nativeTypes() const =0
Returns a list of native types supported by the connection.
virtual QString defaultPrimaryKeyColumnName() const
Returns the default name to use for a primary key column for the connection.
virtual bool validateSqlVectorLayer(const SqlVectorLayerOptions &options, QString &message) const
Validates the SQL query options to determine if it is possible to create a vector layer based on a SQ...
Capabilities capabilities() const
Returns connection capabilities.
virtual QgsFields fields(const QString &schema, const QString &table, QgsFeedback *feedback=nullptr) const
Returns the fields of a table and schema.
QVariantMap configuration() const
Returns the connection configuration parameters.
QgsAbstractProviderConnection(const QString &name)
Creates a new connection with name by reading its configuration from the settings.
QString uri() const
Returns the connection data source URI string representation.
Represents a coordinate reference system (CRS).
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Base class for field domains.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
Custom exception class for provider connection related exceptions.
Provides an interface for provider-specific creation of SQL queries.
Base class for vector data providers.
Represents a vector layer which manages a vector based dataset.
Represent a QgsRelation with possibly unresolved layers or unmatched fields.
static Q_INVOKABLE QString displayString(Qgis::WkbType type)
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
#define SIP_TYPEHINT(type)
#define SIP_ENUM_BASETYPE(type)
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
#define SIP_THROW(name,...)
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
The QueryResult class represents the result of a query executed by execSql().
QList< QList< QVariant > > rows(QgsFeedback *feedback=nullptr)
Returns the result rows by calling the iterator internally and fetching all the rows,...
long long fetchedRowCount() const
Returns the number of fetched rows.
bool hasNextRow() const
Returns true if there are more rows to fetch.
QList< QVariant > nextRow() const
Returns the next result row or an empty row if there are no rows left.
long long rowCount() const
Returns the number of rows returned by a SELECT query or Qgis::FeatureCountState::UnknownCount if unk...
QStringList columns() const
Returns the column names.
The SpatialIndexOptions contains extra options relating to spatial index creation.
QString geometryColumnName
Specifies the name of the geometry column to create the index for.
The SqlVectorLayerOptions stores all information required to create a SQL (query) layer.
QString sql
The SQL expression that defines the SQL (query) layer.
QStringList primaryKeyColumns
List of primary key column names.
QString filter
Additional subset string (provider-side filter), not all data providers support this feature: check s...
QString layerName
Optional name for the new layer.
bool disableSelectAtId
If SelectAtId is disabled (default is false), not all data providers support this feature: check supp...
QString geometryColumn
Name of the geometry column.
The GeometryColumnType struct represents the combination of geometry type and CRS for the table geome...
bool operator==(const GeometryColumnType &other) const
QgsCoordinateReferenceSystem crs
The TableProperty class represents a database table or view.
Stores all information required to create a QgsVectorLayerExporter for the backend.
QStringList primaryKeyColumns
List of primary key column names. Note that some providers may ignore this if not supported.
QString schema
Optional schema for the new layer. May not be supported by all providers.
QString geometryColumn
Preferred name for the geometry column, if required. Note that some providers may ignore this if a sp...
QString layerName
Name for the new layer.
Qgis::WkbType wkbType
WKB type for destination layer geometry.