Skip to content

Commit

Permalink
MINOR: cached fieldlist array can now be cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-silverstripe committed Jan 12, 2011
1 parent 2bd6e9f commit 717f40a
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions code/PostgreSQLDatabase.php
Expand Up @@ -698,7 +698,7 @@ private function alterTableAlterColumn($tableName, $colName, $colSpec){


DB::query($updateConstraint); DB::query($updateConstraint);
} }

//First, delete any existing constraint on this column, even if it's no longer an enum //First, delete any existing constraint on this column, even if it's no longer an enum
if($existing_constraint) if($existing_constraint)
$alterCol .= ",\nDROP CONSTRAINT \"{$tableName}_{$colName}_check\""; $alterCol .= ",\nDROP CONSTRAINT \"{$tableName}_{$colName}_check\"";
Expand All @@ -713,6 +713,7 @@ private function alterTableAlterColumn($tableName, $colName, $colSpec){


public function renameTable($oldTableName, $newTableName) { public function renameTable($oldTableName, $newTableName) {
$this->query("ALTER TABLE \"$oldTableName\" RENAME TO \"$newTableName\""); $this->query("ALTER TABLE \"$oldTableName\" RENAME TO \"$newTableName\"");
unset(self::$cached_fieldlists[$oldTableName]);
} }


/** /**
Expand All @@ -721,6 +722,7 @@ public function renameTable($oldTableName, $newTableName) {
* @return boolean Return true if the table has integrity after the method is complete. * @return boolean Return true if the table has integrity after the method is complete.
*/ */
public function checkAndRepairTable($tableName) { public function checkAndRepairTable($tableName) {

$this->runTableCheckCommand("VACUUM FULL ANALYZE \"$tableName\""); $this->runTableCheckCommand("VACUUM FULL ANALYZE \"$tableName\"");
$this->runTableCheckCommand("REINDEX TABLE \"$tableName\""); $this->runTableCheckCommand("REINDEX TABLE \"$tableName\"");
return true; return true;
Expand Down Expand Up @@ -753,14 +755,18 @@ public function alterField($tableName, $fieldName, $fieldSpec) {
/** /**
* Change the database column name of the given field. * Change the database column name of the given field.
* *
* @param string $tableName The name of the tbale the field is in. * @param string $tableName The name of the table the field is in.
* @param string $oldName The name of the field to change. * @param string $oldName The name of the field to change.
* @param string $newName The new name of the field * @param string $newName The new name of the field
*/ */
public function renameField($tableName, $oldName, $newName) { public function renameField($tableName, $oldName, $newName) {
$fieldList = $this->fieldList($tableName); $fieldList = $this->fieldList($tableName);
if(array_key_exists($oldName, $fieldList)) { if(array_key_exists($oldName, $fieldList)) {
$this->query("ALTER TABLE \"$tableName\" RENAME COLUMN \"$oldName\" TO \"$newName\""); $this->query("ALTER TABLE \"$tableName\" RENAME COLUMN \"$oldName\" TO \"$newName\"");

//Remove this from the cached list:
unset(self::$cached_fieldlists[$tableName]);

} }
} }


Expand Down Expand Up @@ -852,9 +858,28 @@ public function fieldList($table) {


self::$cached_fieldlists[$table]=$output; self::$cached_fieldlists[$table]=$output;
} }

return self::$cached_fieldlists[$table]; return self::$cached_fieldlists[$table];
} }


/**
*
* This allows the cached values for a table's field list to be erased.
* If $tablename is empty, then the whole cache is erased.
*
* @param string $tableName
*
* @return boolean
*/
function clear_cached_fieldlist($tableName=false){
if($tableName!=false){
unset(self::$cached_fieldlists[$tableName]);
} else
self::$cached_fieldlists=array();

return true;
}

/** /**
* Create an index on a table. * Create an index on a table.
* @param string $tableName The name of the table. * @param string $tableName The name of the table.
Expand Down Expand Up @@ -1756,6 +1781,7 @@ public function transactionRollback($savepoint=false){
DB::query("ROLLBACK TO $savepoint;"); DB::query("ROLLBACK TO $savepoint;");
else else
DB::query('ROLLBACK;'); DB::query('ROLLBACK;');

} }


/* /*
Expand Down

0 comments on commit 717f40a

Please sign in to comment.