Fix some oversights in sql preparation.