Jump to content

Community

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


Makoto
 Share

Go to solution Solved by Makoto,

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.

DbEmptyFilter.patch

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

Edited by Makoto
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:

<?php

require 'init.php';
\IPS\Dispatcher\External::i();

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

foreach( $iterator as $row )
{
	var_dump($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

  • Solution

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

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We use technologies, such as cookies, to customise content and advertising, to provide social media features and to analyse traffic to the site. We also share information about your use of our site with our trusted social media, advertising and analytics partners. See more about cookies and our Privacy Policy