fixed sql bug