Fixed crash with SQL query