if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
//const char *sql = "select TaskId,TaskName,StartDate,DueDate,Status,CategoryId from ToDo";
const char *sql = "SELECT TaskId,TaskName,StartDate,DueDate,Status,ToDo.CategoryId,CategoryName FROM ToDo LEFT OUTER JOIN Category ON ToDo.CategoryId=Category.CategoryId";
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);
ToDo *toDoObj = [[ToDo alloc] initWithPrimaryKey:primaryKey];
toDoObj.taskName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
toDoObj.startDate = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
toDoObj.dueDate = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
toDoObj.status = sqlite3_column_int(selectstmt, 4);
toDoObj.categoryId = sqlite3_column_int(selectstmt, 5);
toDoObj.category = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 6)];
toDoObj.isDirty = NO;
[appDelegate.todoArray addObject:toDoObj];
[toDoObj release];
}
}
}
else
sqlite3_close(database);