mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
[spatialite] use view's pkey if defined in meta table (fixes #14232)
This commit is contained in:
parent
05471f55d3
commit
f028c0bb58
@ -319,7 +319,7 @@ bool QgsSpatiaLiteFeatureIterator::prepareStatement( const QString& whereClause,
|
||||
|
||||
QString QgsSpatiaLiteFeatureIterator::quotedPrimaryKey()
|
||||
{
|
||||
return !mSource->isQuery ? "ROWID" : QgsSpatiaLiteProvider::quotedIdentifier( mSource->mPrimaryKey );
|
||||
return !( mSource->isQuery || mSource->mViewBased ) ? "ROWID" : QgsSpatiaLiteProvider::quotedIdentifier( mSource->mPrimaryKey );
|
||||
}
|
||||
|
||||
QString QgsSpatiaLiteFeatureIterator::whereClauseFid()
|
||||
@ -562,6 +562,7 @@ QgsSpatiaLiteFeatureSource::QgsSpatiaLiteFeatureSource( const QgsSpatiaLiteProvi
|
||||
, mFields( p->attributeFields )
|
||||
, mQuery( p->mQuery )
|
||||
, isQuery( p->isQuery )
|
||||
, mViewBased( p->mViewBased )
|
||||
, mVShapeBased( p->mVShapeBased )
|
||||
, mIndexTable( p->mIndexTable )
|
||||
, mIndexGeometry( p->mIndexGeometry )
|
||||
|
@ -40,6 +40,7 @@ class QgsSpatiaLiteFeatureSource : public QgsAbstractFeatureSource
|
||||
QgsFields mFields;
|
||||
QString mQuery;
|
||||
bool isQuery;
|
||||
bool mViewBased;
|
||||
bool mVShapeBased;
|
||||
QString mIndexTable;
|
||||
QString mIndexGeometry;
|
||||
|
@ -793,6 +793,31 @@ void QgsSpatiaLiteProvider::loadFields()
|
||||
}
|
||||
}
|
||||
sqlite3_free_table( results );
|
||||
|
||||
|
||||
// for views try to get the primary key from the meta table
|
||||
if ( mViewBased && mPrimaryKey.isEmpty() )
|
||||
{
|
||||
QString sql = QString( "SELECT view_rowid"
|
||||
" FROM views_geometry_columns"
|
||||
" WHERE upper(view_name) = upper(%1) and upper(view_geometry) = upper(%2)" ).arg( quotedValue( mTableName ),
|
||||
quotedValue( mGeometryColumn ) );
|
||||
|
||||
ret = sqlite3_get_table( sqliteHandle, sql.toUtf8().constData(), &results, &rows, &columns, &errMsg );
|
||||
if ( ret == SQLITE_OK )
|
||||
{
|
||||
if ( rows > 0 )
|
||||
{
|
||||
mPrimaryKey = results[1 * columns];
|
||||
int idx = attributeFields.fieldNameIndex( mPrimaryKey );
|
||||
if ( idx != -1 )
|
||||
mPrimaryKeyAttrs << idx;
|
||||
}
|
||||
sqlite3_free_table( results );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user