【发布时间】:2013-05-02 16:25:58
【问题描述】:
我创建了一个应用程序,将来自NSDictionary 的数据存储在SQLite 中。这个NSDictionary 从许多NSArray 获取自己的信息并存储在SQLite DB 中。这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
int number = [self GetNumberOfRecord]; //this method get number of rows in sqlite
NSArray *idd = @[@"122", @"234", @"453", @"53464", @"4565", @"1111", @"2222"];
NSArray *name = @[@"janatan", @"fred", @"john", @"cristiano", @"vein", @"emma", @"shyla"];
NSArray *age = @[@"23", @"35", @"12", @"24", @"22", @"34", @"56"];
NSArray *sex = @[@"male", @"male", @"male", @"male", @"male", @"famale", @"famale"];
NSString *query2 = [NSString stringWithFormat:@"select * from table1 where name = '%@'", [name lastObject]];
//NSLog(@"query : %@", query2);
BOOL recordExist = [self recordExistOrNot:query2];
if (!recordExist) {
for (int i = number; i < [idd count]; i++)
{
NSString *a = [idd objectAtIndex:i];
NSString *b = [name objectAtIndex:i];
NSString *c = [age objectAtIndex:i];
NSString *d = [sex objectAtIndex:i];
NSString *query = [NSString stringWithFormat:@"insert into table1 (id, name, age, sex) values ('%@', '%@', '%@', '%@')", a, b, c, d];
NSLog(@"%@", query);
[self executeQuery:query];
}
}
}
我想要两件东西,但我没有找到任何东西。
First:如果在上面的代码中,一两个名字发生了变化(例如NSArray *name 是:
{@"janatan", @"louis", @"john", @"fredrick", @"vein", @"emma", @"shyla"}
我如何编辑我的表 SQLite DB 并替换 louis & fredrick 而不是 fred & cristiano?)
第二:如果在上面的代码中删除一两个名字(例如NSArray *name 是:
{@"janatan", @"john", @"vein", @"emma", @"shyla"}
我怎样才能删除记录被删除的名字?)
非常感谢。
【问题讨论】:
-
您的数据是动态的还是静态的,意味着您如何从 API(服务器)或本地获取数据,静态的(如您在此处描述的)?
-
来自 API 服务器的 json
-
我的朋友,我从 API 的 json 中获取了这些数据,并且可能发生了变化。
-
一次检查我的答案。
-
老兄,使用FMDB。如果您直接处理 sqlite 而不是 coredata,它是必须的。
标签: ios objective-c sqlite