Joomla CMS [#26744] loadnextrow and loadnextobject do not iterate (#339) #346

Closed
wants to merge 4 commits into
from

7 participants

@brbrbr

No description provided.

@eddieajau

Thanks for the pull request. I think that change might cause problems if you try to use a second (different) query and iterative with loadNext*. I think you will probably have to check that $this->cursor is not empty and I also think a prerequisite is that you have to fire $db->query first, then loop over $db->loadNextRow (even for the first one). Does that make sense? That introduces a slight backward compatible issue but I don't see any other reliable way around the problem.

@brbrbr

using the $this->cursos instead of the static allows to reset the query using setquery/query without the need to iterate thru the result set.

Having a $this->query in loadnextrow/loadnextobject keeps the functions backward compatible, althought I don't think that is a big issue since the current version do not function as intended ( doing the job of loadrow/loadobject)

@eddieajau

Ok, thanks. I'll take a look when I can.

@chdemko chdemko commented on an outdated diff Sep 27, 2011
libraries/joomla/database/database.php
// Execute the query and get the result set cursor.
- if (!($cursor = $this->query()))
@chdemko
chdemko added a line comment Sep 27, 2011

You could group the test using (!$this->cursor && !($this->cursor = $this->query())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@chdemko chdemko commented on an outdated diff Sep 27, 2011
libraries/joomla/database/database.php
// Execute the query and get the result set cursor.
- if (!($cursor = $this->query()))
- {
- return $this->errorNum ? null : false;
+ if (!($this->cursor = $this->query()))
@chdemko
chdemko added a line comment Sep 27, 2011

idem as above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@chdemko

It remains an issue in your code:
if this code is executed:
$db->setQuery('select * from jos_content');
var_dump($db->loadNextRow()):
$db->setQuery('select * from jos_categories');
var_dump($db->loadNextRow()):

We will have the 2 first articles while we are looking for the first article and the first category. I think, it lacks a line in setQuery such that
$this->cursor = false;

@brbrbr

for the first row there is $db->loadRow()

$db->query(...);

resets the cursor.

loadNextRow/Object are odd anyhow, since they are the only load* functions not resetting the cursor on every call.

@chdemko

$db->query() reset the cursor, sure, but in my example code, it is only called during the first $db->loadNextRow(), the second one does not call it since $this->cursor is not empty

@brbrbr

Hi

I referred to your example code:

$db->setQuery('select * from jos_content');
var_dump($db->loadNextRow()):
$db->setQuery('select * from jos_categories');
var_dump($db->loadNextRow()):

should be? :

$db->setQuery('select * from jos_content');
var_dump($db->loadRow()):
$db->setQuery('select * from jos_categories');
var_dump($db->loadRow()):

with reset

$db->setQuery('select * from jos_content');
var_dump($db->loadNextRow());
var_dump($db->loadNextRow());
$db->setQuery('select * from jos_categories');
$db->query();
var_dump($db->loadNextRow());

Question is what is the supposed usage of loadNextRow?

I found the problem because I needed a function to walk tru a large result set, avoiding overhead.

for smaller set I would use the limit functin to get n rows.

bram

@jlover

Checkstyle error details:
libraries/joomla/database/database.php:936
Whitespace found at end of line
libraries/joomla/database/database.php:941
Whitespace found at end of line
libraries/joomla/database/database.php:941
Functions and classes must not contain multiple empty lines in a row; found 3 empty lines
libraries/joomla/database/database.php:967
Whitespace found at end of line
libraries/joomla/database/database.php:967
Functions and classes must not contain multiple empty lines in a row; found 3 empty lines
libraries/joomla/database/database.php:969
Whitespace found at end of line
libraries/joomla/database/database.php:974
Whitespace found at end of line
libraries/joomla/database/database.php:974
Functions and classes must not contain multiple empty lines in a row; found 3 empty lines

@joomla-jenkins

Build triggered by changes to the base.

Test log missing. Tests failed to execute.
Checkstyle analysis reported 233 warnings and 4165 errors.

@chdemko

No more input for this?

  • Adding a $this->cursor = false; in setQuery
  • Adding a protected $cursor; in JDatabase

Also it remains checkstyle errors

@joomla-jenkins

Build triggered by changes to the base.

Test log missing. Tests failed to execute.
Checkstyle analysis reported 235 warnings and 8 errors.

@gpongelli

Improved my code with other tests, adding case where there are "query" or "load" calls before loadNextObject and loadNextRow.
They are six tests, check them from here.

@ianmacl

I'm closing this because it has been superseded by [#903].

@ianmacl ianmacl closed this Mar 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment