From 37641d5d34028c595f27e74b3c6280cb93064131 Mon Sep 17 00:00:00 2001 From: gggeek Date: Thu, 17 Oct 2013 15:27:31 +0200 Subject: [PATCH 1/2] Fix issue 7: allow different styles of identifier quoting for oracle --- src/handlers/oracle.php | 38 +++++++++++++++++ src/options/oracle.php | 95 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 src/options/oracle.php diff --git a/src/handlers/oracle.php b/src/handlers/oracle.php index 80de924..bd92649 100644 --- a/src/handlers/oracle.php +++ b/src/handlers/oracle.php @@ -34,6 +34,13 @@ class ezcDbHandlerOracle extends ezcDbHandler { + /** + * Contains the options that are used to set up handler. + * + * @var ezcDbOracleOptions + */ + public $options; + /** * Constructs a handler object from the parameters $dbParams. * @@ -78,6 +85,9 @@ public function __construct( $dbParams ) } parent::__construct( $dbParams, $dsn ); + + // setup options + $this->setOptions( new ezcDbOracleOptions() ); } /** @@ -90,6 +100,17 @@ static public function getName() return 'oracle'; } + /** + * Associates an option object with this handler and changes settings for + * opened connections. + * + * @param ezcDbMssqlOptions $options + */ + public function setOptions( ezcDbOracleOptions $options ) + { + $this->options = $options; + } + /** * Returns a new ezcQuerySelect derived object with Oracle implementation specifics. * @@ -167,5 +188,22 @@ public function quote( $str, $paramStr = PDO::PARAM_STR ) $str = str_replace( "'", "''", $str ); return "'$str'"; } + + /** + * @see ezcDBHandler::quoteIdentifier + */ + public function quoteIdentifier( $identifier ) + { + $requiredMode = $this->options->quoteIdentifier; + if ( $requiredMode == ezcDbOracleOptions::QUOTES_UNTOUCHED ) + { + return $identifier; + } + if ( $requiredMode == ezcDbOracleOptions::QUOTES_GUESS && preg_match( '/^[[:alpha:]][[:alnum:]_]*$/', $identifier ) ) + { + return $identifier; + } + return parent::quoteIdentifier( $identifier ); + } } ?> diff --git a/src/options/oracle.php b/src/options/oracle.php new file mode 100644 index 0000000..980095a --- /dev/null +++ b/src/options/oracle.php @@ -0,0 +1,95 @@ +quoteIdentifier = self::QUOTES_UNTOUCHED; + + parent::__construct( $options ); + } + + /** + * Set an option value + * + * @param string $propertyName + * @param mixed $propertyValue + * @throws ezcBasePropertyNotFoundException + * If a property is not defined in this class + * @throws ezcBaseValueException + * If a property is out of range + * @ignore + */ + public function __set( $propertyName, $propertyValue ) + { + switch ( $propertyName ) + { + case 'quoteIdentifier': + if ( !is_numeric( $propertyValue ) || + ( ( $propertyValue != self::QUOTES_COMPLIANT ) && + ( $propertyValue != self::QUOTES_GUESS ) && + ( $propertyValue != self::QUOTES_UNTOUCHED ) + ) + ) + { + throw new ezcBaseValueException( $propertyName, $propertyValue, + 'one of ezcDbOracleOptions::QUOTES_COMPLIANT, QUOTES_GUESS, QUOTES_UNTOUCHED constants' ); + } + + $this->quoteIdentifier = (int) $propertyValue; + break; + default: + throw new ezcBasePropertyNotFoundException( $propertyName ); + break; + } + } +} + +?> From 1eea972190d5752c233fe17fa2ca5dfde5ac9e0e Mon Sep 17 00:00:00 2001 From: gggeek Date: Thu, 17 Oct 2013 15:33:43 +0200 Subject: [PATCH 2/2] For best backwards compatibility, set default quoting style to on --- src/options/oracle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/options/oracle.php b/src/options/oracle.php index 980095a..18b74be 100644 --- a/src/options/oracle.php +++ b/src/options/oracle.php @@ -51,7 +51,7 @@ class ezcDbOracleOptions extends ezcBaseOptions */ public function __construct( array $options = array() ) { - $this->quoteIdentifier = self::QUOTES_UNTOUCHED; + $this->quoteIdentifier = self::QUOTES_COMPLIANT; parent::__construct( $options ); }