In the previous sections, attributes were added and deleted from the sample. This section provides examples of how to write a query.
The following sample code snippets demonstrate querying for items with the attribute Category that contain the value Clothes.
To run the sample
Open a clean copy of QuerySample.java.
Remove any comment marks from the invokeQuery(service, request); line and add the following lines
after // @TODO: set request parameters here:
String queryExpression = "['Category' = 'Clothes']";
request.withDomainName("MyStore").withQueryExpression(queryExpression);Compile and run the sample.
Amazon SimpleDB returns items with the attribute Category that contain the value Clothes.
To view the attributes of the returned items, see Getting the Attributes of an Item.
To run the sample
Open AmazonSimpleDBSamples.cs.
Comment out the code you added in the previous section.
Add the following to the Query Action section:
String queryExpressionSingleAttribute = "['Category' = 'Clothes']";
Query singleAttributeQueryAction = new Query().WithDomainName("MyStore").WithQueryExpression(queryExpressionSingleAttribute);
QuerySample.InvokeQuery(service, singleAttributeQueryAction);
Run the sample.
Amazon SimpleDB returns items with the attribute Category that contain the value Clothes.
To view the attributes of the returned items, see Getting the Attributes of an Item.
To run the sample
Open a clean copy of QuerySample.pl.
Remove any comment marks from the invokeQuery($service, $request); line and add the following lines
after the // @TODO: set request parameters here line:
my $request = Amazon::SimpleDB::Model::Query->new({
DomainName=> "MyStore",
QueryExpression => "['Category' = 'Clothes']"
});Run the sample.
Amazon SimpleDB returns items with the attribute Category that contain the value Clothes.
To view the attributes of the returned items, see Getting the Attributes of an Item.
To run the sample
Open a clean copy of QuerySample.php.
Remove any comment marks from the invokeQuery($service, $request); line and add the following lines
after the // @TODO: set request parameters here line:
$request = new Amazon_SimpleDB_Model_Query();
$request->setDomainName('MyStore');
$request->setQueryExpression("['Category' = 'Clothes']");
Run the sample.
Amazon SimpleDB returns items with the attribute Category that contain the value Clothes.
To view the attributes of the returned items, see Getting the Attributes of an Item.
To run the sample
Open AmazonSimpleDBSamples.vb.
Comment out the code you added in the previous section.
Add the following to the Query Action section:
Dim singleAttributeQueryAction As New Query()
singleAttributeQueryAction.WithDomainName("MyStore").WithQueryExpression("['Category' = 'Clothes']")
QuerySample.InvokeQuery(service, singleAttributeQueryAction)
Run the sample.
Amazon SimpleDB returns items with the attribute Category that contain the value Clothes.
To view the attributes of the returned items, see Getting the Attributes of an Item.
To run the sample
Open the scratchpad application with a web browser.
Select Query from the Explore API list box.
Enter MyStore in the Domain Name field.
Enter the following in the Query Expression field: ['Category' = 'Clothes'].
To limit the number of items returned, enter a value in the Max Number Of Items field.
If there are more items than you specified in the Max Number Of Items field, Amazon SimpleDB returns a next token.
If you need to view the next page of results, enter the next token in the Next Token field.
![]() | Note |
|---|---|
To get the next page of results, you only need to specify the domain name and the next token. |
Select from the following:
To invoke the request, click Invoke Request.
Amazon SimpleDB returns items with the attribute Category that contain the value Clothes.
To view the signed URL, click Display Signed URL. Then, copy and paste the signed URL into a browser.
Amazon SimpleDB returns items with the attribute Category that contain the value Clothes.
To view the string to sign, click Display String to Sign.
To view the attributes of the returned items, see Getting the Attributes of an Item.