diff options
| author | jmruiz84 <31624807+jmruiz84@users.noreply.github.com> | 2021-01-24 18:41:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-24 18:41:56 +0100 |
| commit | 26f083508bec0786c2c76440f4ba0f2413eb1ef5 (patch) | |
| tree | b6a5b724a68e4f73ce580fb080a8ff713e63957f /datadict | |
| parent | d7c0e619d92b2e9a12ea8bf7da393b95754bbeb7 (diff) | |
| download | adodb-26f083508bec0786c2c76440f4ba0f2413eb1ef5.tar.gz adodb-26f083508bec0786c2c76440f4ba0f2413eb1ef5.tar.bz2 adodb-26f083508bec0786c2c76440f4ba0f2413eb1ef5.zip | |
pgsql: add override for ChangeTableSQL()
Inheritance from ADODB DataDict does not work.
This new function has been verified in PostgreSQL 12.2
Fixes #634
Diffstat (limited to 'datadict')
| -rw-r--r-- | datadict/datadict-postgres.inc.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/datadict/datadict-postgres.inc.php b/datadict/datadict-postgres.inc.php index 0a0162b3..222ee55b 100644 --- a/datadict/datadict-postgres.inc.php +++ b/datadict/datadict-postgres.inc.php @@ -516,4 +516,48 @@ CREATE [ UNIQUE ] INDEX index_name ON table } return $ftype; } + + function ChangeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false){ + global $ADODB_FETCH_MODE; + parent::ChangeTableSQL($tablename, $flds); + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; + if ($this->connection->fetchMode !== false) + $savem = $this->connection->SetFetchMode(false); + + // check table exists + $save_handler = $this->connection->raiseErrorFn; + $this->connection->raiseErrorFn = ''; + $cols = $this->MetaColumns($tablename); + $this->connection->raiseErrorFn = $save_handler; + + if (isset($savem)) + $this->connection->SetFetchMode($savem); + $ADODB_FETCH_MODE = $save; + + $sqlResult=array(); + if ( empty($cols)) { + $sqlResult=$this->CreateTableSQL($tablename, $flds, $tableoptions); + } else { + $sqlResultAdd = $this->AddColumnSQL($tablename, $flds); + $sqlResultAlter = $this->AlterColumnSQL($tablename, $flds, '', $tableoptions); + $sqlResult = array_merge((array)$sqlResultAdd, (array)$sqlResultAlter); + + if ($dropOldFlds) { + // already exists, alter table instead + list($lines,$pkey,$idxs) = $this->_GenFields($flds); + // genfields can return FALSE at times + if ($lines == null) + $lines = array(); + $alter = 'ALTER TABLE ' . $this->TableName($tablename); + foreach ( $cols as $id => $v ){ + if ( !isset($lines[$id]) ){ + $sqlResult[] = $alter . $this->dropCol . ' ' . $v->name; + } + } + } + + } + return $sqlResult; + } } |
