Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iphonejudy

macrumors 6502
Original poster
Sep 12, 2008
301
1
I want to update my database.I got the "done" message.But if i open the database the changes are not affected (ie) the database is not updated.

Can anyone tell me the solution?

Code:
- (void)InsertdataintoDatabase
 {
	 
	 
	
	 sqlite3 *the_pDatabase ;
	 sqlite3_stmt *addStmt;
	
 
	 if(sqlite3_open([m_pDatabasePath UTF8String], &the_pDatabase) == SQLITE_OK)
	 {
		  
		 
	         int count1=1;
		 NSString *date1=@"30-10-2009";
		  NSString *comments1=@"hi";
		  int id1=1;
		  NSString *sqlst = [NSString stringWithFormat:@"UPDATE tomato1 SET count='%d', date='%@', comments='%@' WHERE pk='%d'",count1,date1,comments1,id1];
							  
		 
		 
		 
         const char *sql = [sqlst UTF8String];
		 
				
		 if (sqlite3_prepare_v2(the_pDatabase, sql, -1, &addStmt, NULL) != SQLITE_OK) {
			 
			 NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(the_pDatabase));
		 }
		 
	  
	 
    
      int success = sqlite3_step(addStmt);
	 
	if (success != SQLITE_DONE) {
		printf("Not done");
		 
	 }
	 else
	 {
			printf("done"); 
	 }
		 
	}
	 sqlite3_reset(addStmt);
	 
	 
	 sqlite3_finalize(addStmt);
	 }
 
Verify if your database file is accessed in the main bundle or do you copy it to the documents folder before you open it.
 
Yeah if you are trying to use a prebuilt database included from resources youll first have to make a copy of the database then write to the copy.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.