Getting Data from a Domain

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.

Java

To run the sample

  1. Open a clean copy of QuerySample.java.

  2. 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);
  3. 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.

C#

To run the sample

  1. Open AmazonSimpleDBSamples.cs.

  2. Comment out the code you added in the previous section.

  3. Add the following to the Query Action section:

    String queryExpressionSingleAttribute = "['Category' = 'Clothes']";
    Query singleAttributeQueryAction = new Query().WithDomainName("MyStore").WithQueryExpression(queryExpressionSingleAttribute);
    
    QuerySample.InvokeQuery(service, singleAttributeQueryAction);
    
  4. 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.

Perl

To run the sample

  1. Open a clean copy of QuerySample.pl.

  2. 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']"
    });
  3. 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.

PHP

To run the sample

  1. Open a clean copy of QuerySample.php.

  2. 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']");
    
  3. 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.

VB.NET

To run the sample

  1. Open AmazonSimpleDBSamples.vb.

  2. Comment out the code you added in the previous section.

  3. Add the following to the Query Action section:

    Dim singleAttributeQueryAction As New Query()
    singleAttributeQueryAction.WithDomainName("MyStore").WithQueryExpression("['Category' = 'Clothes']")
    
    QuerySample.InvokeQuery(service, singleAttributeQueryAction)
    
  4. 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.

Scratchpad

To run the sample

  1. Open the scratchpad application with a web browser.

  2. Select Query from the Explore API list box.

  3. Enter MyStore in the Domain Name field.

  4. Enter the following in the Query Expression field: ['Category' = 'Clothes'].

  5. 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.

  6. If you need to view the next page of results, enter the next token in the Next Token field.

    [Note]Note

    To get the next page of results, you only need to specify the domain name and the next token.

  7. 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.