当我在运行的iPhone应用程序中从sqlite数据库中第二次检索时,我的应用程序崩溃了

时间:2010-11-16 10:09:19

标签: iphone sqlite

- (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;
}

第二次指针不进入条件&直接进入其他部分。

3 个答案:

答案 0 :(得分:2)

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

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

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

答案 1 :(得分:1)

你这里有一个错字:

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

它应该发布data,而不是date1

答案 2 :(得分:0)

在我的给定代码中我没有t open/close database every Time that s为什么会出现这样的问题而且类型转换中的一些错误我犯了错误,如上所述Chandresh说