Fixed repository sql errors