Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fields() leaving uninitialized values #286

Open
esteban-turnocheck opened this issue Feb 26, 2019 · 0 comments
Open

fields() leaving uninitialized values #286

esteban-turnocheck opened this issue Feb 26, 2019 · 0 comments

Comments

@esteban-turnocheck
Copy link

esteban-turnocheck commented Feb 26, 2019

Hi all!
I've detected what could be a bug.
When you use the fields() function, it sets the _select property of the MY_Model class (declared in line 182). Then, when it fetches data and goes to _prep_after_read, in line 391 it sets _select back to the default "*".
Problem is that _prep_after_read is only called when the query brings back 1 or more rows. Not otherwise. Meaning that _select remains with the previous value. So if you do two querys, one after the other, and the first one doesn't return any row, the next one will try to fetch the same fields as the first, potentially causing errors (if query one and query two, for instance, use different tables).
Here's how lines from 983, on function get(), reads.

if ($query->num_rows() == 1)
  {
    $row = $query->row_array();
    $row = $this->trigger('after_get', $row);
    $row =  $this->_prep_after_read(array($row),FALSE);
    $row = $row[0];
    $this->_write_to_cache($row);
    return $row;
  }
else
  {
    return FALSE;
}

And this is the patch I've made to solve this issue.

if ($query->num_rows() == 1)
  {
    $row = $query->row_array();
    $row = $this->trigger('after_get', $row);
    $row =  $this->_prep_after_read(array($row),FALSE);
    $row = $row[0];
    $this->_write_to_cache($row);
    return $row;
  }
else
  {
    if(isset($this->_select))
      {
        $this->_select = '*';
      }
    return FALSE;
}

And the same goes for function get()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant