fixed sql problems