1
0
mirror of synced 2024-12-13 14:56:01 +03:00

Fixed some small bugs

This commit is contained in:
zYne 2006-11-28 23:45:57 +00:00
parent 2241453570
commit c502c512aa

View File

@ -65,34 +65,34 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
*/ */
public function _makeAutoincrement($name, $table, $start = null) { public function _makeAutoincrement($name, $table, $start = null) {
if (is_null($start)) { if (is_null($start)) {
$db->beginTransaction(); $this->conn->beginTransaction();
$query = 'SELECT MAX(' . $db->quoteIdentifier($name, true) . ') FROM ' . $db->quoteIdentifier($table, true); $query = 'SELECT MAX(' . $this->conn->quoteIdentifier($name, true) . ') FROM ' . $this->conn->quoteIdentifier($table, true);
$start = $this->db->queryOne($query, 'integer'); $start = $this->db->queryOne($query, 'integer');
if (PEAR::isError($start)) {
return $start;
}
++$start; ++$start;
$result = $db->manager->createSequence($table, $start); $result = $this->createSequence($table, $start);
$db->commit(); $this->conn->commit();
} else { } else {
$result = $db->manager->createSequence($table, $start); $result = $this->createSequence($table, $start);
} }
$sequence_name = $db->getSequenceName($table); $sequence_name = $this->conn->getSequenceName($table);
$trigger_name = $db->quoteIdentifier($table . '_AUTOINCREMENT_PK', true); $trigger_name = $this->conn->quoteIdentifier($table . '_AUTOINCREMENT_PK', true);
$table = $db->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
$trigger_sql = 'CREATE TRIGGER ' . $trigger_name . ' FOR ' . $table . ' $triggerSql = 'CREATE TRIGGER ' . $trigger_name . ' FOR ' . $table . '
ACTIVE BEFORE INSERT POSITION 0 ACTIVE BEFORE INSERT POSITION 0
AS AS
BEGIN BEGIN
IF (NEW.' . $name . ' IS NULL OR NEW.' . $name . ' = 0) THEN IF (NEW.' . $name . ' IS NULL OR NEW.' . $name . ' = 0) THEN
NEW.' . $name . ' = GEN_ID('.$sequence_name.', 1); NEW.' . $name . ' = GEN_ID('.$sequence_name.', 1);
END'; END';
$result = $db->exec($trigger_sql); $result = $this->conn->getDbh()->exec($triggerSql);
$this->_silentCommit();
// TODO ? $this->_silentCommit();
return $result; return $result;
} }
/** /**
@ -157,7 +157,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
public function createTable($name, $fields, $options = array()) { public function createTable($name, $fields, $options = array()) {
parent::createTable($name, $fields, $options); parent::createTable($name, $fields, $options);
$this->_silentCommit(); // TODO ? $this->_silentCommit();
foreach($fields as $field_name => $field) { foreach($fields as $field_name => $field) {
if( ! empty($field['autoincrement'])) { if( ! empty($field['autoincrement'])) {
//create PK constraint //create PK constraint
@ -181,11 +181,6 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* @return void * @return void
*/ */
public function checkSupportedChanges(&$changes) { public function checkSupportedChanges(&$changes) {
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
foreach ($changes as $change_name => $change) { foreach ($changes as $change_name => $change) {
switch ($change_name) { switch ($change_name) {
case 'notnull': case 'notnull':
@ -472,10 +467,10 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
* @return void * @return void
*/ */
public function createConstraint($table, $name, $definition) { public function createConstraint($table, $name, $definition) {
$table = $db->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
if (!empty($name)) { if (!empty($name)) {
$name = $db->quoteIdentifier($db->getIndexName($name), true); $name = $this->conn->quoteIdentifier($this->conn->getIndexName($name), true);
} }
$query = "ALTER TABLE $table ADD"; $query = "ALTER TABLE $table ADD";
if (!empty($definition['primary'])) { if (!empty($definition['primary'])) {
@ -491,32 +486,28 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
} }
$fields = array(); $fields = array();
foreach (array_keys($definition['fields']) as $field) { foreach (array_keys($definition['fields']) as $field) {
$fields[] = $db->quoteIdentifier($field, true); $fields[] = $this->conn->quoteIdentifier($field, true);
} }
$query .= ' ('. implode(', ', $fields) . ')'; $query .= ' ('. implode(', ', $fields) . ')';
$result = $db->exec($query); $result = $this->conn->getDbh()->exec($query);
$this->_silentCommit(); // TODO ? $this->_silentCommit();
return $result; return $result;
} }
/** /**
* create sequence * create sequence
* *
* @param string $seq_name 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
* @return void * @return void
*/ */
public function createSequence($seq_name, $start = 1) { public function createSequence($seqName, $start = 1) {
$sequence_name = $db->getSequenceName($seq_name); $sequenceName = $this->conn->getSequenceName($seqName);
if (PEAR::isError($result = $db->exec('CREATE GENERATOR '.$sequence_name))) {
return $result; $this->conn->getDbh()->exec('CREATE GENERATOR ' . $sequenceName);
}
if (PEAR::isError($result = $db->exec('SET GENERATOR '.$sequence_name.' TO '.($start-1)))) { $this->conn->getDbh()->exec('SET GENERATOR ' . $sequenceName . ' TO ' . ($start-1));
if (PEAR::isError($err = $db->dropSequence($seq_name))) {
return $db->raiseError($result, null, null, $this->dropSequence($seqName);
'Could not setup sequence start value and then it was not possible to drop it', __FUNCTION__);
}
}
return $result;
} }
/** /**
* drop existing sequence * drop existing sequence