Wednesday, April 17, 2013

Amazon SimpleDB putAttributes example c c++ objc

putAttributes:
The PutAttributes operation creates or replaces attributes in an item. The client may specify new attributes using a combination of the Attribute.X.Name and Attribute.X.Value parameters. The client specifies the first attribute by the parameters Attribute.0.Name and Attribute.0.Value , the second attribute by the parameters Attribute.1.Name and Attribute.1.Value , and so on. [putAttributes]
Attributes are uniquely identified in an item by their name/value combination. For example, a single item can have the attributes { "first_name", "first_value" } and { "first_name", second_value" } . However, it cannot have two attribute instances where both the Attribute.X.Name and Attribute.X.Value are the same.[putAttributes]
Optionally, the requestor can supply the Replace parameter for each individual attribute. Setting this value to true causes the new attribute value to replace the existing attribute value(s). For example, if an item has the attributes { ‘a’, ‘1’ } ,
- (SimpleDBPutAttributesResponse *)putAttributes:(SimpleDBPutAttributesRequest *)putAttributesRequest

Parameters

putAttributesRequest
Container for the necessary parameters to execute the PutAttributes service method on AmazonSimpleDB.
Example
{
   // Construct attribute (name, value) pairs to put.
   //
    NSMutableArray  *attrList = [[[NSMutableArray alloc] initWithCapacity:attrs.size()] autorelease];
    
    for( int i=0; i<10; i++)
    {
        SimpleDBReplaceableAttribute    *attr = [[[SimpleDBReplaceableAttribute alloc] initWithName: [NSString stringWithFormat:@"attr%d", i] andValue:[NSString stringWithFormat:"@value%d", i] andReplace:YES] autorelease];

        [attrList addObject:attr];
    }

    // Do Put Attributes request to AWS.
    //
    SimpleDBPutAttributesRequest    *putRequest = [[SimpleDBPutAttributesRequest alloc] initWithDomainName:domainName andItemName:itemName andAttributes:attrList];

    [putRequest setRequestEndpoint:AMAZON_SDB_US_EAST_1_ENDPOINT_SECURE];

    SimpleDBPutAttributesResponse   *putResponse = [[AmazonClientManager sdb] putAttributes:putRequest];

    if(putResponse.error != nil)
    {
        NSLog(@"Error: %@", putResponse.error);
    }
}