Some fixes in sql.