如何在iphone应用程序中的域中的亚马逊简单数据库中添加记录

时间:2013-12-10 06:08:46

标签: amazon-web-services insert amazon-simpledb

我正在制作一个iPhone应用程序,我在其中使用具有域类别的Amazon SimpleDB,其中我想从iPhone应用程序添加记录。任何想法或帮助如何从iPhone应用程序添加数据。在教程中,他们展示了如何使用RazorSQL添加,但如何使用iPhone应用程序代码添加,例如我们在SQLite或任何其他数据库中添加记录。

为了选择,可以使用以下方式从iPhone应用程序中的Amazon SimpleDB轻松获取数据,但如何插入新记录。

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 个答案:

答案 0 :(得分:1)

您可能需要查看我们的high scores sample app,其中包含使用SimpleDB执行各种操作的代码。该代码现已在我们的GitHub repository中提供。