Refactor the type casting of booleans in MySQL