我正在处理以下试图连接到数据库的代码,但我被困在这一点上:
#import "ToDos.h"
#import "AppDelegate.h"
static sqlite3 *database = nil;
@implementation ToDos
@synthesize todoID, title, descr, isDirty, isDetailViewHydrated;
- (void) dealloc {
}
+ (void) getInitialDataToDisplay:(NSString *)dbPath {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (sqlite3_open([dbPath UTF8String], database) == SQLITE_OK) {
// const char *sql = "select * from todos";
// sqlite3_stmt *selectstmt;
// if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
//
// while(sqlite3_step(selectstmt) == SQLITE_ROW) {
//
// NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
// ToDos *coffeeObj = [[ToDos alloc] initWithPrimaryKey:primaryKey];
// coffeeObj.title = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
//
// coffeeObj.isDirty = NO;
//
// [appDelegate.todosArray addObject:coffeeObj];
// // [coffeeObj release];
// }
// }
}
else
sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
}
- (id) initWithPrimaryKey:(NSInteger) pk {
// [super init];
todoID = pk;
isDetailViewHydrated = NO;
return self;
}
@end
问题接缝在指针中......
static sqlite3 *database = nil;
和
if (sqlite3_open([dbPath UTF8String], database) == SQLITE_OK) {
但这是尝试启动应用程序时的错误消息
教程中的代码相同,它可以工作:)