Skip to content

Commit

Permalink
[FEATURE] Add support to edit views that have triggers. Fixes #4787
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Jan 15, 2012
1 parent 10dbb6a commit 4413a7d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -443,7 +443,7 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri )
return;
}
enabledCapabilities = QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
if ( mTableBased && !mReadOnly )
if (( mTableBased | mViewBased ) && !mReadOnly )
{
// enabling editing only for Tables [excluding Views and VirtualShapes]
enabledCapabilities |= QgsVectorDataProvider::DeleteFeatures;
Expand Down Expand Up @@ -650,6 +650,23 @@ void QgsSpatiaLiteProvider::loadFields()
}
}

bool QgsSpatiaLiteProvider::hasTriggers()
{
int ret;
char **results;
int rows;
int columns;
char *errMsg = NULL;
QString sql;

sql = QString( "SELECT * FROM sqlite_master WHERE type='trigger' AND tbl_name=%1" )
.arg( quotedIdentifier( mTableName ) );

ret = sqlite3_get_table( sqliteHandle, sql.toUtf8().constData(), &results, &rows, &columns, &errMsg );
sqlite3_free_table( results );
return ( ret == SQLITE_OK && rows > 0 );
}


QString QgsSpatiaLiteProvider::storageType() const
{
Expand Down Expand Up @@ -4217,7 +4234,7 @@ bool QgsSpatiaLiteProvider::checkLayerType()
else if ( type == "view" )
{
mViewBased = true;
mReadOnly = true;
mReadOnly = !hasTriggers();
}
count++;
}
Expand Down Expand Up @@ -4321,7 +4338,7 @@ bool QgsSpatiaLiteProvider::checkLayerType()
if ( ret == SQLITE_OK && rows == 1 )
{
mViewBased = true;
mReadOnly = true;
mReadOnly = !hasTriggers();
count++;
}
if ( errMsg )
Expand Down
3 changes: 3 additions & 0 deletions src/providers/spatialite/qgsspatialiteprovider.h
Expand Up @@ -276,6 +276,9 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider
/** loads fields from input file to member attributeFields */
void loadFields();

/** Check if a table/view has any triggers. Triggers can be used on views to make them editable.*/
bool hasTriggers();

/** convert a QgsField to work with SL */
static bool convertField( QgsField &field );

Expand Down

0 comments on commit 4413a7d

Please sign in to comment.