2011-11-22 57 views
0

我以編程方式在Xcode 4的iPhone應用程序中以編程方式創建了我的數據庫。我也插入到數據庫中並從中選擇所需的值。一切似乎工作正常,但我想檢查值是否重複或不。我無法在Xcode中打開我的數據庫文件,那麼有沒有辦法打開數據庫並檢查其中的值?在iPhone模擬器中查看sqlite3數據庫

回答

4

有兩種方法可以做到這一點: -

1)使用SQLite經理Firefox瀏覽器,然後工具 - >源碼管理器 - >打開數據庫

現在你可以運行查詢

select * from tablename; 您現在可以手動檢查重複值。

鏈接安裝SQLite的經理

https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

2)如果您想通過數據庫來檢查重複值

-(NSMutableArray *) readFromDatabase:(NSString *)query{ 
    // Setup the database object 
    sqlite3 *database; 

    // Init the animals Array 
    MutableArray = [[NSMutableArray alloc] init]; 
    NSString *readCommand=query; 

    //readCommand=[readCommand stringByAppendingFormat:@"%@';",patientID]; 
    // Open the database from the users filessytem 
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { 
     // Setup the SQL Statement and compile it for faster access 
     const char *sqlStatement = [readCommand UTF8String]; 
     sqlite3_stmt *compiledStatement; 
     if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { 
      // Loop through the results and add them to the feeds array 
      while(sqlite3_step(compiledStatement) == SQLITE_ROW) { 
       // Read the data from the result row 
       [MutableArray addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)]]; 
      } 
     } 
     // Release the compiled statement from memory 
     sqlite3_finalize(compiledStatement); 
    } 
    sqlite3_close(database); 
    return MutableArray; 
} 

調用這個函數。並檢查返回的數組值。