fix sql problems