ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

[SOLVED] Get the SQL???

October 24, 2011 12:55pm

Subscribe [1]
  • #1 / Oct 24, 2011 12:55pm

    MrBaseball34

    99 posts

    I have a third-party plugin that uses these functions to “build” a sql statement to retrieve some data:

    $this->EE->db->select();
    $this->EE->db->from();
    $this->EE->db->join();
    $this->EE->db->where()
    $this->EE->db->order_by();
    $this->EE->db->limit();

    How can I get the SQL that this thing builds before the $this->EE->db->get() is run?

  • #2 / Oct 24, 2011 2:06pm

    Jamie Poitra

    409 posts

    That all takes place in the Active Record class.  I’d look in there.

    Jamie

  • #3 / Oct 24, 2011 2:52pm

    MrBaseball34

    99 posts

    I can’t find an Active Record class in the API documentation. I have v2.1.0

  • #4 / Oct 24, 2011 2:56pm

    Jamie Poitra

    409 posts

    It’s a part of CodeIgniter not EE specifically.

    http://ellislab.com/codeigniter/user-guide/database/active_record.html

    I suspect you could just print out $this->EE->db right after the lines that run the query and you’d get the actual query being built somewhere in there.

    print_r($this->EE->db); exit();
  • #5 / Oct 24, 2011 3:43pm

    MrBaseball34

    99 posts

    I finally got it, thanks. Kind of stupid to not be able to have a function like $this->EE->db->SQL() to return the sql that was built. I took a look at that class and it is very convoluted and messy.

  • #6 / Oct 24, 2011 4:00pm

    Jamie Poitra

    409 posts

    Well its an abstraction layer.  By it’s nature it’s going to be messy if it wants to try and support most everything SQL can do.

    It’s true though, it’s a bit weird you can’t spit out the query that’s being built more easily.  I’d suggest making a feature request on that.

    Jamie

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases