Fixes bug 991730 - Fixed custom queries. r=peterbe