Fix some SQL issues.