Commit 3bc748c5 authored by lsmith's avatar lsmith

- s/\$db/\$this->conn

- turned raiseError() calls into throw Exception
- MDB2 style query*() conversion to Doctrine style fetch*()
- removed PEAR::isError() calls
parent b0f3a5d7
...@@ -71,7 +71,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export ...@@ -71,7 +71,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export
if (is_null($start)) { if (is_null($start)) {
$this->conn->beginTransaction(); $this->conn->beginTransaction();
$query = 'SELECT MAX(' . $this->conn->quoteIdentifier($name, true) . ') FROM ' . $this->conn->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->conn->fetchOne($query, 'integer');
++$start; ++$start;
$result = $this->createSequence($table, $start); $result = $this->createSequence($table, $start);
...@@ -110,23 +110,10 @@ class Doctrine_Export_Firebird extends Doctrine_Export ...@@ -110,23 +110,10 @@ class Doctrine_Export_Firebird extends Doctrine_Export
$result = $this->dropSequence($table); $result = $this->dropSequence($table);
/**
if (PEAR::isError($result)) {
return $db->raiseError(null, null, null,
'sequence for autoincrement PK could not be dropped', __FUNCTION__);
}
*/
//remove autoincrement trigger associated with the table //remove autoincrement trigger associated with the table
$table = $this->conn->getDbh()->quote(strtoupper($table)); $table = $this->conn->quote(strtoupper($table));
$trigger_name = $this->conn->getDbh()->quote(strtoupper($table) . '_AUTOINCREMENT_PK'); $trigger_name = $this->conn->quote(strtoupper($table) . '_AUTOINCREMENT_PK');
$result = $this->conn->exec("DELETE FROM RDB\$TRIGGERS WHERE UPPER(RDB\$RELATION_NAME)=$table AND UPPER(RDB\$TRIGGER_NAME)=$trigger_name"); return $this->conn->exec("DELETE FROM RDB\$TRIGGERS WHERE UPPER(RDB\$RELATION_NAME)=$table AND UPPER(RDB\$TRIGGER_NAME)=$trigger_name");
/**
if (PEAR::isError($result)) {
return $db->raiseError(null, null, null,
'trigger for autoincrement PK could not be dropped', __FUNCTION__);
}
*/
} }
/** /**
* create a new table * create a new table
...@@ -190,15 +177,12 @@ class Doctrine_Export_Firebird extends Doctrine_Export ...@@ -190,15 +177,12 @@ class Doctrine_Export_Firebird extends Doctrine_Export
foreach ($changes as $change_name => $change) { foreach ($changes as $change_name => $change) {
switch ($change_name) { switch ($change_name) {
case 'notnull': case 'notnull':
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, throw new Doctrine_DataDict_Firebird_Exception('it is not supported changes to field not null constraint');
'it is not supported changes to field not null constraint', __FUNCTION__);
case 'default': case 'default':
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, throw new Doctrine_DataDict_Firebird_Exception('it is not supported changes to field default value');
'it is not supported changes to field default value', __FUNCTION__);
case 'length': case 'length':
/* /*
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, return throw new Doctrine_DataDict_Firebird_Exception('it is not supported changes to field default length');
'it is not supported changes to field default length', __FUNCTION__);
*/ */
case 'unsigned': case 'unsigned':
case 'type': case 'type':
...@@ -206,11 +190,10 @@ class Doctrine_Export_Firebird extends Doctrine_Export ...@@ -206,11 +190,10 @@ class Doctrine_Export_Firebird extends Doctrine_Export
case 'definition': case 'definition':
break; break;
default: default:
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, throw new Doctrine_DataDict_Firebird_Exception('it is not supported change of type' . $change_name);
'it is not supported change of type' . $change_name, __FUNCTION__);
} }
} }
return MDB2_OK; return true;
} }
/** /**
* drop an existing table * drop an existing table
...@@ -326,18 +309,15 @@ class Doctrine_Export_Firebird extends Doctrine_Export ...@@ -326,18 +309,15 @@ class Doctrine_Export_Firebird extends Doctrine_Export
break; break;
case 'change': case 'change':
foreach ($changes['change'] as $field) { foreach ($changes['change'] as $field) {
if (PEAR::isError($err = $this->checkSupportedChanges($field))) { $this->checkSupportedChanges($field);
return $err;
}
} }
break; break;
default: default:
return $db->raiseError(MDB2_ERROR_CANNOT_ALTER, null, null, throw new Doctrine_DataDict_Firebird_Exception('change type ' . $change_name . ' not yet supported');
'change type ' . $change_name . ' not yet supported', __FUNCTION__);
} }
} }
if ($check) { if ($check) {
return MDB2_OK; return true;
} }
$query = ''; $query = '';
if (!empty($changes['add']) && is_array($changes['add'])) { if (!empty($changes['add']) && is_array($changes['add'])) {
...@@ -345,7 +325,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export ...@@ -345,7 +325,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
} }
$query.= 'ADD ' . $db->getDeclaration($field['type'], $field_name, $field, $name); $query.= 'ADD ' . $this->conn->getDeclaration($field['type'], $field_name, $field, $name);
} }
} }
...@@ -354,7 +334,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export ...@@ -354,7 +334,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
} }
$field_name = $db->quoteIdentifier($field_name, true); $field_name = $this->conn->quoteIdentifier($field_name, true);
$query.= 'DROP ' . $field_name; $query.= 'DROP ' . $field_name;
} }
} }
...@@ -364,32 +344,30 @@ class Doctrine_Export_Firebird extends Doctrine_Export ...@@ -364,32 +344,30 @@ class Doctrine_Export_Firebird extends Doctrine_Export
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
} }
$field_name = $db->quoteIdentifier($field_name, true); $field_name = $this->conn->quoteIdentifier($field_name, true);
$query.= 'ALTER ' . $field_name . ' TO ' . $db->quoteIdentifier($field['name'], true); $query.= 'ALTER ' . $field_name . ' TO ' . $this->conn->quoteIdentifier($field['name'], true);
} }
} }
if (!empty($changes['change']) && is_array($changes['change'])) { if (!empty($changes['change']) && is_array($changes['change'])) {
// missing support to change DEFAULT and NULLability // missing support to change DEFAULT and NULLability
foreach ($changes['change'] as $field_name => $field) { foreach ($changes['change'] as $field_name => $field) {
if (PEAR::isError($err = $this->checkSupportedChanges($field))) { $this->checkSupportedChanges($field);
return $err;
}
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
} }
$db->loadModule('Datatype', null, true); $this->conn->loadModule('Datatype', null, true);
$field_name = $db->quoteIdentifier($field_name, true); $field_name = $this->conn->quoteIdentifier($field_name, true);
$query.= 'ALTER ' . $field_name.' TYPE ' . $db->datatype->getTypeDeclaration($field['definition']); $query.= 'ALTER ' . $field_name.' TYPE ' . $this->conn->datatype->getTypeDeclaration($field['definition']);
} }
} }
if (!strlen($query)) { if (!strlen($query)) {
return MDB2_OK; return false;
} }
$name = $db->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
$result = $db->exec("ALTER TABLE $name $query"); $result = $this->conn->exec("ALTER TABLE $name $query");
$this->_silentCommit(); $this->_silentCommit();
return $result; return $result;
} }
...@@ -529,7 +507,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export ...@@ -529,7 +507,7 @@ class Doctrine_Export_Firebird extends Doctrine_Export
public function dropSequence($seq_name) public function dropSequence($seq_name)
{ {
$sequence_name = $this->conn->getSequenceName($seq_name); $sequence_name = $this->conn->getSequenceName($seq_name);
$sequence_name = $this->conn->getDbh()->quote($sequence_name); $sequence_name = $this->conn->quote($sequence_name);
$query = "DELETE FROM RDB\$GENERATORS WHERE UPPER(RDB\$GENERATOR_NAME)=$sequence_name"; $query = "DELETE FROM RDB\$GENERATORS WHERE UPPER(RDB\$GENERATOR_NAME)=$sequence_name";
return $this->conn->exec($query); return $this->conn->exec($query);
} }
......
...@@ -42,14 +42,14 @@ class Doctrine_Export_Mssql extends Doctrine_Export ...@@ -42,14 +42,14 @@ class Doctrine_Export_Mssql extends Doctrine_Export
*/ */
public function createDatabase($name) public function createDatabase($name)
{ {
$name = $db->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
$query = "CREATE DATABASE $name"; $query = "CREATE DATABASE $name";
if ($db->options['database_device']) { if ($this->conn->options['database_device']) {
$query.= ' ON '.$db->options['database_device']; $query.= ' ON '.$this->conn->options['database_device'];
$query.= $db->options['database_size'] ? '=' . $query.= $this->conn->options['database_size'] ? '=' .
$db->options['database_size'] : ''; $this->conn->options['database_size'] : '';
} }
return $db->standaloneQuery($query, null, true); return $this->conn->standaloneQuery($query, null, true);
} }
/** /**
* drop an existing database * drop an existing database
...@@ -59,8 +59,8 @@ class Doctrine_Export_Mssql extends Doctrine_Export ...@@ -59,8 +59,8 @@ class Doctrine_Export_Mssql extends Doctrine_Export
*/ */
public function dropDatabase($name) public function dropDatabase($name)
{ {
$name = $db->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
return $db->standaloneQuery("DROP DATABASE $name", null, true); return $this->conn->standaloneQuery("DROP DATABASE $name", null, true);
} }
/** /**
* alter an existing table * alter an existing table
...@@ -162,7 +162,7 @@ class Doctrine_Export_Mssql extends Doctrine_Export ...@@ -162,7 +162,7 @@ class Doctrine_Export_Mssql extends Doctrine_Export
case 'rename': case 'rename':
case 'change': case 'change':
default: default:
return $db->raiseError(Doctrine::ERR_CANNOT_ALTER, null, null, return $this->conn->raiseError(Doctrine::ERR_CANNOT_ALTER, null, null,
'alterTable: change type "'.$change_name.'" not yet supported'); 'alterTable: change type "'.$change_name.'" not yet supported');
} }
} }
...@@ -188,7 +188,7 @@ class Doctrine_Export_Mssql extends Doctrine_Export ...@@ -188,7 +188,7 @@ class Doctrine_Export_Mssql extends Doctrine_Export
} }
if (!$query) { if (!$query) {
return MDB2_OK; return false;
} }
$name = $this->conn->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
...@@ -203,29 +203,25 @@ class Doctrine_Export_Mssql extends Doctrine_Export ...@@ -203,29 +203,25 @@ class Doctrine_Export_Mssql extends Doctrine_Export
*/ */
public function createSequence($seq_name, $start = 1) public function createSequence($seq_name, $start = 1)
{ {
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true); $sequence_name = $this->conn->quoteIdentifier($this->conn->getSequenceName($seq_name), true);
$seqcol_name = $db->quoteIdentifier($db->options['seqcol_name'], true); $seqcol_name = $this->conn->quoteIdentifier($this->conn->options['seqcol_name'], true);
$query = "CREATE TABLE $sequence_name ($seqcol_name " . $query = "CREATE TABLE $sequence_name ($seqcol_name " .
"INT PRIMARY KEY CLUSTERED IDENTITY($start,1) NOT NULL)"; "INT PRIMARY KEY CLUSTERED IDENTITY($start,1) NOT NULL)";
$res = $db->exec($query); $res = $this->conn->exec($query);
if ($start == 1) { if ($start == 1) {
return true; return true;
} }
$query = 'SET IDENTITY_INSERT $sequence_name ON ' . try {
'INSERT INTO $sequence_name (' . $seqcol_name . ') VALUES ( ' . $start . ')'; $query = 'SET IDENTITY_INSERT $sequence_name ON ' .
$res = $db->exec($query); 'INSERT INTO $sequence_name (' . $seqcol_name . ') VALUES ( ' . $start . ')';
$res = $this->conn->exec($query);
$result = $db->exec("DROP TABLE $sequence_name"); } catch (Exception $e) {
if (PEAR::isError($result)) { $result = $this->conn->exec("DROP TABLE $sequence_name");
return $db->raiseError($result, null, null,
'createSequence: could not drop inconsistent sequence table');
} }
return true;
return $db->raiseError($res, null, null,
'createSequence: could not create sequence table');
} }
/** /**
* This function drops an existing sequence * This function drops an existing sequence
...@@ -235,7 +231,7 @@ class Doctrine_Export_Mssql extends Doctrine_Export ...@@ -235,7 +231,7 @@ class Doctrine_Export_Mssql extends Doctrine_Export
*/ */
public function dropSequence($seqName) public function dropSequence($seqName)
{ {
$sequenceName = $db->quoteIdentifier($db->getSequenceName($seqName), true); $sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
return $this->conn->exec('DROP TABLE ' . $sequenceName); return $this->conn->exec('DROP TABLE ' . $sequenceName);
} }
} }
...@@ -306,11 +306,11 @@ class Doctrine_Export_Mysql extends Doctrine_Export ...@@ -306,11 +306,11 @@ class Doctrine_Export_Mysql extends Doctrine_Export
} }
if ( ! $query) { if ( ! $query) {
return MDB2_OK; return false;
} }
$name = $this->conn->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
return $this->dbh->query("ALTER TABLE $name $query"); return $this->conn->exec("ALTER TABLE $name $query");
} }
/** /**
* create sequence * create sequence
...@@ -328,7 +328,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export ...@@ -328,7 +328,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
. strlen($this->dbh->options['default_table_type']) ? ' TYPE = ' . strlen($this->dbh->options['default_table_type']) ? ' TYPE = '
. $this->dbh->options['default_table_type'] : ''; . $this->dbh->options['default_table_type'] : '';
$res = $this->dbh->query($query); $res = $this->conn->exec($query);
if ($start == 1) if ($start == 1)
return true; return true;
...@@ -336,11 +336,11 @@ class Doctrine_Export_Mysql extends Doctrine_Export ...@@ -336,11 +336,11 @@ class Doctrine_Export_Mysql extends Doctrine_Export
$query = 'INSERT INTO ' . $sequenceName $query = 'INSERT INTO ' . $sequenceName
. ' (' . $seqcol_name . ') VALUES (' . ($start-1) . ')'; . ' (' . $seqcol_name . ') VALUES (' . ($start-1) . ')';
$res = $this->dbh->query($query); $res = $this->conn->exec($query);
// Handle error // Handle error
try { try {
$result = $this->dbh->query('DROP TABLE ' . $sequenceName); $result = $this->conn->exec('DROP TABLE ' . $sequenceName);
} catch(Exception $e) { } catch(Exception $e) {
throw new Doctrine_Export_Mysql_Exception('could not drop inconsistent sequence table'); throw new Doctrine_Export_Mysql_Exception('could not drop inconsistent sequence table');
} }
......
...@@ -53,19 +53,16 @@ class Doctrine_Export_Oracle extends Doctrine_Export ...@@ -53,19 +53,16 @@ class Doctrine_Export_Oracle extends Doctrine_Export
? ' DEFAULT TABLESPACE '.$this->conn->options['default_tablespace'] : ''; ? ' DEFAULT TABLESPACE '.$this->conn->options['default_tablespace'] : '';
$query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password . $tablespace; $query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password . $tablespace;
$result = $this->conn->query($query); $result = $this->conn->exec($query);
$query = 'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO ' . $username; try {
$result = $this->conn->query($query); $query = 'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO ' . $username;
if (PEAR::isError($result)) { $result = $this->conn->exec($query);
} catch (Exception $e) {
$query = 'DROP USER '.$username.' CASCADE'; $query = 'DROP USER '.$username.' CASCADE';
$result2 = $this->conn->query($query); $result2 = $this->conn->exec($query);
if (PEAR::isError($result2)) {
return $this->conn->raiseError($result2, null, null,
'could not setup the database user', __FUNCTION__);
}
return $result;
} }
return true;
} }
/** /**
* drop an existing database * drop an existing database
...@@ -83,7 +80,7 @@ class Doctrine_Export_Oracle extends Doctrine_Export ...@@ -83,7 +80,7 @@ class Doctrine_Export_Oracle extends Doctrine_Export
$username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name); $username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name);
return $this->conn->query('DROP USER ' . $username . ' CASCADE'); return $this->conn->exec('DROP USER ' . $username . ' CASCADE');
} }
/** /**
* add an autoincrement sequence + trigger * add an autoincrement sequence + trigger
...@@ -104,32 +101,18 @@ class Doctrine_Export_Oracle extends Doctrine_Export ...@@ -104,32 +101,18 @@ class Doctrine_Export_Oracle extends Doctrine_Export
); );
$result = $this->createConstraint($table, $index_name, $definition); $result = $this->createConstraint($table, $index_name, $definition);
/**
if (PEAR::isError($result)) {
return $this->conn->raiseError($result, null, null,
'primary key for autoincrement PK could not be created', __FUNCTION__);
}
*/
if (is_null($start)) { if (is_null($start)) {
$this->conn->beginTransaction(); $this->conn->beginTransaction();
$query = 'SELECT MAX(' . $this->conn->quoteIdentifier($name, true) . ') FROM ' . $this->conn->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->conn->fetchOne($query);
if (PEAR::isError($start)) {
return $start;
}
++$start; ++$start;
$result = $this->createSequence($table, $start); $result = $this->createSequence($table, $start);
$this->conn->commit(); $this->conn->commit();
} else { } else {
$result = $this->createSequence($table, $start); $result = $this->createSequence($table, $start);
} }
/**
if (PEAR::isError($result)) {
return $this->conn->raiseError($result, null, null,
'sequence for autoincrement PK could not be created', __FUNCTION__);
}
*/
$sequence_name = $this->conn->getSequenceName($table); $sequence_name = $this->conn->getSequenceName($table);
$trigger_name = $this->conn->quoteIdentifier($table . '_AI_PK', true); $trigger_name = $this->conn->quoteIdentifier($table . '_AI_PK', true);
$table = $this->conn->quoteIdentifier($table, true); $table = $this->conn->quoteIdentifier($table, true);
...@@ -350,13 +333,12 @@ END; ...@@ -350,13 +333,12 @@ END;
case 'rename': case 'rename':
break; break;
default: default:
return $this->conn->raiseError(MDB2_ERROR_CANNOT_ALTER, null, null, throw new Doctrine_Export_Oracle_Exception('change type "'.$changeName.'" not yet supported');
'change type "'.$changeName.'" not yet supported', __FUNCTION__);
} }
} }
if ($check) { if ($check) {
return MDB2_OK; return false;
} }
$name = $this->conn->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
...@@ -367,9 +349,6 @@ END; ...@@ -367,9 +349,6 @@ END;
$fields[] = $this->conn->getDeclaration($field['type'], $field_name, $field); $fields[] = $this->conn->getDeclaration($field['type'], $field_name, $field);
} }
$result = $this->conn->exec("ALTER TABLE $name ADD (". implode(', ', $fields).')'); $result = $this->conn->exec("ALTER TABLE $name ADD (". implode(', ', $fields).')');
if (PEAR::isError($result)) {
return $result;
}
} }
if (!empty($changes['change']) && is_array($changes['change'])) { if (!empty($changes['change']) && is_array($changes['change'])) {
...@@ -378,9 +357,6 @@ END; ...@@ -378,9 +357,6 @@ END;
$fields[] = $field_name. ' ' . $this->conn->getDeclaration($field['definition']['type'], '', $field['definition']); $fields[] = $field_name. ' ' . $this->conn->getDeclaration($field['definition']['type'], '', $field['definition']);
} }
$result = $this->conn->exec("ALTER TABLE $name MODIFY (". implode(', ', $fields).')'); $result = $this->conn->exec("ALTER TABLE $name MODIFY (". implode(', ', $fields).')');
if (PEAR::isError($result)) {
return $result;
}
} }
if (!empty($changes['rename']) && is_array($changes['rename'])) { if (!empty($changes['rename']) && is_array($changes['rename'])) {
...@@ -388,9 +364,6 @@ END; ...@@ -388,9 +364,6 @@ END;
$field_name = $this->conn->quoteIdentifier($field_name, true); $field_name = $this->conn->quoteIdentifier($field_name, true);
$query = "ALTER TABLE $name RENAME COLUMN $field_name TO ".$this->conn->quoteIdentifier($field['name']); $query = "ALTER TABLE $name RENAME COLUMN $field_name TO ".$this->conn->quoteIdentifier($field['name']);
$result = $this->conn->exec($query); $result = $this->conn->exec($query);
if (PEAR::isError($result)) {
return $result;
}
} }
} }
...@@ -400,17 +373,11 @@ END; ...@@ -400,17 +373,11 @@ END;
$fields[] = $this->conn->quoteIdentifier($field_name, true); $fields[] = $this->conn->quoteIdentifier($field_name, true);
} }
$result = $this->conn->exec("ALTER TABLE $name DROP COLUMN ". implode(', ', $fields)); $result = $this->conn->exec("ALTER TABLE $name DROP COLUMN ". implode(', ', $fields));
if (PEAR::isError($result)) {
return $result;
}
} }
if (!empty($changes['name'])) { if (!empty($changes['name'])) {
$change_name = $this->conn->quoteIdentifier($changes['name'], true); $change_name = $this->conn->quoteIdentifier($changes['name'], true);
$result = $this->conn->exec("ALTER TABLE $name RENAME TO ".$change_name); $result = $this->conn->exec("ALTER TABLE $name RENAME TO ".$change_name);
if (PEAR::isError($result)) {
return $result;
}
} }
} }
/** /**
......
...@@ -167,8 +167,8 @@ class Doctrine_Export_Pgsql extends Doctrine_Export ...@@ -167,8 +167,8 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
if (!empty($changes['add']) && is_array($changes['add'])) { if (!empty($changes['add']) && is_array($changes['add'])) {
foreach ($changes['add'] as $field_name => $field) { foreach ($changes['add'] as $field_name => $field) {
$query = 'ADD ' . $db->getDeclaration($field['type'], $field_name, $field); $query = 'ADD ' . $this->conn->getDeclaration($field['type'], $field_name, $field);
$this->dbh->query("ALTER TABLE $name $query"); $this->conn->exec("ALTER TABLE $name $query");
} }
} }
...@@ -176,7 +176,7 @@ class Doctrine_Export_Pgsql extends Doctrine_Export ...@@ -176,7 +176,7 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
foreach ($changes['remove'] as $field_name => $field) { foreach ($changes['remove'] as $field_name => $field) {
$field_name = $this->conn->quoteIdentifier($field_name, true); $field_name = $this->conn->quoteIdentifier($field_name, true);
$query = 'DROP ' . $field_name; $query = 'DROP ' . $field_name;
$this->dbh->query("ALTER TABLE $name $query"); $this->conn->exec("ALTER TABLE $name $query");
} }
} }
...@@ -184,21 +184,21 @@ class Doctrine_Export_Pgsql extends Doctrine_Export ...@@ -184,21 +184,21 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
foreach ($changes['change'] as $field_name => $field) { foreach ($changes['change'] as $field_name => $field) {
$field_name = $this->conn->quoteIdentifier($field_name, true); $field_name = $this->conn->quoteIdentifier($field_name, true);
if (!empty($field['type'])) { if (!empty($field['type'])) {
$server_info = $db->getServerVersion(); $server_info = $this->conn->getServerVersion();
if (is_array($server_info) && $server_info['major'] < 8) { if (is_array($server_info) && $server_info['major'] < 8) {
throw new Doctrine_Export_Pgsql_Exception('changing column type for "'.$change_name.'\" requires PostgreSQL 8.0 or above'); throw new Doctrine_Export_Pgsql_Exception('changing column type for "'.$change_name.'\" requires PostgreSQL 8.0 or above');
} }
$query = "ALTER $field_name TYPE ".$db->datatype->getTypeDeclaration($field['definition']); $query = "ALTER $field_name TYPE ".$this->conn->datatype->getTypeDeclaration($field['definition']);
$this->dbh->query("ALTER TABLE $name $query"); $this->conn->exec("ALTER TABLE $name $query");
} }
if (array_key_exists('default', $field)) { if (array_key_exists('default', $field)) {
$query = "ALTER $field_name SET DEFAULT ".$db->quote($field['definition']['default'], $field['definition']['type']); $query = "ALTER $field_name SET DEFAULT ".$this->conn->quote($field['definition']['default'], $field['definition']['type']);
$this->dbh->query("ALTER TABLE $name $query"); $this->conn->exec("ALTER TABLE $name $query");
} }
if (!empty($field['notnull'])) { if (!empty($field['notnull'])) {
$query = "ALTER $field_name ".($field['definition']['notnull'] ? "SET" : "DROP").' NOT NULL'; $query = "ALTER $field_name ".($field['definition']['notnull'] ? "SET" : "DROP").' NOT NULL';
$this->dbh->query("ALTER TABLE $name $query"); $this->conn->exec("ALTER TABLE $name $query");
} }
} }
...@@ -207,14 +207,14 @@ class Doctrine_Export_Pgsql extends Doctrine_Export ...@@ -207,14 +207,14 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
if (!empty($changes['rename']) && is_array($changes['rename'])) { if (!empty($changes['rename']) && is_array($changes['rename'])) {
foreach ($changes['rename'] as $field_name => $field) { foreach ($changes['rename'] as $field_name => $field) {
$field_name = $this->conn->quoteIdentifier($field_name, true); $field_name = $this->conn->quoteIdentifier($field_name, true);
$this->dbh->query("ALTER TABLE $name RENAME COLUMN $field_name TO ".$this->conn->quoteIdentifier($field['name'], true)); $this->conn->exec("ALTER TABLE $name RENAME COLUMN $field_name TO ".$this->conn->quoteIdentifier($field['name'], true));
} }
} }
$name = $this->conn->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
if (!empty($changes['name'])) { if (!empty($changes['name'])) {
$change_name = $this->conn->quoteIdentifier($changes['name'], true); $change_name = $this->conn->quoteIdentifier($changes['name'], true);
$this->dbh->query("ALTER TABLE $name RENAME TO ".$change_name); $this->conn->exec("ALTER TABLE $name RENAME TO ".$change_name);
} }
} }
} }
......
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