2011-06-30 145 views
0

我不知道我的程序中有什麼問題。Sqlite數據庫文件正在加密或不是數據庫

kill error while killing target (killing anyway):
warning: error on line 2179 of "/SourceCache/gdb/gdb-1510/src/gdb/macosx/macosx-nat-inferior.c" in function "macosx_kill_inferior_safe": (os/kern) failure (0x5x)
quit

這裏是我的插入代碼:

-(id)init { 
    self = [super init]; 

    sqlite3 *database; 

    NSMutableArray *locations; 
    NSString *result = nil; 
    NSString *dbPath = [self getWritableDBPath]; 

    if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) 
    { 
     NSString *sqlStr = [NSString stringWithFormat:@"select Longitude,Latitude from myLocation"]; 
     const char *sqlStatement = [sqlStr UTF8String]; 
     sqlite3_stmt *compiledStatement; 

     if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { 
      locations = [NSMutableArray array]; 

      while(sqlite3_step(compiledStatement) == SQLITE_ROW) { 

       double longitude = sqlite3_column_double(compiledStatement, 0); 
       double latitude = sqlite3_column_double(compiledStatement, 1); 
       NSLog(@"%f , %f",longitude,latitude); 
       NSString *coords = [[[NSString alloc] initWithFormat:@"%f,%f\n",longitude,latitude] autorelease]; 

       [locations addObject:coords]; 
       NSLog(@"this location :-%@",locations); 
       //[coords release]; 

      } 

      result = [locations componentsJoinedByString:@","]; // same as `fake_location` 
      NSLog(@"this for resulte data :- %@",result); 
      // Get file path here 

      NSError *error; 
      if ([result writeToFile:dbPath atomically:YES encoding:NSUTF8StringEncoding error:&error]) { 
       NSLog(@"%@", [error localizedDescription]); 
      } 
     } 
     // Release the compiled statement from memory 
     sqlite3_finalize(compiledStatement); 
    } 
    sqlite3_close(database); 


    pointsArray = [[result componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] retain]; 
    pointsArrayIndex = 0; 
    oldLocationsIndex = 0; 

    [result release]; 

    oldLocations = [[NSMutableArray alloc] init]; 


    return self; 
} 

第二次,我跑我的應用程序時,在我的程序從SQlite的獲取數據運行此選擇的代碼,它第一次與此錯誤消息崩潰,它顯示我在控制檯上:

Save Error: file is encrypted or is not a database

這些錯誤是什麼意思,我該如何解決?

+1

你想火插入查詢的sqlite的????? – iMOBDEV

+0

是的我的朋友我需要的sqlite插入語句 – Ajay

+0

你試圖用NSData覆蓋整個數據庫文件,你不能這樣做,檢查我的答案在下面,你只需要引發插入查詢... – iMOBDEV

回答

1

你需要用火插入查詢如下:

-(void)insertLocation:(double)latitude withLongitude:(double)longitude 
{ 
sqlite3_stmt *insertStatement = nil; 
const char *sql = "insert into UserJourneyLocation(Latitude, Longitude) Values(?,?)"; 
int returnValue = sqlite3_prepare_v2(database, sql, -1, &insertStatement, NULL); 
if(returnValue == SQLITE_OK) 
{ 
    sqlite3_bind_double(insertStatement,1,latitude); 
      sqlite3_bind_double(insertStatement,2,longitude); 
    if(sqlite3_step(insertStatement)==SQLITE_DONE) 
    { 
     //Data; 
    } 
} 
sqlite3_finalize(insertStatement); 
} 
+0

對不起,我的朋友我做select語句不插入statemt對不起,請檢查updata問題請 – Ajay

+0

但你不能寫數據到數據庫使用[result writeToFile :dbPath atomically:YES encoding:NSUTF8StringEncoding error:&error],你能提一下爲什麼這行已被使用? – iMOBDEV

+0

我評論該行它的工作,但現在讓我看看下一個錯誤 - [CFString釋放]:發送到釋放實例0xe2db5f0的消息。 – Ajay

0

是的,我有。

轉到iphone應用程序文件夾

/用戶/(提供yourname)/庫/應用程序支持/ iPhone模擬器/用戶/應用

,並刪除,重新啓動應用程序的所有Targets.After。

+0

沒有我的朋友它sitll顯示我保存錯誤:文件被加密或不是數據庫 – Ajay

相關問題