2012-09-02 66 views
0

我是新來的iOS和AWS ...如何從iOS SDK中的SimpleDB AWS中檢索數據並顯示它們?

我一直試圖讓一些方法來從我在AWS上SDB檢索數據...

首先,我想連接到aws然後我想從somedomain中檢索所有內容並將其放入數組中。並讀出數組內部的內容。

// Connecting to SDB  
AmazonSimpleDBClient *sdbClient = [[AmazonSimpleDBClient alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY]; 


@try { 
    SimpleDBSelectRequest *selectRequest = [[SimpleDBSelectRequest alloc] initWithSelectExpression:@"select * from somedomain"]; 
    selectRequest.consistentRead = YES; 
    if (self.nextToken != nil) { 
     selectRequest.nextToken = self.nextToken; 
    } 

    SimpleDBSelectResponse *selectResponse = [sdbClient select:selectRequest]; 
    self.nextToken = selectResponse.nextToken; 

    NSLog(self.nextToken); 

} 
@catch (NSException *exception) { 
    NSLog(@"Exception : [%@]", exception); 

} 

在此先感謝傢伙。我感謝所有的幫助。 :)

回答

1

這裏有一些幫助列出在Java中的域名,創建域名,添加屬性,刪除屬性和列表項。

public boolean checkSubscriptionToAmazonSimpleDB(String accessKey, String secretKey) { 
      try { 
       basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey); 
       amazonSimpleDBClient = new AmazonSimpleDBClient(basicAWSCredentials); 
       String sNextToken = ""; 
       boolean bDomainExist = false; 
       do { 
        ListDomainsRequest listDomainsRequest = new ListDomainsRequest(); 
        listDomainsRequest.setMaxNumberOfDomains(100); 
        listDomainsRequest.setNextToken(sNextToken); 
        ListDomainsResult listDomainsResult = amazonSimpleDBClient.listDomains(listDomainsRequest); 
        sNextToken = listDomainsResult.getNextToken(); 
        List<String> list = listDomainsResult.getDomainNames(); 
        for (String domain : list) { 
         System.out.println(domain); 
        } 
       } while (sNextToken != null && bDomainExist == false); 

      } catch (Throwable ex) { 
       System.out.println(ex.toString()); 
       return false; 
      } 
      return true; 
     } 

     public void createDomain(String domain) { 
      CreateDomainRequest createDomainRequest = new CreateDomainRequest(domain); 
      amazonSimpleDBClient.createDomain(createDomainRequest); 

     } 

     private boolean addItem(String domain, String itemName) { 
      try { 
       PutAttributesRequest putAttributesRequest = new PutAttributesRequest(); 
       putAttributesRequest.setDomainName(domain); 
       putAttributesRequest.setItemName(itemName); 
       List<ReplaceableAttribute> list = new ArrayList<ReplaceableAttribute>(); 
       list.add(new ReplaceableAttribute("A", "a", true)); 
       list.add(new ReplaceableAttribute("B", "c", true)); 
       list.add(new ReplaceableAttribute("C", "b", true)); 
       putAttributesRequest.setAttributes(list); 
       amazonSimpleDBClient.putAttributes(putAttributesRequest); 
      } catch (Throwable ex) { 
       System.out.println(ex.toString()); 
       return false; 
      } 
      return true; 
     } 

     private boolean deleteItem(String domain, String itemName) { 
      try { 
       DeleteAttributesRequest deleteAttributesRequest = new DeleteAttributesRequest(); 
       deleteAttributesRequest.setDomainName(domain); 
       deleteAttributesRequest.setItemName(itemName); 
       amazonSimpleDBClient.deleteAttributes(deleteAttributesRequest); 
      } catch (Throwable ex) { 
       System.out.println(ex.toString()); 
       return false; 
      } 
      return true; 
     } 

     public void getListOfArchived(String domainname, String pagesize, String nextToken) { 
      SelectResult selectResult = null; 
      String sNextToken = null; 
      String query = null; 
      do { 
       query = "select * from " + domainname; 
       SelectRequest selectRequest = new SelectRequest(query); 
       selectRequest.setNextToken(nextToken); 
       selectResult = amazonSimpleDBClient.select(selectRequest); 
       sNextToken = selectResult.getNextToken(); 
       List<Item> list = selectResult.getItems(); 
       for(Item item: list){ 
        item.getName(); // itemName 
        List<Attribute> listAttribute = item.getAttributes(); 
        for(Attribute attribute:listAttribute){ 
         attribute.getName(); // Attribute Name 
         attribute.getValue(); // Attribute value; 
        } 
       } 
      } while (sNextToken != null); 

     } 
+0

Hi @Ashish Pancholi,在ios中我如何刪除simpledb中的一行。 – Vendetta

+0

@Vendetta請參閱上面的'private boolean deleteItem(String domain,String itemName)'方法。您可以通過僅指定刪除請求中的項目名稱來刪除行。 –

+0

@Vendetta https://github.com/aws/aws-sdk-ios/blob/master/src/Amazon.SimpleDB/Model/SimpleDBBatchDeleteAttributesRequest.m –

相關問題