Correctly handle optional values.

This fixes handling of optional values in jDub queries. I'm not thrilled with the code duplication, and would be open to suggestions to fix this.