Bugfix - COUNT database query result was casted to a wrong type. Closes #745.