Problem in updating sqlite database

Discussion in 'iOS Programming' started by iphonejudy, Dec 31, 2009.

  1. iphonejudy macrumors 6502

    iphonejudy

    Joined:
    Sep 12, 2008
    #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);
    	 }
     
  2. mraheel macrumors regular

    Joined:
    Apr 18, 2009
    #2
    Verify if your database file is accessed in the main bundle or do you copy it to the documents folder before you open it.
     
  3. AndyCodez macrumors regular

    Joined:
    Aug 6, 2009
    #3
    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.
     

Share This Page