【问题标题】:My application crashed when I retrieve second time from sqlite database in my running iPhone application当我在运行的 iPhone 应用程序中第二次从 sqlite 数据库中检索时,我的应用程序崩溃了
【发布时间】:2010-11-16 10:09:18
【问题描述】:
- (void) hydrateDetailViewData {

    strong text//If the detail view is hydrated then do not get it from the database.
    if(isDetailViewHydrated) return;

    if(detailStmt == nil) {
        const char *sql = "Select name,Rdate,image from Movie_data Where id = ?";
        if(sqlite3_prepare_v2(database, sql, -1, &detailStmt, NULL) != SQLITE_OK)
            NSAssert1(0, @"Error while creating detail view statement. '%s'", sqlite3_errmsg(database));
    }

    sqlite3_bind_int(detailStmt, 1, informationId);

    if(SQLITE_DONE != sqlite3_step(detailStmt)) {

        NSString *str = [NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, 0)];
        self.informationName = str;

        //Get the date in a temporary variable.
        NSDate *date1;
        date1 = [NSDate dateWithTimeIntervalSince1970:sqlite3_column_double(detailStmt, 1)];

        //NSInteger dateInInteger = sqlite3_column_int(detailStmt, 2);
        //self.setDate= dateInInteger;

    //Assign the date. The date value will be copied, since the property is declared with "copy" attribute.
        self.date = date1;

        NSData *data =[[NSData alloc] initWithBytes:sqlite3_column_blob(detailStmt, 2) length:sqlite3_column_bytes(detailStmt, 2)];

        if(data == nil)
            NSLog(@"No image found.");
        else
            self.img = [UIImage imageWithData:data]; 

        //Release the temporary variable. Since we created it using alloc, we have own it.
        [date1 release];
    }
    else
        NSAssert1(0, @"Error while getting the price of coffee. '%s'", sqlite3_errmsg(database));
    //DetailViewController.dvObj=
    //Reset the detail statement.

    sqlite3_reset(detailStmt);

    //Set isDetailViewHydrated as YES, so we do not get it again from the database.
    isDetailViewHydrated = YES;
}

第二时间指针不进入if条件&直接进入else部分。

【问题讨论】:

    标签: iphone sqlite


    【解决方案1】:

    请更改您的日期绑定代码并使用以下代码:

    NSInteger dateValueS = sqlite3_column_int(detailStmt, 1);
    self.date17 = (int )dateValueS;
    

    其中date17 是在.h 文件中定义的NSInteger,因为我认为您在数据库中的日期字段是整数。

    【讨论】:

      【解决方案2】:

      这里有错别字:

      //Release the temporary variable. Since we created it using alloc, we have own it.
      [date1 release];
      

      它应该释放data,而不是date1

      【讨论】:

      • @AJPatel:这就是答案吗?
      • 不,伙计,他们在我从 int 获取数据时出错了,这就是我的应用程序崩溃了
      【解决方案3】:

      在我的给定代码中我没有t open/close database every Time thats 为什么我会出现这样的问题以及类型转换中的一些错误我犯了上面 Chandresh 所说的错误

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-07
        相关资源
        最近更新 更多