image controller sql query fixes