Jump to content

\IPS\Helpers\Table\Db and filters with zero results


Recommended Posts

There's an issue with the Db table helper where if your table has filters that can return zero results, it will return an error on ajax requests due to an underflow exception and does not change the table results at all (while the correct behavior is to indicate there are no results).

I attached a patch that resolves this issue by running a try/catch statement before iterating over the select results.


Let me know if you need me to elaborate on the issue/fix.

Link to comment
Share on other sites

I don't understand your patch. Calling foreach against an iterator that has no results should never result in an UnderflowException (that occurs when calling ->first() against a select object with no results). I set up this example script to test and did not get any UnderflowException thrown:


require 'init.php';

$iterator = \IPS\Db::i()->select( '*', 'core_members', array( 'member_id > ?', 999999 ) );

foreach( $iterator as $row )

die( "No exception" );


Is there a way to test the issue you ran into in the core software? I mean, I regularly adjust filters and end up with no results in table helper instances, so I'm not clear on why you'd be seeing anything different.

Link to comment
Share on other sites

My bad, this is why I shouldn't report bugs after 24 hours with no sleep.

It was a third-party issue. Wasn't the foreach throwing the exception, was a call to first() in a custom table helper class I was working on that I.. just happened to fix at the same time, so I thought that was the issue. Should have tested further.

Sorry for wasting your time >_>

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...