Updating Values

FDO API

 
Updating Values
 
 
 

After inserting (see Inserting Values), you can update the values. The update operation involves identifying a feature class (“table”), a feature class object (“row”), and an object property (“column in a row”) to be changed, and supplying a new value for the object property to replace the old.

First, create an FdoIUpdate command object and use the command object’s SetFeatureClassName() method to identify the feature class. Then, create a filter to identity the feature class object whose properties we want to update, and use the command object’s SetFilter() method to attach the command to it. Filters are discussed in Filter and Expression Languages.

One of the data properties in the example SampleFeatureClass class definition is an identity property, whose name is “SampleIdentityDataProperty” and whose type is fdo:Int32. This means that its value uniquely identifies the feature class object, that is, the “row”. Use the name of the identity property in the filter. In the Insert operation, the value of the identity property was set to be ‘101’. The value of the filter that is needed is “( SampleIdentityDataProperty = 101 )”.

Finally, create a property value, which contains the new value, attach it to the command object, and then execute the command.

Example: Updating Property Values

The following is an example of updating property values:

FdoPtr<FdoIUpdate> sampleUpdate;
sampleUpdate =
    (FdoIUpdate *)connection->CreateCommand(FdoCommandType_Update);
FdoInt32 numUpdated = 0;
// point the Update command at the target feature class
// use a fully qualified class name
// whose format is <schemaName>:<className>
sampleUpdate-> SetFeatureClassName(L"SampleFeatureSchema:SampleFeatureClass");
// set the filter to identify which set of properties to update
sampleUpdate->SetFilter(L"( SampleIdentityDataProperty = 101 )");
// get the pointer to the value collection used to add properties
// to the Update command
// we are reusing the samplePropertyValues object that we used
// for the insert operation
samplePropertyValues = sampleUpdate->GetPropertyValues();
// create an FdoDataValue for the name property value
FdoPtr<FdoDataValue> sampleNameDataValue;
sampleNameDataValue = FdoDataValue::Create(L"Green Lake");
// set the name and value of the property value
sampleNamePropertyValue->SetName(L"SampleNameDataProperty");
sampleNamePropertyValue->SetValue(sampleNameDataValue);
// add the name property value to the property value collection
// owned by the Update command
samplePropertyValues->Add(sampleNamePropertyValue);
// execute the command
numUpdated = sampleUpdate->Execute();