Fix some sql errors