Commit 8d8b66eb authored by zYne's avatar zYne

porting features from MDB2

parent 365bdc23
...@@ -198,9 +198,15 @@ class Doctrine_Export extends Doctrine_Connection_Module ...@@ -198,9 +198,15 @@ class Doctrine_Export extends Doctrine_Connection_Module
* *
* @param string $seqName name of the sequence to be created * @param string $seqName name of the sequence to be created
* @param string $start start value of the sequence; default is 1 * @param string $start start value of the sequence; default is 1
* @param array $options An associative array of table options:
* array(
* 'comment' => 'Foo',
* 'charset' => 'utf8',
* 'collate' => 'utf8_unicode_ci',
* );
* @return string * @return string
*/ */
public function createSequenceSql($seqName, $start = 1) public function createSequenceSql($seqName, $start = 1, array $options = array())
{ {
throw new Doctrine_Export_Exception('Create sequence not supported by this driver.'); throw new Doctrine_Export_Exception('Create sequence not supported by this driver.');
} }
...@@ -680,42 +686,54 @@ class Doctrine_Export extends Doctrine_Connection_Module ...@@ -680,42 +686,54 @@ class Doctrine_Export extends Doctrine_Connection_Module
public function getForeignKeyDeclaration(array $definition) public function getForeignKeyDeclaration(array $definition)
{ {
$sql = $this->getForeignKeyBaseDeclaration($definition); $sql = $this->getForeignKeyBaseDeclaration($definition);
$sql .= $this->getForeignKeyAdvancedOptions($definition);
if (isset($definition['deferred'])) { return $sql;
$sql .= ' ' . $this->getForeignKeyDeferredDeclaration();
} }
/**
$a = array('onUpdate', 'onDelete'); * getAdvancedForeignKeyOptions
foreach($a as $v) { * Return the FOREIGN KEY query section dealing with non-standard options
$keyword = ($v == 'onUpdate') ? ' ON UPDATE ' : ' ON DELETE '; * as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
*
if (isset($definition[$v])) { * @param array $definition foreign key definition
$upper = strtoupper($definition[$v]); * @return string
*/
public function getAdvancedForeignKeyOptions($definition)
{
$query = '';
if ( ! empty($definition['onUpdate'])) {
$query .= ' ON UPDATE ' . $this->getForeignKeyRefentialAction($definition['onUpdate']);
}
if ( ! empty($definition['onDelete'])) {
$query .= ' ON DELETE ' . $this->getForeignKeyRefentialAction($definition['onDelete']);
}
return $query;
}
/**
* getForeignKeyReferentialAction
*
* returns given referential action in uppercase if valid, otherwise throws
* an exception
*
* @throws Doctrine_Exception_Exception if unknown referential action given
* @param string $action foreign key referential action
* @param string foreign key referential action in uppercase
*/
public function getForeignKeyReferentialAction($action)
{
$upper = strtoupper($action);
switch ($upper) { switch ($upper) {
case 'CASCADE': case 'CASCADE':
case 'SET NULL': case 'SET NULL':
case 'NO ACTION': case 'NO ACTION':
case 'RESTRICT': case 'RESTRICT':
case 'SET DEFAULT': case 'SET DEFAULT':
$sql .= $keyword . $upper; return $upper;
break; break;
default: default:
throw new Doctrine_Export_Exception('Unknown foreign key referential action \'' . $upper . '\' given.'); throw new Doctrine_Export_Exception('Unknown foreign key referential action \'' . $upper . '\' given.');
} }
} }
}
return $sql;
}
/**
* getForeignKeyDeferredDeclaration
*
* @return string
*/
public function getForeignKeyDeferredDeclaration($deferred)
{
return '';
}
/** /**
* getForeignKeyBaseDeclaration * getForeignKeyBaseDeclaration
* Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint * Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment