QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
56 static QMetaEnum metaEnum = QMetaEnum::fromType<QgsAbstractDatabaseProviderConnection::Capability>();
57 const QString capName { metaEnum.valueToKey( capability ) };
74 const QMap<QString, QVariant> *
81 Q_UNUSED( overwrite );
89 checkCapability( Capability::RenameVectorTable );
94 checkCapability( Capability::RenameRasterTable );
99 checkCapability( Capability::DropVectorTable );
104 checkCapability( Capability::TableExists );
105 const QList<QgsAbstractDatabaseProviderConnection::TableProperty> constTables {
tables( schema ) };
106 for (
const auto &t : constTables )
108 if ( t.tableName() == name )
118 checkCapability( Capability::DropRasterTable );
123 checkCapability( Capability::CreateSchema );
128 checkCapability( Capability::DropSchema );
133 checkCapability( Capability::RenameSchema );
138 checkCapability( Capability::ExecuteSql );
139 return QList<QList<QVariant>>();
144 checkCapability( Capability::Vacuum );
149 checkCapability( Capability::CreateSpatialIndex );
154 checkCapability( Capability::DeleteSpatialIndex );
159 checkCapability( Capability::SpatialIndexExists );
165 checkCapability( Capability::DeleteField );
169 std::unique_ptr<QgsVectorLayer> vl { qgis::make_unique<QgsVectorLayer>(
tableUri( schema, tableName ), QStringLiteral(
"temp_layer" ),
mProviderKey, options ) };
170 if ( ! vl->isValid() )
173 .arg( tableName, schema ) );
175 if ( vl->fields().lookupField( fieldName ) == -1 )
178 .arg( fieldName, tableName, schema ) );
181 if ( ! vl->dataProvider()->deleteAttributes( { vl->fields().lookupField( fieldName ) } ) )
184 .arg( fieldName, tableName, schema ) );
190 checkCapability( Capability::AddField );
194 std::unique_ptr<QgsVectorLayer> vl( qgis::make_unique<QgsVectorLayer>(
tableUri( schema, tableName ), QStringLiteral(
"temp_layer" ),
mProviderKey, options ) );
195 if ( ! vl->isValid() )
198 .arg( tableName, schema ) );
200 if ( vl->fields().lookupField(
field.
name() ) != -1 )
203 .arg(
field.
name(), tableName, schema ) );
206 if ( ! vl->dataProvider()->addAttributes( { field } ) )
209 .arg(
field.
name(), tableName, schema ) );
215 checkCapability( Capability::Tables );
216 return QList<QgsAbstractDatabaseProviderConnection::TableProperty>();
222 checkCapability( Capability::Tables );
223 const QList<QgsAbstractDatabaseProviderConnection::TableProperty> constTables {
tables( schema ) };
224 for (
const auto &t : constTables )
226 if ( t.tableName() == name )
232 .arg( name, schema ) );
237 return tables( schema,
static_cast<QgsAbstractDatabaseProviderConnection::TableFlags
>( flags ) );
243 checkCapability( Capability::Schemas );
244 return QStringList();
261 for (
const auto &t : qgis::as_const( mGeometryColumnTypes ) )
268 mGeometryColumnTypes.push_back( toAdd );
273 return mGeometryColumnTypes;
293 QString n = mTableName;
294 if ( mGeometryColumnCount > 1 ) n +=
'.' + mGeometryColumn;
302 Q_ASSERT( index >= 0 && index < mGeometryColumnTypes.size() );
304 property.mGeometryColumnTypes << mGeometryColumnTypes[ index ];
305 property.mSchema = mSchema;
306 property.mTableName = mTableName;
307 property.mGeometryColumn = mGeometryColumn;
308 property.mPkColumns = mPkColumns;
309 property.mGeometryColumnCount = mGeometryColumnCount;
310 property.mFlags = mFlags;
311 property.mComment = mComment;
312 property.mInfo = mInfo;
318 mFlags.setFlag( flag );
333 return mSchema == other.mSchema &&
334 mTableName == other.mTableName &&
335 mGeometryColumn == other.mGeometryColumn &&
336 mGeometryColumnCount == other.mGeometryColumnCount &&
337 mPkColumns == other.mPkColumns &&
338 mFlags == other.mFlags &&
339 mComment == other.mComment &&
340 mInfo == other.mInfo;
346 mGeometryColumnTypes = columnTypes;
352 return mGeometryColumnCount;
357 mGeometryColumnCount = geometryColumnCount;
392 QList<QgsCoordinateReferenceSystem> crss;
393 for (
const auto &t : qgis::as_const( mGeometryColumnTypes ) )
395 crss.push_back( t.crs );
407 mPkColumns = pkColumns;
412 return mGeometryColumn;
417 mGeometryColumn = geometryColumn;
void setGeometryColumnTypes(const QList< QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType > &geometryColumnTypes)
Sets the geometry column types to geometryColumnTypes.
virtual void createSpatialIndex(const QString &schema, const QString &name, const QgsAbstractDatabaseProviderConnection::SpatialIndexOptions &options=QgsAbstractDatabaseProviderConnection::SpatialIndexOptions()) const SIP_THROW(QgsProviderConnectionException)
Creates a spatial index for the database table with given schema and name (schema is ignored if not s...
void setSchema(const QString &schema)
Sets the schema.
QList< QgsAbstractDatabaseProviderConnection::TableProperty > tablesInt(const QString &schema=QString(), const int flags=0) const SIP_THROW(QgsProviderConnectionException)
Returns information on the tables in the given schema.
virtual void renameRasterTable(const QString &schema, const QString &name, const QString &newName) const SIP_THROW(QgsProviderConnectionException)
Renames a raster table with given schema (schema is ignored if not supported by the backend) and name...
virtual void dropSchema(const QString &name, bool force=false) const SIP_THROW(QgsProviderConnectionException)
Drops an entire schema with the specified name.
virtual void createSchema(const QString &name) const SIP_THROW(QgsProviderConnectionException)
Creates a new schema with the specified name.
const QgsCoordinateReferenceSystem & crs
void setPrimaryKeyColumns(const QStringList &primaryKeyColumns)
Sets the primary key column names to primaryKeyColumns.
Container of fields for a vector layer.
virtual bool spatialIndexExists(const QString &schema, const QString &name, const QString &geometryColumn) const SIP_THROW(QgsProviderConnectionException)
Determines whether a spatial index exists for the database table with given schema,...
QString geometryColumn() const
Returns the geometry column name.
virtual void addField(const QgsField &field, const QString &schema, const QString &tableName) const SIP_THROW(QgsProviderConnectionException)
Adds a field Raises a QgsProviderConnectionException if any errors are encountered.
Type
The WKB type describes the number of dimensions a geometry has.
QStringList primaryKeyColumns() const
Returns the list of primary key column names.
virtual QList< QgsAbstractDatabaseProviderConnection::TableProperty > tables(const QString &schema=QString(), const QgsAbstractDatabaseProviderConnection::TableFlags &flags=QgsAbstractDatabaseProviderConnection::TableFlags()) const
Returns information on the tables in the given schema.
void addGeometryColumnType(const QgsWkbTypes::Type &type, const QgsCoordinateReferenceSystem &crs)
Appends the geometry column type with the given srid to the geometry column types list.
virtual void deleteField(const QString &fieldName, const QString &schema, const QString &tableName, bool force=false) const SIP_THROW(QgsProviderConnectionException)
Deletes the field with the specified name.
static int coordDimensions(Type type) SIP_HOLDGIL
Returns the coordinate dimension of the geometry type as an integer.
QString defaultName() const
Returns the default name for the table entry.
The TableProperty class represents a database table or view.
GeometryColumnCapabilities mGeometryColumnCapabilities
virtual QgsFields fields(const QString &schema, const QString &table) const SIP_THROW(QgsProviderConnectionException)
Returns the fields of a table and schema.
virtual GeometryColumnCapabilities geometryColumnCapabilities()
Returns connection geomerty column capabilities (Z, M, SinglePart, Curves)
void setFlag(const TableFlag &flag)
Sets a flag.
virtual bool tableExists(const QString &schema, const QString &name) const SIP_THROW(QgsProviderConnectionException)
Checks whether a table name exists in the given schema.
QVariantMap info() const
Returns additional information about the table.
virtual void renameSchema(const QString &name, const QString &newName) const SIP_THROW(QgsProviderConnectionException)
Renames a schema with the specified name.
void setGeometryColumnCount(int geometryColumnCount)
Sets the geometryColumnCount.
QgsAbstractDatabaseProviderConnection(const QString &name)
Creates a new connection with name by reading its configuration from the settings.
Capabilities mCapabilities
Base class for feedback objects to be used for cancellation of something running in a worker thread.
int maxCoordinateDimensions() const
Returns the maximum coordinate dimensions of the geometries of a vector table.
QList< QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType > geometryColumnTypes() const
Returns the list of geometry column types and CRSs.
QList< QgsCoordinateReferenceSystem > crsList() const
Returns the list of CRSs supported by the geometry column.
virtual void dropVectorTable(const QString &schema, const QString &name) const SIP_THROW(QgsProviderConnectionException)
Drops 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 QList< QList< QVariant > > executeSql(const QString &sql, QgsFeedback *feedback=nullptr) const SIP_THROW(QgsProviderConnectionException)
Executes raw sql and returns the (possibly empty) list of results in a multi-dimensional array,...
Custom exception class for provider connection related exceptions.
This class represents a coordinate reference system (CRS).
virtual void vacuum(const QString &schema, const QString &name) const SIP_THROW(QgsProviderConnectionException)
Vacuum the database table with given schema and name (schema is ignored if not supported by the backe...
virtual void deleteSpatialIndex(const QString &schema, const QString &name, const QString &geometryColumn) const SIP_THROW(QgsProviderConnectionException)
Deletes the existing spatial index for the database table with given schema, name and geometryColumn ...
Setting options for loading vector layers.
Contains extra options relating to spatial index creation.
void setFlags(const TableFlags &flags)
Sets the table flags.
QString comment() const
Returns the table comment.
QString tableName() const
Returns the table name.
Capability
The Capability enum represents the operations supported by the connection.
Represents a vector layer which manages a vector based data sets.
TableProperty at(int index) const
Returns the table property corresponding to the geometry type at the given index.
void setTableName(const QString &name)
Sets the table name to name.
void setInfo(const QVariantMap &info)
Sets additional information about the table to info.
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)
Creates an empty table with name in the given schema (schema is ignored if not supported by the backe...
int geometryColumnCount() const
Returns the number of geometry columns in the original table this entry refers to.
TableFlag
Flags for table properties.
The GeometryColumnType struct represents the combination of geometry type and CRS for the table geome...
virtual QgsAbstractDatabaseProviderConnection::TableProperty table(const QString &schema, const QString &table) const SIP_THROW(QgsProviderConnectionException)
Returns information on a table in the given schema.
The QgsAbstractProviderConnection provides an interface for data provider connections.
virtual void renameVectorTable(const QString &schema, const QString &name, const QString &newName) const SIP_THROW(QgsProviderConnectionException)
Renames a vector or aspatial table with given schema (schema is ignored if not supported by the backe...
TableFlags flags() const
Returns the table flags.
void setComment(const QString &comment)
Sets the table comment.
void setGeometryColumn(const QString &geometryColumn)
Sets the geometry column name to geometryColumn.
virtual void dropRasterTable(const QString &schema, const QString &name) const SIP_THROW(QgsProviderConnectionException)
Drops a raster table with given schema (schema is ignored if not supported by the backend) and name.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
QString schema() const
Returns the schema or an empty string for backends that do not support a schema.
virtual QStringList schemas() const SIP_THROW(QgsProviderConnectionException)
Returns information about the existing schemas.
bool operator==(const QgsAbstractDatabaseProviderConnection::TableProperty &other) const
virtual QString tableUri(const QString &schema, const QString &name) const SIP_THROW(QgsProviderConnectionException)
Returns the URI string for the given table and schema.
Capabilities capabilities() const
Returns connection capabilities.
Encapsulate a field in an attribute table or data source.