2013-03-02 77 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声明的目的是什么?

相关问题