Hi all -- I need a little advice. I have a database (sqlite) table that defines a parent/child relationship. I figured the easiest way to walk the hierarchy of the data would be to use a re-entrant (nested?) iterator. I'd iterate over the initial statement, until I hit a row that has a link to child records where I'd instantiate a new Iterator and start looping through those records. I have the initial Iterator built and can successfully return all the rows from a sqlite statement. However, I'm struggling to visualize the re-entrant/nested piece.
I figured I'd just define a nested flag and a nested Iterator, within the Iterator. When I hit a row that indicates there is a child query, I'd instantiate a new Iterator, flip the nested flag to true, and then successive calls to the parent Iterator.get/next would be chained down to the childs Iterator.get/next methods. In this particular case, I don't need the actual row with the child indicator, returned via the iteratation.. However, it wouldn't hurt anything if it did. (in case it makes a difference) Unfortunately, I can't figure out how I'm supposed to iterate over an Iterator w/o using a foreach loop? When I started, I figured it'd look something like this: class Query { class Iterator { next() { .. step over query .. if (Sqlite.DONE) return false; if ( record.linked_child != null ) { child = new Query(record.linked_child); nested = true; } if ( nested ) { var ret = child.next(); if ( ! ret ) nested = false; } return true } get() { if ( nested) return child.get(); return record; } } } But, it wasn't immediately obvious to me that the nested "query" object wouldn't expose the next and get methods. I gotta believe this is possible, but I'm surely not seeing the solution. (an elegant one anyway) OR, if someone knows a better way to do this, I'm all ears.. As always.. I appreciate any help! Shawn _______________________________________________ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list