(Bug 50155) Fix issue with category hierarchies on SQLite 

Based on SQLite fixes provided by #144, this PR extends to categories and category hierarchies.

- https://bugzilla.wikimedia.org/show_bug.cgi?id=50155
- Relates to #134