Fix issues with sqlite field parsing.

The previous attempt would still fail on unions or derived table join
queries. This new approach is a bit slower but more robust.

Refs #3972