mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
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:
parent
fd73cf738a
commit
66240f0c5d
2 changed files with 40 additions and 47 deletions
|
@ -974,7 +974,9 @@ class Controller extends Object {
|
|||
if (isset($defaults[0])) {
|
||||
$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')) {
|
||||
$count = $object->paginateCount($conditions, $recursive);
|
||||
|
|
|
@ -222,7 +222,11 @@ class DboPostgres extends DboSource {
|
|||
$fields[$c['name']] = array(
|
||||
'type' => $this->column($c['type']),
|
||||
'null' => ($c['null'] == 'NO' ? false : true),
|
||||
'default' => preg_replace("/^'(.*)'$/", "$1", preg_replace('/::.*/', '', $c['default'])),
|
||||
'default' => preg_replace(
|
||||
"/^'(.*)'$/",
|
||||
"$1",
|
||||
preg_replace('/::.*/', '', $c['default'])
|
||||
),
|
||||
'length' => $length
|
||||
);
|
||||
if ($c['name'] == $model->primaryKey) {
|
||||
|
@ -231,7 +235,10 @@ class DboPostgres extends DboSource {
|
|||
$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;
|
||||
if (!empty($seq) && isset($seq[1])) {
|
||||
$this->_sequenceMap[$table][$c['name']] = $seq[1];
|
||||
|
@ -300,10 +307,7 @@ class DboPostgres extends DboSource {
|
|||
*/
|
||||
function lastError() {
|
||||
$error = pg_last_error($this->connection);
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
return null;
|
||||
return ($error) ? $error : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -312,11 +316,7 @@ class DboPostgres extends DboSource {
|
|||
* @return integer Number of affected rows
|
||||
*/
|
||||
function lastAffected() {
|
||||
if ($this->_result) {
|
||||
$return = pg_affected_rows($this->_result);
|
||||
return $return;
|
||||
}
|
||||
return false;
|
||||
return ($this->_result) ? pg_affected_rows($this->_result) : false;
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function lastNumRows() {
|
||||
if ($this->_result) {
|
||||
$return = pg_num_rows($this->_result);
|
||||
return $return;
|
||||
}
|
||||
return false;
|
||||
return ($this->_result) ? pg_num_rows($this->_result) : false;
|
||||
}
|
||||
/**
|
||||
* Returns the ID generated from the previous INSERT operation.
|
||||
|
@ -473,41 +469,36 @@ class DboPostgres extends DboSource {
|
|||
|
||||
$col = str_replace(')', '', $real);
|
||||
$limit = null;
|
||||
|
||||
if (strpos($col, '(') !== false) {
|
||||
list($col, $limit) = explode('(', $col);
|
||||
}
|
||||
|
||||
if (in_array($col, array('date', 'time'))) {
|
||||
return $col;
|
||||
$floats = array(
|
||||
'float', 'float4', 'float8', 'double', 'double precision', 'decimal', 'real', 'numeric'
|
||||
);
|
||||
|
||||
switch (true) {
|
||||
case (in_array($col, array('date', 'time', 'inet', 'boolean'))):
|
||||
return $col;
|
||||
case (strpos($col, 'timestamp') !== false):
|
||||
return 'datetime';
|
||||
case (strpos($col, 'time') === 0):
|
||||
return 'time';
|
||||
case (strpos($col, 'int') !== false && $col != 'interval'):
|
||||
return 'integer';
|
||||
case (strpos($col, 'char') !== false || $col == 'uuid'):
|
||||
return 'string';
|
||||
case (strpos($col, 'text') !== false):
|
||||
return 'text';
|
||||
case (strpos($col, 'bytea') !== false):
|
||||
return 'binary';
|
||||
case (in_array($col, $floats)):
|
||||
return 'float';
|
||||
default:
|
||||
return 'text';
|
||||
break;
|
||||
}
|
||||
if (strpos($col, 'timestamp') !== false) {
|
||||
return 'datetime';
|
||||
}
|
||||
if (strpos($col, 'time') === 0) {
|
||||
return 'time';
|
||||
}
|
||||
if ($col == 'inet') {
|
||||
return('inet');
|
||||
}
|
||||
if ($col == 'boolean') {
|
||||
return 'boolean';
|
||||
}
|
||||
if (strpos($col, 'int') !== false && $col != 'interval') {
|
||||
return 'integer';
|
||||
}
|
||||
if (strpos($col, 'char') !== false || $col == 'uuid') {
|
||||
return 'string';
|
||||
}
|
||||
if (strpos($col, 'text') !== false) {
|
||||
return 'text';
|
||||
}
|
||||
if (strpos($col, 'bytea') !== false) {
|
||||
return 'binary';
|
||||
}
|
||||
if (in_array($col, array('float', 'float4', 'float8', 'double', 'double precision', 'decimal', 'real', 'numeric'))) {
|
||||
return 'float';
|
||||
}
|
||||
return 'text';
|
||||
}
|
||||
/**
|
||||
* Gets the length of a database-native column description, or null if no length
|
||||
|
|
Loading…
Add table
Reference in a new issue