Update SqlPriorityQueue to resolve Issue #3099

Fixes Issue #3099.
By moving the compare function up the chain and only setting flags bottom up, the code stays maintainable and prevents dirty circular references. Those nasty refs should be a last resort.