2010-11-16 134 views
1
- (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; 
} 

第二次指針不進去,如果條件&在其他部分直接進入檢索SQLite數據庫第二次我的應用程序崩潰。當我在運行iPhone應用程序

回答

0
我定的代碼

我沒t open/close database every Time that爲什麼這樣的問題發生在我和類型轉換一些錯誤我犯錯如上Chandresh說

1

您在這裏有一個錯字:

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

它應該釋放data,不date1

+0

謝謝主席先生,您的回覆.... – AJPatel 2010-11-22 05:08:26

+0

@AJPatel:是那答案? – JeremyP 2010-11-22 08:51:14

+0

沒有朋友他們是錯誤在我的數據從int到日期這是我的應用程序gona崩潰 – AJPatel 2010-11-23 06:41:34

2

請更改日期綁定代碼並使用下面的代碼:

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

其中date17NSInteger是在.h文件中定義的,因爲我覺得在數據庫中的日期字段是整數。

相關問題