From 6ce6a396cf4f13a290778cef5f6455c21a8d4c10 Mon Sep 17 00:00:00 2001 From: Steve Gallo Date: Tue, 31 Jan 2017 13:52:03 -0500 Subject: [PATCH] Allow comments in queries to contain characters after # --- classes/ETL/DbEntity/Column.php | 2 +- classes/ETL/DbEntity/Join.php | 2 +- classes/ETL/DbEntity/Query.php | 2 +- classes/ETL/DbEntity/Trigger.php | 18 +++++++++--------- classes/ETL/DbEntity/aNamedEntity.php | 17 +++++++++++++++++ 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/classes/ETL/DbEntity/Column.php b/classes/ETL/DbEntity/Column.php index 4d61ab8870..a4607fc61e 100644 --- a/classes/ETL/DbEntity/Column.php +++ b/classes/ETL/DbEntity/Column.php @@ -70,7 +70,7 @@ protected function initialize(stdClass $config, $force = false) } foreach ( $config as $property => $value ) { - if ( '#' == $property ) { + if ( $this->isComment($property) ) { continue; } diff --git a/classes/ETL/DbEntity/Join.php b/classes/ETL/DbEntity/Join.php index 7cd397ca15..ad0c874ac8 100644 --- a/classes/ETL/DbEntity/Join.php +++ b/classes/ETL/DbEntity/Join.php @@ -63,7 +63,7 @@ protected function initialize(stdClass $config, $force = false) } foreach ( $config as $property => $value ) { - if ( '#' == $property ) { + if ( $this->isComment($property) ) { continue; } diff --git a/classes/ETL/DbEntity/Query.php b/classes/ETL/DbEntity/Query.php index bbef3f64bf..141e38a7b8 100644 --- a/classes/ETL/DbEntity/Query.php +++ b/classes/ETL/DbEntity/Query.php @@ -745,7 +745,7 @@ public function getSelectSql($includeSchema = true) $columnList = array(); $thisObj = $this; foreach ( $this->records as $columnName => $formula ) { - if ( "#" == $columnName ) { + if ( $this->isComment($columnName) ) { continue; } diff --git a/classes/ETL/DbEntity/Trigger.php b/classes/ETL/DbEntity/Trigger.php index 2460793ad3..d220829b3b 100644 --- a/classes/ETL/DbEntity/Trigger.php +++ b/classes/ETL/DbEntity/Trigger.php @@ -43,7 +43,7 @@ class Trigger extends aNamedEntity public function __construct($config, $systemQuoteChar = null, Log $logger = null) { parent::__construct($systemQuoteChar, $logger); - + if ( ! is_object($config) ) { $msg = __CLASS__ . ": Argument is not an object"; $this->logAndThrowException($msg); @@ -68,7 +68,7 @@ protected function initialize(stdClass $config, $force = false) } foreach ( $config as $property => $value ) { - if ( '#' == $property ) { + if ( $this->isComment($property) ) { continue; } @@ -78,13 +78,13 @@ protected function initialize(stdClass $config, $force = false) } $this->$property = $value; - + } // foreach ( $config as $property => $value ) $this->initialized = true; } // initialize() - + /* ------------------------------------------------------------------------------------------ * @return The time that the trigger will fire, null if not specified * ------------------------------------------------------------------------------------------ @@ -94,7 +94,7 @@ public function getTime() { return $this->time; } // getTime() - + /* ------------------------------------------------------------------------------------------ * @return The trigger event, null if not specified * ------------------------------------------------------------------------------------------ @@ -104,7 +104,7 @@ public function getEvent() { return $this->event; } // getEvent() - + /* ------------------------------------------------------------------------------------------ * @return The table that the trigger is associated with, null if not specified * ------------------------------------------------------------------------------------------ @@ -114,7 +114,7 @@ public function getTable() { return $this->table; } // getTable() - + /* ------------------------------------------------------------------------------------------ * @return The trigger body, null if not specified * ------------------------------------------------------------------------------------------ @@ -124,7 +124,7 @@ public function getBody() { return $this->body; } // getBody() - + /* ------------------------------------------------------------------------------------------ * @return The trigger definer, null if not specified * ------------------------------------------------------------------------------------------ @@ -134,7 +134,7 @@ public function getDefiner() { return $this->definer; } // getDefiner() - + /* ------------------------------------------------------------------------------------------ * @see iTableItem::compare() * ------------------------------------------------------------------------------------------ diff --git a/classes/ETL/DbEntity/aNamedEntity.php b/classes/ETL/DbEntity/aNamedEntity.php index 7407af3ef7..98d5ce8dc2 100644 --- a/classes/ETL/DbEntity/aNamedEntity.php +++ b/classes/ETL/DbEntity/aNamedEntity.php @@ -27,6 +27,9 @@ abstract class aNamedEntity extends aEtlObject protected $systemQuoteChar = '`'; + // Keys starting with this character are considered comments + const COMMENT_KEY = "#"; + /* ------------------------------------------------------------------------------------------ * Construct a database entity object from a JSON definition file or a definition object. * @@ -159,4 +162,18 @@ public function quote($identifier) return $this->systemQuoteChar . $identifier . $this->systemQuoteChar; } // quote() + /* ------------------------------------------------------------------------------------------ + * Identify commented out keys in JSON definition/specification files. + * + * @param $key The string to examine + * + * @return TRUE if the key is considered a comment, FALSE otherwise. + * ------------------------------------------------------------------------------------------ + */ + + protected function isComment($key) + { + return ( 0 === strpos($key, self::COMMENT_KEY) ); + } // isComment() + } // abstract class aNamedEntity