From 894948f175b651c3d5e826f32a7d9ffc6b488478 Mon Sep 17 00:00:00 2001 From: Jeremy Dorn Date: Tue, 22 Mar 2016 19:38:21 -0700 Subject: [PATCH] Fix some adodb bugs - undefined variables, missing debug query, etc. --- classes/headers/VariableHeader.php | 2 +- classes/report_types/AdoPivotReportType.php | 9 ++++----- classes/report_types/AdoReportType.php | 11 +++++++---- config/config.php.sample | 2 ++ sample_reports/ado/names.ado | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/classes/headers/VariableHeader.php b/classes/headers/VariableHeader.php index f37ffaa3..279ab1a4 100644 --- a/classes/headers/VariableHeader.php +++ b/classes/headers/VariableHeader.php @@ -190,7 +190,7 @@ public static function afterParse(&$report) { } //if the type is daterange, parse start and end with strtotime - if($params['type'] === 'daterange' && $report->macros[$params['name']][0] && $report->macros[$params['name']][1]) { + if($params['type'] === 'daterange' && !empty($report->macros[$params['name']][0]) && !empty($report->macros[$params['name']][1])) { $start = date_create($report->macros[$params['name']][0]); if(!$start) throw new Exception($params['display']." must have a valid start date."); date_time_set($start,0,0,0); diff --git a/classes/report_types/AdoPivotReportType.php b/classes/report_types/AdoPivotReportType.php index e6c37375..ed1b4589 100644 --- a/classes/report_types/AdoPivotReportType.php +++ b/classes/report_types/AdoPivotReportType.php @@ -10,6 +10,9 @@ public static function init(&$report) { //make sure the syntax highlighting is using the proper class SqlFormatter::$pre_attributes = "class='prettyprint linenums lang-sql'"; + //set a formatted query here for debugging. It will be overwritten below after macros are substituted. + $report->options['Query_Formatted'] = "
".$report->raw_query."
"; + $object = spyc_load($report->raw_query); $report->raw_query = array(); @@ -25,10 +28,6 @@ public static function init(&$report) { } $report->raw_query[] = $object; - - //set a formatted query here for debugging. It will be overwritten below after macros are substituted. - //We can not set the query here - it's not a query just yet... - //$report->options['Query_Formatted'] = SqlFormatter::format($report->raw_query); } public static function openConnection(&$report) { @@ -38,7 +37,7 @@ public static function openConnection(&$report) { $config = $environments[$report->options['Environment']][$report->options['Database']]; if(!($report->conn = ADONewConnection($config['uri']))) { - throw new Exception('Could not connect to the database: '.$report->conn->ErrorMsg()); + throw new Exception('Could not connect to the database'); } } diff --git a/classes/report_types/AdoReportType.php b/classes/report_types/AdoReportType.php index 544a8cc4..63bfb1f8 100644 --- a/classes/report_types/AdoReportType.php +++ b/classes/report_types/AdoReportType.php @@ -15,8 +15,11 @@ public static function init(&$report) { //replace legacy shorthand macro format foreach($report->macros as $key=>$value) { - $params = $report->options['Variables'][$key]; - + $params = array(); + if(isset($report->options['Variables'][$key])) { + $params = $report->options['Variables'][$key]; + } + //macros shortcuts for arrays if(isset($params['multiple']) && $params['multiple']) { //allow {macro} instead of {% for item in macro %}{% if not item.first %},{% endif %}{{ item.value }}{% endfor %} @@ -55,7 +58,7 @@ public static function openConnection(&$report) { $config = $environments[$report->options['Environment']][$report->options['Database']]; if(!($report->conn = ADONewConnection($config['uri']))) { - throw new Exception('Could not connect to the database: '.$report->conn->ErrorMsg()); + throw new Exception('Could not connect to the database'); } } @@ -153,4 +156,4 @@ public static function run(&$report) { return $result->GetArray(); } -} +} \ No newline at end of file diff --git a/config/config.php.sample b/config/config.php.sample index 4ef5c2fc..1154c1ee 100644 --- a/config/config.php.sample +++ b/config/config.php.sample @@ -21,6 +21,7 @@ return array( 'php'=>'Php', 'js'=>'Mongo', 'ado'=>'Ado', + 'pivot'=>'AdoPivot', ), //this enables listing different types of download formats on the report page @@ -117,3 +118,4 @@ return array( ), ); ?> + diff --git a/sample_reports/ado/names.ado b/sample_reports/ado/names.ado index 543aeec8..6cea50cb 100644 --- a/sample_reports/ado/names.ado +++ b/sample_reports/ado/names.ado @@ -12,7 +12,7 @@ -- database_options: { -- table: "blocked_accounts", -- column: "batch", --- all: "false" +-- all: false -- } -- }