You can do this before your query:
$this->db->_compile_select();
.. and then this, once you've run the query:
$this->db->last_query();