Folder heirarchies: #3788

Now supporting folder heirarchies.  The client will now descend looking for subfolders.  This task now opens up multiple outstanding requests to the Engine as well as exercises the database schema.

Closing this ticket opens the door to finishing #3692.
This commit is contained in:
Jim Nelson 2011-07-01 15:40:20 -07:00
parent a774034aff
commit 0273b78005
36 changed files with 846 additions and 249 deletions

View file

@ -87,5 +87,46 @@ public class Geary.Sqlite.FolderTable : Geary.Sqlite.Table {
return (!result.finished) ? new FolderRow.from_query_result(this, result) : null;
}
public async FolderRow? fetch_descend_async(Gee.List<string> path, Cancellable? cancellable = null)
throws Error {
assert(path.size > 0);
int64 parent_id = Row.INVALID_ID;
// walk the folder tree to the final node (which is at length - 1 - 1)
int length = path.size;
for (int ctr = 0; ctr < length - 1; ctr++) {
SQLHeavy.Query query;
if (parent_id != Row.INVALID_ID) {
query = db.prepare("SELECT id FROM FolderTable WHERE parent_id=? AND name=?");
query.bind_int64(0, parent_id);
query.bind_string(1, path[ctr]);
} else {
query = db.prepare("SELECT id FROM FolderTable WHERE parent_id IS NULL AND name=?");
query.bind_string(0, path[ctr]);
}
SQLHeavy.QueryResult result = yield query.execute_async(cancellable);
if (result.finished)
return null;
int64 id = result.fetch_int64(0);
// watch for loops, real bad if it happens ... could be more thorough here, but at least
// one level of checking is better than none
if (id == parent_id) {
warning("Loop found in database: parent of %lld is %lld in FolderTable",
parent_id, id);
return null;
}
parent_id = id;
}
// do full fetch on this folder
return yield fetch_async(parent_id, path.last(), cancellable);
}
}