Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix issue with duplicate prefixes.
Postgres::truncate() was double prefixing
table names.

Fixes #2355
  • Loading branch information
markstory committed Dec 10, 2011
1 parent f367249 commit c3f17c2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/Cake/Model/Datasource/Database/Postgres.php
Expand Up @@ -295,21 +295,20 @@ public function getSequence($table, $field = 'id') {
*
* @param mixed $table A string or model class representing the table to be truncated
* @param boolean $reset true for resetting the sequence, false to leave it as is.
* and if 1, sequences are not modified
* and if 1, sequences are not modified
* @return boolean SQL TRUNCATE TABLE statement, false if not applicable.
*/
public function truncate($table, $reset = 0) {
$table = $this->fullTableName($table, false);
if (!isset($this->_sequenceMap[$table])) {
public function truncate($table, $reset = false) {
$fullTable = $this->fullTableName($table, false);
if (!isset($this->_sequenceMap[$fullTable])) {
$cache = $this->cacheSources;
$this->cacheSources = false;
$this->describe($table);
$this->cacheSources = $cache;
}
if ($this->execute('DELETE FROM ' . $this->fullTableName($table))) {
$table = $this->fullTableName($table, false);
if (isset($this->_sequenceMap[$table]) && $reset !== 1) {
foreach ($this->_sequenceMap[$table] as $field => $sequence) {
if (isset($this->_sequenceMap[$fullTable]) && $reset != true) {
foreach ($this->_sequenceMap[$fullTable] as $field => $sequence) {
$this->_execute("ALTER SEQUENCE \"{$sequence}\" RESTART WITH 1");
}
}
Expand Down

0 comments on commit c3f17c2

Please sign in to comment.