Permalink
Browse files

MINOR: cached fieldlist array can now be cleared

  • Loading branch information...
1 parent 2bd6e9f commit 717f40af9e42a016274c1881a0947c15801c869d @geoff-silverstripe geoff-silverstripe committed Jan 12, 2011
Showing with 28 additions and 2 deletions.
  1. +28 −2 code/PostgreSQLDatabase.php
@@ -698,7 +698,7 @@ private function alterTableAlterColumn($tableName, $colName, $colSpec){
DB::query($updateConstraint);
}
-
+
//First, delete any existing constraint on this column, even if it's no longer an enum
if($existing_constraint)
$alterCol .= ",\nDROP CONSTRAINT \"{$tableName}_{$colName}_check\"";
@@ -713,6 +713,7 @@ private function alterTableAlterColumn($tableName, $colName, $colSpec){
public function renameTable($oldTableName, $newTableName) {
$this->query("ALTER TABLE \"$oldTableName\" RENAME TO \"$newTableName\"");
+ unset(self::$cached_fieldlists[$oldTableName]);
}
/**
@@ -721,6 +722,7 @@ public function renameTable($oldTableName, $newTableName) {
* @return boolean Return true if the table has integrity after the method is complete.
*/
public function checkAndRepairTable($tableName) {
+
$this->runTableCheckCommand("VACUUM FULL ANALYZE \"$tableName\"");
$this->runTableCheckCommand("REINDEX TABLE \"$tableName\"");
return true;
@@ -753,14 +755,18 @@ public function alterField($tableName, $fieldName, $fieldSpec) {
/**
* 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 $newName The new name of the field
*/
public function renameField($tableName, $oldName, $newName) {
$fieldList = $this->fieldList($tableName);
if(array_key_exists($oldName, $fieldList)) {
$this->query("ALTER TABLE \"$tableName\" RENAME COLUMN \"$oldName\" TO \"$newName\"");
+
+ //Remove this from the cached list:
+ unset(self::$cached_fieldlists[$tableName]);
+
}
}
@@ -852,10 +858,29 @@ public function fieldList($table) {
self::$cached_fieldlists[$table]=$output;
}
+
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.
* @param string $tableName The name of the table.
* @param string $indexName The name of the index.
@@ -1756,6 +1781,7 @@ public function transactionRollback($savepoint=false){
DB::query("ROLLBACK TO $savepoint;");
else
DB::query('ROLLBACK;');
+
}
/*

0 comments on commit 717f40a

Please sign in to comment.