mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-01 23:29:45 +00:00
Updating DboPosgres::describe() to use PDO
This commit is contained in:
parent
c1ca039582
commit
ad22bc31c7
1 changed files with 37 additions and 47 deletions
|
@ -190,61 +190,51 @@ class DboPostgres extends DboSource {
|
||||||
$this->_sequenceMap[$table] = array();
|
$this->_sequenceMap[$table] = array();
|
||||||
|
|
||||||
if ($fields === null) {
|
if ($fields === null) {
|
||||||
$cols = $this->fetchAll(
|
$cols = $this->_execute(
|
||||||
"SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null,
|
"SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null,
|
||||||
column_default AS default, ordinal_position AS position, character_maximum_length AS char_length,
|
column_default AS default, ordinal_position AS position, character_maximum_length AS char_length,
|
||||||
character_octet_length AS oct_length FROM information_schema.columns
|
character_octet_length AS oct_length FROM information_schema.columns
|
||||||
WHERE table_name = " . $this->value($table) . " AND table_schema = " .
|
WHERE table_name = ? AND table_schema = ? ORDER BY position",
|
||||||
$this->value($this->config['schema'])." ORDER BY position",
|
array($table, $this->config['schema'])
|
||||||
false
|
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($cols as $column) {
|
foreach ($cols as $c) {
|
||||||
$colKey = array_keys($column);
|
$type = $c->type;
|
||||||
|
if (!empty($c->char_length)) {
|
||||||
if (isset($column[$colKey[0]]) && !isset($column[0])) {
|
$length = intval($c->char_length);
|
||||||
$column[0] = $column[$colKey[0]];
|
} elseif (!empty($c->oct_length)) {
|
||||||
}
|
if ($c->type == 'character varying') {
|
||||||
|
$length = null;
|
||||||
if (isset($column[0])) {
|
$type = 'text';
|
||||||
$c = $column[0];
|
|
||||||
|
|
||||||
if (!empty($c['char_length'])) {
|
|
||||||
$length = intval($c['char_length']);
|
|
||||||
} elseif (!empty($c['oct_length'])) {
|
|
||||||
if ($c['type'] == 'character varying') {
|
|
||||||
$length = null;
|
|
||||||
$c['type'] = 'text';
|
|
||||||
} else {
|
|
||||||
$length = intval($c['oct_length']);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$length = $this->length($c['type']);
|
$length = intval($c->oct_length);
|
||||||
}
|
}
|
||||||
$fields[$c['name']] = array(
|
} else {
|
||||||
'type' => $this->column($c['type']),
|
$length = $this->length($c->type);
|
||||||
'null' => ($c['null'] == 'NO' ? false : true),
|
}
|
||||||
'default' => preg_replace(
|
$fields[$c->name] = array(
|
||||||
"/^'(.*)'$/",
|
'type' => $this->column($type),
|
||||||
"$1",
|
'null' => ($c->null == 'NO' ? false : true),
|
||||||
preg_replace('/::.*/', '', $c['default'])
|
'default' => preg_replace(
|
||||||
),
|
"/^'(.*)'$/",
|
||||||
'length' => $length
|
"$1",
|
||||||
);
|
preg_replace('/::.*/', '', $c->default)
|
||||||
if ($c['name'] == $model->primaryKey) {
|
),
|
||||||
$fields[$c['name']]['key'] = 'primary';
|
'length' => $length
|
||||||
if ($fields[$c['name']]['type'] !== 'string') {
|
);
|
||||||
$fields[$c['name']]['length'] = 11;
|
if ($c->name == $model->primaryKey) {
|
||||||
}
|
$fields[$c->name]['key'] = 'primary';
|
||||||
|
if ($fields[$c->name]['type'] !== 'string') {
|
||||||
|
$fields[$c->name]['length'] = 11;
|
||||||
}
|
}
|
||||||
if (
|
}
|
||||||
$fields[$c['name']]['default'] == 'NULL' ||
|
if (
|
||||||
preg_match('/nextval\([\'"]?([\w.]+)/', $c['default'], $seq)
|
$fields[$c->name]['default'] == 'NULL' ||
|
||||||
) {
|
preg_match('/nextval\([\'"]?([\w.]+)/', $c->default, $seq)
|
||||||
$fields[$c['name']]['default'] = null;
|
) {
|
||||||
if (!empty($seq) && isset($seq[1])) {
|
$fields[$c->name]['default'] = null;
|
||||||
$this->_sequenceMap[$table][$c['name']] = $seq[1];
|
if (!empty($seq) && isset($seq[1])) {
|
||||||
}
|
$this->_sequenceMap[$table][$c->default] = $seq[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue