Skip to content
Permalink
Browse files
Fix to make deletion of postgres columns working again
git-svn-id: http://svn.osgeo.org/qgis/trunk@7063 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jul 6, 2007
1 parent 108ddab commit 0174afd26a5b32a9fffe5c4cb098596d05a4f092
@@ -356,9 +356,7 @@ void QgsAttributeTable::deleteAttribute(const QString& name)
}
else
{
QgsDebugMsg("QgsAttributeTable: deleteAttribute " + name);

// TODO: [MD] mDeletedAttributes.insert(name);
mDeletedAttributes.insert(name);
removeAttrColumn(name);
}
mEdited=true;
@@ -130,7 +130,7 @@ class QgsAttributeTable:public Q3Table
and the value the attribute type*/
QgsNewAttributesMap mAddedAttributes;
/**Set containing the attribute names of deleted attributes*/
QgsFeatureIds mDeletedAttributes;
QgsDeletedAttributesSet mDeletedAttributes;
/**Nested map containing the changed attribute values. The int is the feature id,
the first QString the attribute name and the second QString the new value*/
QgsChangedAttributesMap mChangedValues;
@@ -82,7 +82,7 @@ bool QgsVectorDataProvider::addAttributes(const QgsNewAttributesMap & attributes
return false;
}

bool QgsVectorDataProvider::deleteAttributes(const QgsAttributeIds & attributes)
bool QgsVectorDataProvider::deleteAttributes(const QgsAttributeIds& attributes)
{
return false;
}
@@ -220,15 +220,13 @@ QString QgsVectorDataProvider::capabilitiesString() const
int QgsVectorDataProvider::indexFromFieldName(const QString& fieldName) const
{
const QgsFieldMap& theFields = fields();
int counter = 0;

for (QgsFieldMap::const_iterator it = theFields.begin(); it != theFields.end(); ++it)
{
if(it->name() == fieldName)
{
return counter;
return it.key();
}
++counter;
}
return -1;
}
@@ -190,10 +190,10 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider

/**
* Deletes existing attributes
* @param attributes a set containing indexes of attributes
* @param attributes a set containing names of attributes
* @return true in case of success and false in case of failure
*/
virtual bool deleteAttributes(const QgsAttributeIds & attributes);
virtual bool deleteAttributes(const QgsAttributeIds& attributes);

/**
* Changes attribute values of existing features.
@@ -2878,27 +2878,36 @@ void QgsVectorLayer::setCoordinateSystem()

}

bool QgsVectorLayer::commitAttributeChanges(const QgsAttributeIds& deleted,
bool QgsVectorLayer::commitAttributeChanges(const QgsDeletedAttributesSet& deleted,
const QgsNewAttributesMap& added,
const QgsChangedAttributesMap& changed)
{
bool returnvalue=true;

if(mDataProvider)
{

QgsAttributeIds attIds;
QgsDeletedAttributesSet::const_iterator att_it = deleted.constBegin();

for(; att_it != deleted.constEnd(); ++att_it)
{
attIds.insert(mDataProvider->indexFromFieldName(*att_it));
}

if(mDataProvider->capabilities()&QgsVectorDataProvider::DeleteAttributes)
{
//delete attributes in all not commited features
for (QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter)
{
for (QgsAttributeIds::const_iterator it = deleted.begin(); it != deleted.end(); ++it)
for (QgsAttributeIds::const_iterator it = attIds.begin(); it != attIds.end(); ++it)
{
(*iter).deleteAttribute(*it);
}
}

//and then in the provider
if(!mDataProvider->deleteAttributes(deleted))
if(!mDataProvider->deleteAttributes(attIds))
{
returnvalue=false;
}
@@ -56,6 +56,8 @@ typedef QSet<int> QgsAttributeIds;
// key = attribute name, value = attribute type
typedef QMap<QString, QString> QgsNewAttributesMap;

typedef QSet<QString> QgsDeletedAttributesSet;

typedef QMap<int, QgsField> QgsFieldMap;


@@ -314,7 +316,7 @@ existing rings, 5 no feature found where ring can be inserted*/
of attribute values to change
*/
bool commitAttributeChanges(const QgsAttributeIds& deleted,
bool commitAttributeChanges(const QgsDeletedAttributesSet& deleted,
const QgsNewAttributesMap& added,
const QgsChangedAttributesMap& changed);

@@ -1768,17 +1768,21 @@ bool QgsPostgresProvider::addAttributes(const QgsNewAttributesMap & name)
return returnvalue;
}

bool QgsPostgresProvider::deleteAttributes(const QgsAttributeIds& name)
bool QgsPostgresProvider::deleteAttributes(const QgsAttributeIds& ids)
{
bool returnvalue=true;
PQexec(connection,"BEGIN");
for(QgsAttributeIds::const_iterator iter=name.begin();iter!=name.end();++iter)

for(QgsAttributeIds::const_iterator iter=ids.begin();iter != ids.end();++iter)
{
QString column = attributeFields[*iter].name();
QgsFieldMap::const_iterator field_it = attributeFields.find(*iter);
if(field_it == attributeFields.constEnd())
{
continue;
}
QString column = field_it->name();
QString sql="ALTER TABLE "+mSchemaTableName+" DROP COLUMN "+column;

QgsDebugMsg(sql);

//send sql statement and do error handling
PGresult* result=PQexec(connection, (const char *)(sql.utf8()));
if(result==0)

0 comments on commit 0174afd

Please sign in to comment.