Skip to content

Commit

Permalink
Fix some adodb bugs - undefined variables, missing debug query, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdorn committed Mar 23, 2016
1 parent 071f5f9 commit 894948f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion classes/headers/VariableHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions classes/report_types/AdoPivotReportType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = "<pre class='prettyprint linenums lang-yaml'>".$report->raw_query."</pre>";

$object = spyc_load($report->raw_query);

$report->raw_query = array();
Expand All @@ -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) {
Expand All @@ -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');
}
}

Expand Down
11 changes: 7 additions & 4 deletions classes/report_types/AdoReportType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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');
}
}

Expand Down Expand Up @@ -153,4 +156,4 @@ public static function run(&$report) {

return $result->GetArray();
}
}
}
2 changes: 2 additions & 0 deletions config/config.php.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -117,3 +118,4 @@ return array(
),
);
?>

2 changes: 1 addition & 1 deletion sample_reports/ado/names.ado
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-- database_options: {
-- table: "blocked_accounts",
-- column: "batch",
-- all: "false"
-- all: false
-- }
-- }

Expand Down

0 comments on commit 894948f

Please sign in to comment.