Refactoring DboPostgres and adding '.' to sequence name detection, fixes #5424, fixing code formatting

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7620 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-09-18 00:23:17 +00:00
parent fd73cf738a
commit 66240f0c5d
2 changed files with 40 additions and 47 deletions

View file

@ -974,7 +974,9 @@ class Controller extends Object {
if (isset($defaults[0])) { if (isset($defaults[0])) {
$type = array_shift($defaults); $type = array_shift($defaults);
} }
$extra = array_diff_key($defaults, compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive')); $extra = array_diff_key($defaults, compact(
'conditions', 'fields', 'order', 'limit', 'page', 'recursive'
));
if (method_exists($object, 'paginateCount')) { if (method_exists($object, 'paginateCount')) {
$count = $object->paginateCount($conditions, $recursive); $count = $object->paginateCount($conditions, $recursive);

View file

@ -222,7 +222,11 @@ class DboPostgres extends DboSource {
$fields[$c['name']] = array( $fields[$c['name']] = array(
'type' => $this->column($c['type']), 'type' => $this->column($c['type']),
'null' => ($c['null'] == 'NO' ? false : true), 'null' => ($c['null'] == 'NO' ? false : true),
'default' => preg_replace("/^'(.*)'$/", "$1", preg_replace('/::.*/', '', $c['default'])), 'default' => preg_replace(
"/^'(.*)'$/",
"$1",
preg_replace('/::.*/', '', $c['default'])
),
'length' => $length 'length' => $length
); );
if ($c['name'] == $model->primaryKey) { if ($c['name'] == $model->primaryKey) {
@ -231,7 +235,10 @@ class DboPostgres extends DboSource {
$fields[$c['name']]['length'] = 11; $fields[$c['name']]['length'] = 11;
} }
} }
if ($fields[$c['name']]['default'] == 'NULL' || preg_match('/nextval\([\'"]?(\w+)/', $c['default'], $seq)) { if (
$fields[$c['name']]['default'] == 'NULL' ||
preg_match('/nextval\([\'"]?([\w.]+)/', $c['default'], $seq)
) {
$fields[$c['name']]['default'] = null; $fields[$c['name']]['default'] = null;
if (!empty($seq) && isset($seq[1])) { if (!empty($seq) && isset($seq[1])) {
$this->_sequenceMap[$table][$c['name']] = $seq[1]; $this->_sequenceMap[$table][$c['name']] = $seq[1];
@ -300,10 +307,7 @@ class DboPostgres extends DboSource {
*/ */
function lastError() { function lastError() {
$error = pg_last_error($this->connection); $error = pg_last_error($this->connection);
if ($error) { return ($error) ? $error : null;
return $error;
}
return null;
} }
/** /**
@ -312,11 +316,7 @@ class DboPostgres extends DboSource {
* @return integer Number of affected rows * @return integer Number of affected rows
*/ */
function lastAffected() { function lastAffected() {
if ($this->_result) { return ($this->_result) ? pg_affected_rows($this->_result) : false;
$return = pg_affected_rows($this->_result);
return $return;
}
return false;
} }
/** /**
* Returns number of rows in previous resultset. If no previous resultset exists, * Returns number of rows in previous resultset. If no previous resultset exists,
@ -325,11 +325,7 @@ class DboPostgres extends DboSource {
* @return integer Number of rows in resultset * @return integer Number of rows in resultset
*/ */
function lastNumRows() { function lastNumRows() {
if ($this->_result) { return ($this->_result) ? pg_num_rows($this->_result) : false;
$return = pg_num_rows($this->_result);
return $return;
}
return false;
} }
/** /**
* Returns the ID generated from the previous INSERT operation. * Returns the ID generated from the previous INSERT operation.
@ -473,41 +469,36 @@ class DboPostgres extends DboSource {
$col = str_replace(')', '', $real); $col = str_replace(')', '', $real);
$limit = null; $limit = null;
if (strpos($col, '(') !== false) { if (strpos($col, '(') !== false) {
list($col, $limit) = explode('(', $col); list($col, $limit) = explode('(', $col);
} }
if (in_array($col, array('date', 'time'))) { $floats = array(
'float', 'float4', 'float8', 'double', 'double precision', 'decimal', 'real', 'numeric'
);
switch (true) {
case (in_array($col, array('date', 'time', 'inet', 'boolean'))):
return $col; return $col;
} case (strpos($col, 'timestamp') !== false):
if (strpos($col, 'timestamp') !== false) {
return 'datetime'; return 'datetime';
} case (strpos($col, 'time') === 0):
if (strpos($col, 'time') === 0) {
return 'time'; return 'time';
} case (strpos($col, 'int') !== false && $col != 'interval'):
if ($col == 'inet') {
return('inet');
}
if ($col == 'boolean') {
return 'boolean';
}
if (strpos($col, 'int') !== false && $col != 'interval') {
return 'integer'; return 'integer';
} case (strpos($col, 'char') !== false || $col == 'uuid'):
if (strpos($col, 'char') !== false || $col == 'uuid') {
return 'string'; return 'string';
} case (strpos($col, 'text') !== false):
if (strpos($col, 'text') !== false) {
return 'text'; return 'text';
} case (strpos($col, 'bytea') !== false):
if (strpos($col, 'bytea') !== false) {
return 'binary'; return 'binary';
} case (in_array($col, $floats)):
if (in_array($col, array('float', 'float4', 'float8', 'double', 'double precision', 'decimal', 'real', 'numeric'))) {
return 'float'; return 'float';
} default:
return 'text'; return 'text';
break;
}
} }
/** /**
* Gets the length of a database-native column description, or null if no length * Gets the length of a database-native column description, or null if no length