update recursive queries to native sqlite3

sqlite3 recursive with/cte queries just came out. I retired the old
hacky and incomplete recursive queries with some proper recursive
queries. A few more queries that employ loops need to be changed as
well.