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.
Changed the test in order to not fail because of #149 issue

The test for the #149 issue would be added in another pull request, as @spekary suggested.
Fix for wrong test in issue #100
Merge pull request #147 from olegabr/bug-100

Fix for #100 issue