how to add record in amazon simple db in domain in iphone application

55 views Asked by At

I am making an iPhone application in which I am using Amazon SimpleDB which has domain Category in which I want to add record from the iPhone app. Any idea or help how to add the data from iPhone app. In tutorials they show how to add using RazorSQL but how to do adding using iPhone application code like we add record in SQLite or any other data base.

For selecting it is easy to get data from the Amazon SimpleDB in iPhone application using following way but how to insert new record.

AmazonSimpleDBClient*sdbClient = [[AmazonSimpleDBClient alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
NSString*itemNameUser=@"UserName";

SimpleDBGetAttributesRequest *gar = [[SimpleDBGetAttributesRequest alloc] initWithDomainName:DOMAIN_NAME andItemName:itemNameUser];
SimpleDBGetAttributesResponse *response = [sdbClient getAttributes:gar];

NSString*nextToken;
NSLog(@" Catgeory ID is %@ ", appDelegate.categoryID);
NSLog(@"%@ ", appDelegate.organizationCode);

SimpleDBSelectRequest *selectRequest = [[[SimpleDBSelectRequest alloc] initWithSelectExpression:[NSString stringWithFormat:@"select * from Topic where CategoryLinkedID='%@'",appDelegate.categoryID]] autorelease];
NSLog(@"Select Request is %@",selectRequest);

selectRequest.consistentRead = YES;
nextToken = selectRequest.nextToken;
NSLog(@"Next Token is %@",nextToken);

SimpleDBSelectResponse *selectResponse = [sdbClient select:selectRequest];
int a=selectResponse.items.count;
NSLog(@"Count of a is %d",a);

if (a==0) { 
}
else{
    //   SimpleDBItem *countItem = [selectResponse.items objectAtIndex:0];
    for (SimpleDBItem *countItem in selectResponse.items) {
        NSMutableArray*test;
        NSMutableArray*attributeList;
        attributeList=[[NSMutableArray alloc] init];
        [attributeList addObject:@"TopicID"];
        [attributeList addObject:@"TopicName"];
        [attributeList addObject:@"TopicAddedByUserID"];
        [attributeList addObject:@"TopicAddedDateTime"];
        [attributeList addObject:@"CategoryLinkedID"];
        [attributeList addObject:@"HiveletCode"];

        test=[[NSMutableArray alloc] init];
        test=[self getIntValueForAttribute:@"TopicID" fromList:countItem.attributes];

        NSDictionary *userInfo =[[NSDictionary alloc]init];
        NSString*str2=[self getIntValueForAttribute:@"TopicName" fromList:countItem.attributes];
        NSString*str3=[self getIntValueForAttribute:@"TopicAddedByUserID" fromList:countItem.attributes];
        NSString*str4=[self getIntValueForAttribute:@"TopicAddedDateTime" fromList:countItem.attributes];
        NSString*str5=[self getIntValueForAttribute:@"CategoryLinkedID" fromList:countItem.attributes];
        NSString*str6=[self getIntValueForAttribute:@"HiveletCode" fromList:countItem.attributes];

        NSLog(@"TopicID is %@",test);
        NSLog(@"TopicName is %@",str2);
        NSLog(@"TopicAddedByUserID is %@",str3);
        NSLog(@"TopicAddedDateTime is %@",str4);
        NSLog(@"CategoryLinkedID is %@",str5);
        NSLog(@"HiveletCode is %@",str6);

        Topic *theObject =[[Topic alloc] init];
        [theObject setTopicID:test];
        [theObject setTopicName:str2];
        [theObject setTopicAddedByUserID:str3];
        [theObject setTopicAddedDateTime:str4];
        [theObject setCategoryLinkedID:str5];
        [theObject setOrganizationCode:str6];

        [appDelegate.topicArray addObject:theObject];
        int count=[appDelegate.topicArray count];

    }
1

There are 1 answers

0
Bob Kinney On

You may want to take a look at the our high scores sample app which includes code for doing various operations with SimpleDB. The code is now available in our GitHub repository.