how to edit sqlite DB

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.


for that you can use UPDATE Query.

try like this run for loop with unique identification value and update the values.

UPDATE table1 SET ContactName='newName' WHERE id=uniqu_id

Use this one.

NSString *query = [NSString stringWithFormat:@"UPDATE table1 SET  name='%@' WHERE id='%@' ,[dic objectForKey:@"name"],[dic objectForKey:@"id"]];


NSString *query = [NSString stringWithFormat:@"UPDATE table1 SET  name='%@',age='%@' WHERE id='%@' ,[dic objectForKey:@"name"],[dic objectForKey:@"age"],[dic objectForKey:@"id"]];

Need Your Help

how to create a camera action common for all android devices

java android upload camera

in my app i want use the camera for capturing image and send to a server.

Issue with Homebrew install on Mac

osx bash homebrew

As prescribed by the Homebrew installation guide I input the following into the terminal:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.