pawsSDB::putAttributes($itemName, $attributes, $replace)

Description

The putAttributes operation creates or replaces attributes in an item in the currently set domain (seesetDomain()).

Attributes are in an associative array with name/value pairs: $attr = array('name1' = 'val1', 'name2' => 'val2', 'name3' => array('vala', 'valb'));

Note that any attribute can have more than one value. A design decision was made to have the pawsSDB library use PHP associative arrays to hold attributes. The index to the array is the name of the attribute, while the value of the array element is the value or values of the attribute. If there only a single value (which is likely to be the most common case), then the value is stored. If there are multiple values per attribute name, then the values are stored as a simple array: you can use the is_array() PHP function to test to see if the value is a single value or an array of multiple values. This design seems to be a very natural way to access AWS database attributes for PHP programs. You don't need to worry about all the Attribute.X.Name and Attribute.X.Value stuff referred to in the AWS documentation.

putAttributes does not need to be called with all attributes of an item, just the ones you need to add or update.

If an attribute with the same name already exists for the item, then the attribute will be modified to have multiple values. Thus, you can set multiple values for a given attribute either by calling putAttributes with an original attribute with multiple values, or call putAttributes multiple times with the same attribute name but different values.

If putAttributes is called with the $replace parameter not specified or with it set to false, then the attributes are added to the item. The functionreplaceAttributeshas been provided as a convenience for a replace operation.

[Note] Notes

putAttributes does not specifically deal with issues of the format or length of the values stored. If you need to have integer values normalized for query operations, than that is up to you. The utility functions needed for this sort of conversion are supplied as part of this library.

Using putAttributes to replace attribute values that do not exist will not result in an error response.

According to AWS, puts with replace are signficantly slower than new insert puts.

Because Amazon SimpleDB makes multiple copies of your data and uses an eventual consistency update model, agetAllAttributes or query request (read) immediately after a putAttributes or deleteAttributes operation (write) might not return the updated data.

The following limitations are enforced for this operation:

  • 100 attributes per each call
  • 56 total attribute name-value pairs per item
  • 250 million attributes per domain
  • 10 GB of total user data storage per domain

Parameters

NameDescriptionRequired?
$itemName

The name of the item.

Type: String.

Yes
$attributes

An associative array with attribute name/value pairs.

Type: Associative array.

Yes
$replace

Set true if replace values for a given attribute name.

Default value: false.

Type: String.

No

Return Value

True or false. Call getErrorCode on false.

Special Errors

ErrorDescription
InvalidParameterValue Value (" + value + ") for parameter Name is invalid. Value exceeds maximum length of 1024.
InvalidParameterValue Value (" + value + ") for parameter Value is invalid. Value exceeds maximum length of 1024.
InvalidParameterValue Value (" + value + ") for parameter Item is invalid. Value exceeds max length of 1024.
InvalidParameterValue Value (" + value + ") for parameter Replace is invalid. The Replace flag should be either true or false.
MissingParameter The request must contain the parameter DomainName.
MissingParameter The request must contain the parameter ItemName.
MissingParameter Attribute.Value missing for Attribute.Name='<attribute name>'.
MissingParameter Attribute.Name missing for Attribute.Value='<attribute value>'.
NoSuchDomain The specified domain does not exist.
NumberItemAttributesExceeded Too many attributes in this item.
NumberDomainAttributesExceeded Too many attributes in this domain.
NumberDomainBytesExceeded Too many bytes in this domain.

Examples

Sample Code

    /**
     *	simple example of paws function 
     */
     ...
     include('pawsSDB.php');
     $mySDB = new pawsSDB();
     $mySDB->setDomain('aDomainName');    // Need to set domain name before data operations
     ...
     $attr = array('name1' = 'val1', 'name2' => 'val2', 'name3' => array('vala', 'valb'));
     
     // put attributes to 'item00' in domain 'aDomainName'
     if (!$mySDB->putAttributes('item00',$attr)) {
         handle_error();
     }
     ...
     
		

Copyright © 2008 Bruce E. Wampler