fix invalid sql statement error when calling .count