Client should not crash Server when db is empty

* solved a bug in getQuery fn.
* solved a bug in initPQ fn.
* solved a bug in getStats fn.