I create one application that store data from NSDictionary
in SQLite. this NSDictionary
get own information from many NSArray
and store in SQLite DB. this is my code:
- (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];
}
}
}
I want two things but I not found any thing about it.
First: If in above code one or two of names changed (for example NSArray
*name was:
{@"janatan", @"louis", @"john", @"fredrick", @"vein", @"emma", @"shyla"}
how I can edit my table SQLite DB and replace louis
& fredrick
instead fred
& cristiano
?)
Second: If in above code one or two names removed (for example NSArray
*name was:
{@"janatan", @"john", @"vein", @"emma", @"shyla"}
how I can remove Record the name of the deleted?)
thanks a lot.
See Question&Answers more detail:os