Fix for incorrect handling of SQL results