Fix for #100 issue

The same behavior as in the BuildQueryStatement function is implemented for the QueryCount function.
Unit test is added for the QueryCount function.