Fix some SQL bugs in the configure while loop