Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Database select problem
  • Hi,

    $query = \DB::select('SQL_CALC_FOUND_ROWS');
    $query->select_array(array_merge(
    \Dev10\Core::get_fields_from_table('extension_news_category', 'enc.', array(), array()),
    \Dev10\Core::get_fields_from_table('extension_news_category_description', 'encd.', array(), array())
    ));

    Sql query output : SELECT SQL_CALC_FOUND_ROWS, dev10_enc.category_id, dev10_enc.parent_id, dev10_enc.status, dev10_enc.image, dev10_enc.date_added, dev10_enc.date_modified, dev10_enc.sort_order, dev10_encd.category_id, dev10_encd.language_id, dev10_encd.name, dev10_encd.description, dev10_encd.meta_keywords, dev10_encd.meta_description, dev10_encd.seo FROM dev10_extension_news_category AS dev10_enc LEFT JOIN dev10_extension_news_category_description AS dev10_encd ON (dev10_enc.category_id = dev10_encd.category_id) WHERE dev10_encd.language_id = 1 ORDER BY dev10_encd.name ASC

    Normal Query : SELECT SQL_CALC_FOUND_ROWS dev10_enc.category_id, dev10_enc.parent_id, dev10_enc.status, dev10_enc.image, dev10_enc.date_added, dev10_enc.date_modified, dev10_enc.sort_order, dev10_encd.category_id, dev10_encd.language_id, dev10_encd.name, dev10_encd.description, dev10_encd.meta_keywords, dev10_encd.meta_description, dev10_encd.seo FROM dev10_extension_news_category AS dev10_enc LEFT JOIN dev10_extension_news_category_description AS dev10_encd ON (dev10_enc.category_id = dev10_encd.category_id) WHERE dev10_encd.language_id = 1 ORDER BY dev10_encd.name ASC

    Active Record problem select function... :/
  • HarroHarro
    Accepted Answer
    This is currently not supported, select() only supports column names and functions (via DB::expr()).
  • So what is your suggestion?
  • I don't really have one, other then perhaps fetch the compiled query (without the SQL_CALC_ROWS), stick that on it manually, and then pass everything to DB::query() ?

    I know it's been looked at in the past, but no good solution was ever found.
  • Codeigniter in select ('field', FALSE); well we did not have such problems.
    But this one went into distress.
    I do not want to write pure SQL code.
  • Fuel v1's uses Kohana's old DB layer, and that unfortunately isn't too flexible. Which is why for v2 we've written a completely new DB layer.

    You don't have to write SQL code, you can do:

    function sql_calc_found_rows($query)
    {
        return \DB::query('SQL_CALC_FOUND_ROWS '.$query->compile());
    }

    and in your code

    $query = sql_calc_found_rows(DB::select_array(array_merge(
        \Dev10\Core::get_fields_from_table('extension_news_category', 'enc.', array(), array()),
        \Dev10\Core::get_fields_from_table('extension_news_category_description', 'encd.', array(), array())
        ))
    );

    You can also make that a class method somewhere, or even extend a core database class and add it to that.
  • Thank you...
    I'm waiting new release version...
  • That may take a while, v2 won't be ready until summer next year (or so).
  • I expect no problems.
  • \DB::expr using... problem resolved...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion