Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 7: allow different styles of identifier quoting for oracle #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/handlers/oracle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -78,6 +85,9 @@ public function __construct( $dbParams )
}

parent::__construct( $dbParams, $dsn );

// setup options
$this->setOptions( new ezcDbOracleOptions() );
}

/**
Expand All @@ -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.
*
Expand Down Expand Up @@ -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 );
}
}
?>
95 changes: 95 additions & 0 deletions src/options/oracle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* File containing the ezcDbOracleOption class
*
* @package Database
* @version //autogentag//
* @copyright Copyright (C) 2013 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
* Class containing the options for MS SQL Server connections
*
* @property int $quoteIdentifier
* Mode of quoting identifiers.
*
* @package Database
* @version //autogentag//
*/
class ezcDbOracleOptions extends ezcBaseOptions
{
/**
* Constant represents mode of identifiers quoting that
* always quotes all identifiers (default).
*
* @access public
*/
const QUOTES_COMPLIANT = 0;

/**
* Constant represents mode of identifiers quoting that
* quotes only identifiers which need it according to SQL92 spec
*
* @access public
*/
const QUOTES_GUESS = 1;


/**
* Constant represents mode of identifiers quoting that does nothing.
* Can be used for optimization.
*
* @access public
*/
const QUOTES_UNTOUCHED = 2;


/**
* Creates an ezcDbMssqlOptions object with default option values.
*
* @param array $options
*/
public function __construct( array $options = array() )
{
$this->quoteIdentifier = self::QUOTES_COMPLIANT;

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;
}
}
}

?>