Fixes bug 991730 - Fixed custom queries.

@peterbe r?