Add query function for prepared SQL statements