2013-03-02 78 views
0

我想在我的應用程序中添加SQLite支持,但是我遇到了一個問題,所以我試圖在Internet上搜索某些東西,並且找到了一個教程。但問題是,本教程使用的數據庫被應用程序讀取,但是當我添加個人數據庫(我修改了代碼)時,它不被讀取。有什麼建議麼?訪問數據庫記錄的難度

這是代碼(部分):

static sqlite3 *database = nil; 
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) { 

    const char *sql = "select id,name from myDb"; 
    sqlite3_stmt *selectstmt; 

    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) { 
     while(sqlite3_step(selectstmt) == SQLITE_ROW) { 

      id = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 0)]; 
      name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)]; 


      dictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:id, @"id", name, @"nome", nil]; 

      [dictionary release]; 
     } 
    } 


else{ 
    sqlite3_close(database); 

} 
+1

你的問題和代碼是(而且)是超級格式不正確。在發佈之前,請盡力校對。 – 2013-03-02 22:22:17

+0

請指定確切的問題,我們不知道您使用了哪個教程以及代碼中發生了什麼。它是否進入if語句? – 2013-03-04 04:56:31

回答

0

你需要釋放資源else語句之前:

// "Finalize" the statement - releases the resources associated with the statement. 
    sqlite3_finalize(selectstmt); 

,什麼是release聲明的目的是什麼?

相關問題