KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Catch Query Exception #1607

Open Mike Carroll opened this topic on on Aug 31, 2020 - 1 comments

Mike Carroll commented on Aug 31, 2020

For various reasons, a query can be invalid causing the whole application to die. Is there a way to catch the exception so this does not occur?

ore/src/datasources/PdoDataSource.php on line 432

KoolReport commented on Sep 1, 2020

Your question is very interesting. Normally the SQL will be executes when the report is run. So we use try catch in around the run() method:

$report = new MyReport;
try {
    $report->run();
} catch(\Exception $e) {

}
$report->render();

However, if you are using SQL query directly into widget at view, it seems a little more to perform try catch:

$store = $this->src("db")->query("SELECT ... ")->pipe(new \koolreport\core\DataStore);
try {
    $store->requestDataSending();
} catch (\Exception $e)
{

}
ColumnChart::create(array(
    "dataSource"=>$store,
    ...
));

Actually you can create a method to handle all try catch like this in the main class

class MyReport extends \koolreport\KoolReport
{
    protected function performSQL($sql) {
        $store = $this->src("db")->query(sql)->pipe(new \koolreport\core\DataStore);
        try {
            $store->requestDataSending();
        } catch (\Exception $e)
        {

        }
        return $store;
    }
}

and then in any widget, you can do:

ColumnChart::create(array(
    "dataSource"=>$this->performSQL("SELECT .... ");
));

Hope my answer helps.

Your question give us an ideas for centralized error handler, I will mark your post as suggestion and forward this topic to our dev.team.

Thank you very much.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
suggestion

None