28 QStringList leftJoins;
42 QString uid = QStringLiteral(
"uid" );
44 uid += QLatin1String(
"_" );
47 columns <<
"t.rowid AS " + uid;
52 for (
const auto &f : providerFields )
54 columns <<
"t." + f.name();
60 QString joinName = QStringLiteral(
"j%1" ).arg( ++joinIdx );
64 QString prefix = join.
prefix().isEmpty() ? joinedLayer->
name() +
"_" : join.
prefix();
66 leftJoins << QStringLiteral(
"LEFT JOIN %1 AS %2 ON t.\"%5\"=%2.\"%3\"" ).arg( joinedLayer->
id(), joinName, join.
joinFieldName(), join.
targetFieldName() );
71 columns << joinName +
"." + f +
" AS " + prefix + f;
77 for (
const QgsField &f : joinFields )
81 columns << joinName +
"." + f.name() +
" AS " + prefix + f.name();
86 QString query =
"SELECT " + columns.join( QStringLiteral(
", " ) ) +
" FROM " + layer->
id() +
" AS t " + leftJoins.join( QStringLiteral(
" " ) );
int lookupField(const QString &fieldName) const
Look up field's index from the field name.
QString targetFieldName() const
Returns name of the field of our layer that will be used for join.
virtual QgsAttributeList pkAttributeIndexes() const
Returns list of indexes of fields that make up the primary key.
Container of fields for a vector layer.
const QList< QgsVectorLayerJoinInfo > vectorJoins() const
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QgsVectorLayer * joinLayer() const
Returns joined layer (may be null if the reference was set by layer ID and not resolved yet) ...
QgsFields fields() const override
Returns the list of fields of this layer.
void setQuery(const QString &query)
Sets the SQL query.
QgsFields fields() const override=0
Returns the fields associated with this data provider.
Defines left outer join from our vector layer to some other vector layer.
static QgsVirtualLayerDefinition fromJoinedLayer(QgsVectorLayer *joinedLayer)
Gets a virtual layer definition from a vector layer where vector joins are replaced by SQL LEFT JOINs...
static QStringList joinFieldNamesSubset(const QgsVectorLayerJoinInfo &info, bool blacklisted=true)
Returns the list of field names to use for joining considering blacklisted fields and subset...
Encapsulate a field in an attribute table or data source.
void setUid(const QString &uid)
Sets the name of the field with unique identifiers.
QgsVectorDataProvider * dataProvider() override
Returns the layer's data provider.
QList< int > QgsAttributeList
Represents a vector layer which manages a vector based data sets.
QString joinFieldName() const
Returns name of the field of joined layer that will be used for join.
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)
Class to manipulate the definition of a virtual layer.
QString prefix() const
Returns prefix of fields from the joined layer. If null, joined layer's name will be used...