Skip to content
Permalink
Browse files

[FEATURE] Add support to edit views that have triggers. Fixes #4787

  • Loading branch information
NathanW2 committed Jan 15, 2012
1 parent 10dbb6a commit 4413a7db324a8a56114447b2e2f68fca089f055b
@@ -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;
@@ -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
{
@@ -4217,7 +4234,7 @@ bool QgsSpatiaLiteProvider::checkLayerType()
else if ( type == "view" )
{
mViewBased = true;
mReadOnly = true;
mReadOnly = !hasTriggers();
}
count++;
}
@@ -4321,7 +4338,7 @@ bool QgsSpatiaLiteProvider::checkLayerType()
if ( ret == SQLITE_OK && rows == 1 )
{
mViewBased = true;
mReadOnly = true;
mReadOnly = !hasTriggers();
count++;
}
if ( errMsg )
@@ -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 );

0 comments on commit 4413a7d

Please sign in to comment.
You can’t perform that action at this time.