当下面的函数被调用,我得到EXC_BAD_ACCESS崩溃。看起来FMDB在解析subject_id NSInteger时遇到了问题,因为当它击中WHERE子句中的这个subject_id列时,它会通过两个NString和炸弹。保存到数据库使用FMDB崩溃解释NSInteger
- (void) saveAllData {
if(isDirty) {
DrillDownAppAppDelegate *appDelegate = (DrillDownAppAppDelegate *)[[UIApplication sharedApplication] delegate];
FMDatabase *database = [FMDatabase databaseWithPath:appDelegate.getDBPath];
if ([database open]) {
[database executeUpdate:@"update Subject Set subject = ?, category = ? where subject_id = ?",
self.title, self.category_title, self.subject_id];
[database close];
}
isDirty = NO;
}
//Reclaim all memory here.
[title release];
title = nil;
[category_title release];
category_title = nil;
}
的问题是,我遇到了在FMDB另一篇文章中插入的问题一样,这归结为我subject_id成员有些不妥。我相信我在标题中使用了错误的声明。那就是:
//
// Subject.h
// DrillDownApp
#import <UIKit/UIKit.h>
@interface Subject : NSObject {
NSInteger subject_id;
NSString *category_title;
NSString *title;
// NSMutableArray *quotes;
BOOL isDirty;
// BOOL isDetailViewHydrated;
}
- (id) initWithPrimaryKey:(NSInteger)pk;
@property (nonatomic, readwrite) BOOL isDirty;
//@property (nonatomic, readwrite) BOOL isDetailViewHydrated;
- (void) addSubject;
- (NSInteger)getNextSubjectId;
@property (nonatomic, assign) NSInteger subject_id;
@property (nonatomic, copy) NSString * title;
@property (nonatomic, copy) NSString * category_title;
//@property (nonatomic, retain) NSMutableArray *quotes;
//- (void) saveAllData;
@end
(注:我编辑这majorly,我想通了,它的其余部分。)
您正在将标题值和类别标题值设置为主题对象。但是,您将对象保存到数据库的位置? – Ilanchezhian 2012-01-27 07:40:19
我将其更新为包含将对象保存到数据库的saveAllData函数。但问题是,它甚至没有使数据保留在对象中。我认为我的问题是我没有正确调用setTitle和setCategory_Title函数,因为在调试器中运行时,这些方法永远不会被触及... – jroyce 2012-01-27 18:44:36