From 2dfb908fbf9e1123d43f1da2f7f13e68c541d962 Mon Sep 17 00:00:00 2001 From: cytopia Date: Sun, 8 Nov 2020 14:44:21 +0100 Subject: [PATCH] Fix phpPgAdmin for PHP 8.0 and PHP 8.1 --- .../adodb/drivers/adodb-postgres64.inc.php | 458 +++++++++--------- .../adodb/drivers/adodb-postgres7.inc.php | 106 ++-- .tests/tests/vendor-phppgadmin.sh | 2 +- CONTRIBUTING.md | 14 + 4 files changed, 297 insertions(+), 283 deletions(-) diff --git a/.devilbox/www/htdocs/vendor/phppgadmin-7.13.0/libraries/adodb/drivers/adodb-postgres64.inc.php b/.devilbox/www/htdocs/vendor/phppgadmin-7.13.0/libraries/adodb/drivers/adodb-postgres64.inc.php index 7b838a88..77684523 100644 --- a/.devilbox/www/htdocs/vendor/phppgadmin-7.13.0/libraries/adodb/drivers/adodb-postgres64.inc.php +++ b/.devilbox/www/htdocs/vendor/phppgadmin-7.13.0/libraries/adodb/drivers/adodb-postgres64.inc.php @@ -1,29 +1,29 @@ - jlim - changed concat operator to || and data types to MetaType to match documented pgsql types - see http://www.postgresql.org/devel-corner/docs/postgres/datatype.htm + jlim - changed concat operator to || and data types to MetaType to match documented pgsql types + see http://www.postgresql.org/devel-corner/docs/postgres/datatype.htm 22 Nov 2000 jlim - added changes to FetchField() and MetaTables() contributed by "raser" 27 Nov 2000 jlim - added changes to _connect/_pconnect from ideas by "Lennie" - 15 Dec 2000 jlim - added changes suggested by Additional code changes by "Eric G. Werk" egw@netguide.dk. + 15 Dec 2000 jlim - added changes suggested by Additional code changes by "Eric G. Werk" egw@netguide.dk. 31 Jan 2002 jlim - finally installed postgresql. testing 01 Mar 2001 jlim - Freek Dijkstra changes, also support for text type - + See http://www.varlena.com/varlena/GeneralBits/47.php - + -- What indexes are on my table? select * from pg_indexes where tablename = 'tablename'; - + -- What triggers are on my table? - select c.relname as "Table", t.tgname as "Trigger Name", + select c.relname as "Table", t.tgname as "Trigger Name", t.tgconstrname as "Constraint Name", t.tgenabled as "Enabled", t.tgisconstraint as "Is Constraint", cc.relname as "Referenced Table", p.proname as "Function Name" @@ -31,7 +31,7 @@ where t.tgfoid = p.oid and t.tgrelid = c.oid and t.tgconstrrelid = cc.oid and c.relname = 'tablename'; - + -- What constraints are on my table? select r.relname as "Table", c.conname as "Constraint Name", contype as "Constraint Type", conkey as "Key Columns", @@ -50,7 +50,7 @@ function adodb_addslashes($s) $len = strlen($s); if ($len == 0) return "''"; if (strncmp($s,"'",1) === 0 && substr($s,$len-1) == "'") return $s; // already quoted - + return "'".addslashes($s)."'"; } @@ -63,34 +63,34 @@ class ADODB_postgres64 extends ADOConnection{ var $metaDatabasesSQL = "select datname from pg_database where datname not in ('template0','template1') order by 1"; var $metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' and tablename not in ('sql_features', 'sql_implementation_info', 'sql_languages', - 'sql_packages', 'sql_sizing', 'sql_sizing_profiles') - union + 'sql_packages', 'sql_sizing', 'sql_sizing_profiles') + union select viewname,'V' from pg_views where viewname not like 'pg\_%'"; //"select tablename from pg_tables where tablename not like 'pg_%' order by 1"; var $isoDates = true; // accepts dates in ISO format var $sysDate = "CURRENT_DATE"; var $sysTimeStamp = "CURRENT_TIMESTAMP"; var $blobEncodeType = 'C'; - var $metaColumnsSQL = "SELECT a.attname,t.typname,a.attlen,a.atttypmod,a.attnotnull,a.atthasdef,a.attnum - FROM pg_class c, pg_attribute a,pg_type t + var $metaColumnsSQL = "SELECT a.attname,t.typname,a.attlen,a.atttypmod,a.attnotnull,a.atthasdef,a.attnum + FROM pg_class c, pg_attribute a,pg_type t WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s')) and a.attname not like '....%%' AND a.attnum > 0 AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum"; // used when schema defined - var $metaColumnsSQL1 = "SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, a.attnum -FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n + var $metaColumnsSQL1 = "SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, a.attnum +FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s')) - and c.relnamespace=n.oid and n.nspname='%s' - and a.attname not like '....%%' AND a.attnum > 0 + and c.relnamespace=n.oid and n.nspname='%s' + and a.attname not like '....%%' AND a.attnum > 0 AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum"; - + // get primary key etc -- from Freek Dijkstra - var $metaKeySQL = "SELECT ic.relname AS index_name, a.attname AS column_name,i.indisunique AS unique_key, i.indisprimary AS primary_key + var $metaKeySQL = "SELECT ic.relname AS index_name, a.attname AS column_name,i.indisunique AS unique_key, i.indisprimary AS primary_key FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND (i.indkey[0] = a.attnum OR i.indkey[1] = a.attnum OR i.indkey[2] = a.attnum OR i.indkey[3] = a.attnum OR i.indkey[4] = a.attnum OR i.indkey[5] = a.attnum OR i.indkey[6] = a.attnum OR i.indkey[7] = a.attnum) AND a.attrelid = bc.oid AND bc.relname = '%s'"; - + var $hasAffectedRows = true; var $hasLimit = false; // set to true for pgsql 7 only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10 - // below suggested by Freek Dijkstra + // below suggested by Freek Dijkstra var $true = 'TRUE'; // string that represents TRUE for a database var $false = 'FALSE'; // string that represents FALSE for a database var $fmtDate = "'Y-m-d'"; // used by DBDate() as the default date format used by the database @@ -104,37 +104,37 @@ WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s')) var $random = 'random()'; /// random function var $autoRollback = true; // apparently pgsql does not autorollback properly before php 4.3.4 // http://bugs.php.net/bug.php?id=25404 - + var $uniqueIisR = true; var $_bindInputArray = false; // requires postgresql 7.3+ and ability to modify database var $disableBlobs = false; // set to true to disable blob checking, resulting in 2-5% improvement in performance. - - // The last (fmtTimeStamp is not entirely correct: - // PostgreSQL also has support for time zones, - // and writes these time in this format: "2001-03-01 18:59:26+02". - // There is no code for the "+02" time zone information, so I just left that out. - // I'm not familiar enough with both ADODB as well as Postgres - // to know what the concequences are. The other values are correct (wheren't in 0.94) - // -- Freek Dijkstra - function ADODB_postgres64() + // The last (fmtTimeStamp is not entirely correct: + // PostgreSQL also has support for time zones, + // and writes these time in this format: "2001-03-01 18:59:26+02". + // There is no code for the "+02" time zone information, so I just left that out. + // I'm not familiar enough with both ADODB as well as Postgres + // to know what the concequences are. The other values are correct (wheren't in 0.94) + // -- Freek Dijkstra + + function __construct() { // changes the metaColumnsSQL, adds columns: attnum[6] } - + function ServerInfo() { if (isset($this->version)) return $this->version; - + $arr['description'] = $this->GetOne("select version()"); $arr['version'] = ADOConnection::_findvers($arr['description']); $this->version = $arr; return $arr; } - function IfNull( $field, $ifNull ) + function IfNull( $field, $ifNull ) { - return " coalesce($field, $ifNull) "; + return " coalesce($field, $ifNull) "; } // get the last id - never tested @@ -148,10 +148,10 @@ WHERE relkind in ('r','v') AND (c.relname='%s' or c.relname = lower('%s')) } return false; } - + /* Warning from http://www.php.net/manual/function.pg-getlastoid.php: -Using a OID as a unique identifier is not generally wise. -Unless you are very careful, you might end up with a tuple having +Using a OID as a unique identifier is not generally wise. +Unless you are very careful, you might end up with a tuple having a different OID if a database must be reloaded. */ function _insertid($table,$column) { @@ -168,8 +168,8 @@ a different OID if a database must be reloaded. */ if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; return pg_cmdtuples($this->_resultid); } - - + + // returns true/false function BeginTrans() { @@ -177,23 +177,23 @@ a different OID if a database must be reloaded. */ $this->transCnt += 1; return @pg_Exec($this->_connectionID, "begin ".$this->_transmode); } - - function RowLock($tables,$where,$col='1 as adodbignore') + + function RowLock($tables,$where,$col='1 as adodbignore') { if (!$this->transCnt) $this->BeginTrans(); return $this->GetOne("select $col from $tables where $where for update"); } - // returns true/false. - function CommitTrans($ok=true) - { + // returns true/false. + function CommitTrans($ok=true) + { if ($this->transOff) return true; if (!$ok) return $this->RollbackTrans(); - + $this->transCnt -= 1; return @pg_Exec($this->_connectionID, "commit"); } - + // returns true/false function RollbackTrans() { @@ -201,14 +201,14 @@ a different OID if a database must be reloaded. */ $this->transCnt -= 1; return @pg_Exec($this->_connectionID, "rollback"); } - - function MetaTables($ttype=false,$showSchema=false,$mask=false) + + function MetaTables($ttype=false,$showSchema=false,$mask=false) { $info = $this->ServerInfo(); if ($info['version'] >= 7.3) { $this->metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' and schemaname not in ( 'pg_catalog','information_schema') - union + union select viewname,'V' from pg_views where viewname not like 'pg\_%' and schemaname not in ( 'pg_catalog','information_schema') "; } if ($mask) { @@ -216,55 +216,55 @@ a different OID if a database must be reloaded. */ $mask = $this->qstr(strtolower($mask)); if ($info['version']>=7.3) $this->metaTablesSQL = " -select tablename,'T' from pg_tables where tablename like $mask and schemaname not in ( 'pg_catalog','information_schema') - union +select tablename,'T' from pg_tables where tablename like $mask and schemaname not in ( 'pg_catalog','information_schema') + union select viewname,'V' from pg_views where viewname like $mask and schemaname not in ( 'pg_catalog','information_schema') "; else $this->metaTablesSQL = " -select tablename,'T' from pg_tables where tablename like $mask - union +select tablename,'T' from pg_tables where tablename like $mask + union select viewname,'V' from pg_views where viewname like $mask"; } $ret = ADOConnection::MetaTables($ttype,$showSchema); - + if ($mask) { $this->metaTablesSQL = $save; } return $ret; } - - + + // if magic quotes disabled, use pg_escape_string() function qstr($s,$magic_quotes=false) { if (is_bool($s)) return $s ? 'true' : 'false'; - + if (!$magic_quotes) { if (ADODB_PHPVER >= 0x5200) { return "'".pg_escape_string($this->_connectionID,$s)."'"; - } + } if (ADODB_PHPVER >= 0x4200) { return "'".pg_escape_string($s)."'"; } if ($this->replaceQuote[0] == '\\'){ $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\\000"),$s); } - return "'".str_replace("'",$this->replaceQuote,$s)."'"; + return "'".str_replace("'",$this->replaceQuote,$s)."'"; } - + // undo magic quotes for " $s = str_replace('\\"','"',$s); return "'$s'"; } - - - + + + // Format date column in sql string given an input format that understands Y M D function SQLDate($fmt, $col=false) - { + { if (!$col) $col = $this->sysTimeStamp; $s = 'TO_CHAR('.$col.",'"; - + $len = strlen($fmt); for ($i=0; $i < $len; $i++) { $ch = $fmt[$i]; @@ -277,11 +277,11 @@ select viewname,'V' from pg_views where viewname like $mask"; case 'q': $s .= 'Q'; break; - + case 'M': $s .= 'Mon'; break; - + case 'm': $s .= 'MM'; break; @@ -289,36 +289,36 @@ select viewname,'V' from pg_views where viewname like $mask"; case 'd': $s .= 'DD'; break; - + case 'H': $s.= 'HH24'; break; - + case 'h': $s .= 'HH'; break; - + case 'i': $s .= 'MI'; break; - + case 's': $s .= 'SS'; break; - + case 'a': case 'A': $s .= 'AM'; break; - + case 'w': $s .= 'D'; break; - + case 'l': $s .= 'DAY'; break; - + case 'W': $s .= 'WW'; break; @@ -331,44 +331,44 @@ select viewname,'V' from pg_views where viewname like $mask"; } if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; else $s .= '"'.$ch.'"'; - + } } return $s. "')"; } - - - - /* - * Load a Large Object from a file - * - the procedure stores the object id in the table and imports the object using - * postgres proprietary blob handling routines + + + + /* + * Load a Large Object from a file + * - the procedure stores the object id in the table and imports the object using + * postgres proprietary blob handling routines * * contributed by Mattia Rossi mattia@technologist.com * modified for safe mode by juraj chlebec - */ - function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') - { - pg_exec ($this->_connectionID, "begin"); - + */ + function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') + { + pg_exec ($this->_connectionID, "begin"); + $fd = fopen($path,'r'); $contents = fread($fd,filesize($path)); fclose($fd); - + $oid = pg_lo_create($this->_connectionID); $handle = pg_lo_open($this->_connectionID, $oid, 'w'); pg_lo_write($handle, $contents); pg_lo_close($handle); - - // $oid = pg_lo_import ($path); - pg_exec($this->_connectionID, "commit"); - $rs = ADOConnection::UpdateBlob($table,$column,$oid,$where,$blobtype); - $rez = !empty($rs); - return $rez; - } - + + // $oid = pg_lo_import ($path); + pg_exec($this->_connectionID, "commit"); + $rs = ADOConnection::UpdateBlob($table,$column,$oid,$where,$blobtype); + $rez = !empty($rs); + return $rez; + } + /* - * Deletes/Unlinks a Blob from the database, otherwise it + * Deletes/Unlinks a Blob from the database, otherwise it * will be left behind * * Returns TRUE on success or FALSE on failure. @@ -391,8 +391,8 @@ select viewname,'V' from pg_views where viewname like $mask"; if (strlen($oid)>16) return false; return is_numeric($oid); } - - /* + + /* * If an OID is detected, then we use pg_lo_* to open the oid file and read the * real blob from the db using the oid supplied as a parameter. If you are storing * blobs using bytea, we autodetect and process it so this function is not needed. @@ -403,109 +403,109 @@ select viewname,'V' from pg_views where viewname like $mask"; * * Since adodb 4.54, this returns the blob, instead of sending it to stdout. Also * added maxsize parameter, which defaults to $db->maxblobsize if not defined. - */ - function BlobDecode($blob,$maxsize=false,$hastrans=true) + */ + function BlobDecode($blob,$maxsize=false,$hastrans=true) { if (!$this->GuessOID($blob)) return $blob; - - if ($hastrans) @pg_exec($this->_connectionID,"begin"); + + if ($hastrans) @pg_exec($this->_connectionID,"begin"); $fd = @pg_lo_open($this->_connectionID,$blob,"r"); if ($fd === false) { if ($hastrans) @pg_exec($this->_connectionID,"commit"); return $blob; } if (!$maxsize) $maxsize = $this->maxblobsize; - $realblob = @pg_loread($fd,$maxsize); - @pg_loclose($fd); - if ($hastrans) @pg_exec($this->_connectionID,"commit"); + $realblob = @pg_loread($fd,$maxsize); + @pg_loclose($fd); + if ($hastrans) @pg_exec($this->_connectionID,"commit"); return $realblob; } - - /* + + /* See http://www.postgresql.org/idocs/index.php?datatype-binary.html - - NOTE: SQL string literals (input strings) must be preceded with two backslashes - due to the fact that they must pass through two parsers in the PostgreSQL + + NOTE: SQL string literals (input strings) must be preceded with two backslashes + due to the fact that they must pass through two parsers in the PostgreSQL backend. */ function BlobEncode($blob) { if (ADODB_PHPVER >= 0x5200) return pg_escape_bytea($this->_connectionID, $blob); if (ADODB_PHPVER >= 0x4200) return pg_escape_bytea($blob); - + /*92=backslash, 0=null, 39=single-quote*/ $badch = array(chr(92),chr(0),chr(39)); # \ null ' $fixch = array('\\\\134','\\\\000','\\\\047'); return adodb_str_replace($badch,$fixch,$blob); - + // note that there is a pg_escape_bytea function only for php 4.2.0 or later } - + // assumes bytea for blob, and varchar for clob function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') { - + if ($blobtype == 'CLOB') { return $this->Execute("UPDATE $table SET $column=" . $this->qstr($val) . " WHERE $where"); } // do not use bind params which uses qstr(), as blobencode() already quotes data return $this->Execute("UPDATE $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where"); } - + function OffsetDate($dayFraction,$date=false) - { + { if (!$date) $date = $this->sysDate; else if (strncmp($date,"'",1) == 0) { $len = strlen($date); if (10 <= $len && $len <= 12) $date = 'date '.$date; else $date = 'timestamp '.$date; } - - + + return "($date+interval'".($dayFraction * 1440)." minutes')"; #return "($date+interval'$dayFraction days')"; } - + // for schema support, pass in the $table param "$schema.$tabname". // converts field names to lowercase, $upper is ignored // see http://phplens.com/lens/lensforum/msgs.php?id=14018 for more info - function MetaColumns($table,$normalize=true) + function MetaColumns($table,$normalize=true) { global $ADODB_FETCH_MODE; - + $schema = false; $false = false; $this->_findschema($table,$schema); - + if ($normalize) $table = strtolower($table); $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); - + if ($schema) $rs = $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema)); else $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table,$table)); if (isset($savem)) $this->SetFetchMode($savem); $ADODB_FETCH_MODE = $save; - + if ($rs === false) { return $false; } if (!empty($this->metaKeySQL)) { // If we want the primary keys, we have to issue a separate query - // Of course, a modified version of the metaColumnsSQL query using a - // LEFT JOIN would have been much more elegant, but postgres does + // Of course, a modified version of the metaColumnsSQL query using a + // LEFT JOIN would have been much more elegant, but postgres does // not support OUTER JOINS. So here is the clumsy way. - + $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; - + $rskey = $this->Execute(sprintf($this->metaKeySQL,($table))); // fetch all result in once for performance. $keys = $rskey->GetArray(); if (isset($savem)) $this->SetFetchMode($savem); $ADODB_FETCH_MODE = $save; - + $rskey->Close(); unset($rskey); } @@ -517,7 +517,7 @@ select viewname,'V' from pg_views where viewname like $mask"; $rsdef = $this->Execute($sql); if (isset($savem)) $this->SetFetchMode($savem); $ADODB_FETCH_MODE = $save; - + if ($rsdef) { while (!$rsdef->EOF) { $num = $rsdef->fields['num']; @@ -535,15 +535,15 @@ select viewname,'V' from pg_views where viewname like $mask"; } unset($rsdef); } - + $retarr = array(); - while (!$rs->EOF) { + while (!$rs->EOF) { $fld = new ADOFieldObject(); $fld->name = $rs->fields[0]; $fld->type = $rs->fields[1]; $fld->max_length = $rs->fields[2]; $fld->attnum = $rs->fields[6]; - + if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4; if ($fld->max_length <= 0) $fld->max_length = -1; if ($fld->type == 'numeric') { @@ -559,45 +559,45 @@ select viewname,'V' from pg_views where viewname like $mask"; //Freek $fld->not_null = $rs->fields[4] == 't'; - - + + // Freek if (is_array($keys)) { foreach($keys as $key) { - if ($fld->name == $key['column_name'] AND $key['primary_key'] == 't') + if ($fld->name == $key['column_name'] AND $key['primary_key'] == 't') $fld->primary_key = true; - if ($fld->name == $key['column_name'] AND $key['unique_key'] == 't') + if ($fld->name == $key['column_name'] AND $key['unique_key'] == 't') $fld->unique = true; // What name is more compatible? } } - - if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; + + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; else $retarr[($normalize) ? strtoupper($fld->name) : $fld->name] = $fld; - + $rs->MoveNext(); } $rs->Close(); if (empty($retarr)) return $false; else - return $retarr; - + return $retarr; + } function MetaIndexes ($table, $primary = FALSE, $owner = false) { global $ADODB_FETCH_MODE; - + $schema = false; $this->_findschema($table,$schema); if ($schema) { // requires pgsql 7.3+ - pg_namespace used. $sql = ' -SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns" -FROM pg_catalog.pg_class c -JOIN pg_catalog.pg_index i ON i.indexrelid=c.oid +SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns" +FROM pg_catalog.pg_class c +JOIN pg_catalog.pg_index i ON i.indexrelid=c.oid JOIN pg_catalog.pg_class c2 ON c2.oid=i.indrelid - ,pg_namespace n + ,pg_namespace n WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\')) and c.relnamespace=c2.relnamespace and c.relnamespace=n.oid and n.nspname=\'%s\''; } else { $sql = ' @@ -607,17 +607,17 @@ JOIN pg_catalog.pg_index i ON i.indexrelid=c.oid JOIN pg_catalog.pg_class c2 ON c2.oid=i.indrelid WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; } - + if ($primary == FALSE) { $sql .= ' AND i.indisprimary=false;'; } - + $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; if ($this->fetchMode !== FALSE) { $savem = $this->SetFetchMode(FALSE); } - + $rs = $this->Execute(sprintf($sql,$table,$table,$schema)); if (isset($savem)) { $this->SetFetchMode($savem); @@ -628,9 +628,9 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; $false = false; return $false; } - - $col_names = $this->MetaColumnNames($table,true,true); - //3rd param is use attnum, + + $col_names = $this->MetaColumnNames($table,true,true); + //3rd param is use attnum, // see http://sourceforge.net/tracker/index.php?func=detail&aid=1451245&group_id=42718&atid=433976 $indexes = array(); while ($row = $rs->FetchRow()) { @@ -638,7 +638,7 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; foreach (explode(' ', $row[2]) as $col) { $columns[] = $col_names[$col]; } - + $indexes[$row[0]] = array( 'unique' => ($row[1] == 't'), 'columns' => $columns @@ -654,11 +654,11 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; // $db->Connect('host1','user1','secret'); function _connect($str,$user='',$pwd='',$db='',$ctype=0) { - + if (!function_exists('pg_connect')) return null; - + $this->_errorMsg = false; - + if ($user || $pwd || $db) { $user = adodb_addslashes($user); $pwd = adodb_addslashes($pwd); @@ -683,17 +683,17 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; } else { if ($ctype === -1) { // nconnect, we trick pgsql ext by changing the connection str static $ncnt; - + if (empty($ncnt)) $ncnt = 1; else $ncnt += 1; - + $str .= str_repeat(' ',$ncnt); } $this->_connectionID = @pg_connect($str); } if ($this->_connectionID === false) return false; $this->Execute("set datestyle='ISO'"); - + $info = $this->ServerInfo(); $this->pgVersion = (float) substr($info['version'],0,3); if ($this->pgVersion >= 7.1) { // good till version 999 @@ -701,12 +701,12 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; } return true; } - + function _nconnect($argHostname, $argUsername, $argPassword, $argDatabaseName) { return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName,-1); } - + // returns true or false // // examples: @@ -716,7 +716,7 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; { return $this->_connect($str,$user,$pwd,$db,1); } - + // returns queryID or false function _query($sql,$inputarr=false) @@ -725,19 +725,19 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; if ($inputarr) { /* It appears that PREPARE/EXECUTE is slower for many queries. - + For query executed 1000 times: - "select id,firstname,lastname from adoxyz + "select id,firstname,lastname from adoxyz where firstname not like ? and lastname not like ? and id = ?" - + with plan = 1.51861286163 secs no plan = 1.26903700829 secs - + */ $plan = 'P'.md5($sql); - + $execp = ''; foreach($inputarr as $v) { if ($execp) $execp .= ','; @@ -747,11 +747,11 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; $execp .= $v; } } - + if ($execp) $exsql = "EXECUTE $plan ($execp)"; else $exsql = "EXECUTE $plan"; - - + + $rez = @pg_exec($this->_connectionID,$exsql); if (!$rez) { # Perhaps plan does not exist? Prepare/compile plan. @@ -774,7 +774,7 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; $sql .= $v.' $'.$i; $i++; } - $s = "PREPARE $plan ($params) AS ".substr($sql,0,strlen($sql)-2); + $s = "PREPARE $plan ($params) AS ".substr($sql,0,strlen($sql)-2); //adodb_pr($s); $rez = pg_exec($this->_connectionID,$s); //echo $this->ErrorMsg(); @@ -793,18 +793,18 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; $this->_resultid = $rez; return true; } - + return $rez; } - + function _errconnect() { if (defined('DB_ERROR_CONNECT_FAILED')) return DB_ERROR_CONNECT_FAILED; else return 'Database connection failed'; } - /* Returns: the last error message from previous database operation */ - function ErrorMsg() + /* Returns: the last error message from previous database operation */ + function ErrorMsg() { if ($this->_errorMsg !== false) return $this->_errorMsg; if (ADODB_PHPVER >= 0x4300) { @@ -812,7 +812,7 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; $this->_errorMsg = @pg_result_error($this->_resultid); if ($this->_errorMsg) return $this->_errorMsg; } - + if (!empty($this->_connectionID)) { $this->_errorMsg = @pg_last_error($this->_connectionID); } else $this->_errorMsg = $this->_errconnect(); @@ -822,7 +822,7 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; } return $this->_errorMsg; } - + function ErrorNo() { $e = $this->ErrorMsg(); @@ -844,8 +844,8 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; $this->_connectionID = false; return true; } - - + + /* * Maximum size of C field */ @@ -853,7 +853,7 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; { return 1000000000; // should be 1 Gb? } - + /* * Maximum size of X field */ @@ -861,10 +861,10 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))'; { return 1000000000; // should be 1 Gb? } - - + + } - + /*-------------------------------------------------------------------------------------- Class Name: Recordset --------------------------------------------------------------------------------------*/ @@ -873,9 +873,9 @@ class ADORecordSet_postgres64 extends ADORecordSet{ var $_blobArr; var $databaseType = "postgres64"; var $canSeek = true; - function __construct($queryID,$mode=false) + function __construct($queryID,$mode=false) { - if ($mode === false) { + if ($mode === false) { global $ADODB_FETCH_MODE; $mode = $ADODB_FETCH_MODE; } @@ -883,15 +883,15 @@ class ADORecordSet_postgres64 extends ADORecordSet{ { case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break; case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break; - + case ADODB_FETCH_DEFAULT: case ADODB_FETCH_BOTH: default: $this->fetchMode = PGSQL_BOTH; break; } $this->adodbFetchMode = $mode; - parent::__construct($queryID); + parent::__construct($queryID); } - + function GetRowAssoc($upper=true) { if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields; @@ -905,11 +905,11 @@ class ADORecordSet_postgres64 extends ADORecordSet{ $qid = $this->_queryID; $this->_numOfRows = ($ADODB_COUNTRECS)? @pg_numrows($qid):-1; $this->_numOfFields = @pg_numfields($qid); - + // cache types for blob decode check // apparently pg_fieldtype actually performs an sql query on the database to get the type. if (empty($this->connection->noBlobs)) - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { + for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { if (pg_fieldtype($qid,$i) == 'bytea') { $this->_blobArr[$i] = pg_fieldname($qid,$i); } @@ -920,7 +920,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{ function Fields($colname) { if ($this->fetchMode != PGSQL_NUM) return @$this->fields[$colname]; - + if (!$this->bind) { $this->bind = array(); for ($i=0; $i < $this->_numOfFields; $i++) { @@ -931,33 +931,33 @@ class ADORecordSet_postgres64 extends ADORecordSet{ return $this->fields[$this->bind[strtoupper($colname)]]; } - function FetchField($off = 0) + function FetchField($off = 0) { // offsets begin at 0 - + $o= new ADOFieldObject(); $o->name = @pg_fieldname($this->_queryID,$off); $o->type = @pg_fieldtype($this->_queryID,$off); $o->max_length = @pg_fieldsize($this->_queryID,$off); - return $o; + return $o; } function _seek($row) { return @pg_fetch_row($this->_queryID,$row); } - + function _decode($blob) { if ($blob === NULL) return NULL; eval('$realblob="'.adodb_str_replace(array('"','$'),array('\"','\$'),$blob).'";'); - return $realblob; + return $realblob; } - + function _fixblobs() { - - return; # bypass adodb's bytea handling, so we can handle it ourselves within PHP + + return; # bypass adodb's bytea handling, so we can handle it ourselves within PHP if ($this->fetchMode == PGSQL_NUM || $this->fetchMode == PGSQL_BOTH) { foreach($this->_blobArr as $k => $v) { @@ -970,9 +970,9 @@ class ADORecordSet_postgres64 extends ADORecordSet{ } } } - + // 10% speedup to move MoveNext to child class - function MoveNext() + function MoveNext() { if (!$this->EOF) { $this->_currentRow++; @@ -987,23 +987,23 @@ class ADORecordSet_postgres64 extends ADORecordSet{ $this->EOF = true; } return false; - } - + } + function _fetch() { - + if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) return false; $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); - + if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); - + return (is_array($this->fields)); } - function _close() - { + function _close() + { return @pg_freeresult($this->_queryID); } @@ -1026,45 +1026,45 @@ class ADORecordSet_postgres64 extends ADORecordSet{ case 'INET': case 'MACADDR': if ($len <= $this->blobSize) return 'C'; - + case 'TEXT': return 'X'; - + case 'IMAGE': // user defined type case 'BLOB': // user defined type case 'BIT': // This is a bit string, not a single bit, so don't return 'L' case 'VARBIT': case 'BYTEA': return 'B'; - + case 'BOOL': case 'BOOLEAN': return 'L'; - + case 'DATE': return 'D'; - - + + case 'TIMESTAMP WITHOUT TIME ZONE': case 'TIME': case 'DATETIME': case 'TIMESTAMP': case 'TIMESTAMPTZ': return 'T'; - - case 'SMALLINT': - case 'BIGINT': - case 'INTEGER': - case 'INT8': + + case 'SMALLINT': + case 'BIGINT': + case 'INTEGER': + case 'INT8': case 'INT4': case 'INT2': if (isset($fieldobj) && empty($fieldobj->primary_key) && (!$this->connection->uniqueIisR || empty($fieldobj->unique))) return 'I'; - + case 'OID': case 'SERIAL': return 'R'; - + default: return 'N'; } diff --git a/.devilbox/www/htdocs/vendor/phppgadmin-7.13.0/libraries/adodb/drivers/adodb-postgres7.inc.php b/.devilbox/www/htdocs/vendor/phppgadmin-7.13.0/libraries/adodb/drivers/adodb-postgres7.inc.php index 1ce0350e..9729e221 100644 --- a/.devilbox/www/htdocs/vendor/phppgadmin-7.13.0/libraries/adodb/drivers/adodb-postgres7.inc.php +++ b/.devilbox/www/htdocs/vendor/phppgadmin-7.13.0/libraries/adodb/drivers/adodb-postgres7.inc.php @@ -1,11 +1,11 @@ ADODB_postgres64(); + parent::__construct(); if (ADODB_ASSOC_CASE !== 2) { $this->rsPrefix .= 'assoc_'; } $this->_bindInputArray = PHP_VERSION >= 5.1; } - - // the following should be compat with postgresql 7.2, + + // the following should be compat with postgresql 7.2, // which makes obsolete the LIMIT limit,offset syntax - function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) + function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) { $offsetStr = ($offset >= 0) ? " OFFSET ".((integer)$offset) : ''; $limitStr = ($nrows >= 0) ? " LIMIT ".((integer)$nrows) : ''; @@ -42,7 +42,7 @@ class ADODB_postgres7 extends ADODB_postgres64 { $rs = $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr); else $rs = $this->Execute($sql."$limitStr$offsetStr",$inputarr); - + return $rs; } /* @@ -58,7 +58,7 @@ class ADODB_postgres7 extends ADODB_postgres64 { /* I discovered that the MetaForeignKeys method no longer worked for Postgres 8.3. - I went ahead and modified it to work for both 8.2 and 8.3. + I went ahead and modified it to work for both 8.2 and 8.3. Please feel free to include this change in your next release of adodb. William Kolodny [William.Kolodny#gt-t.net] */ @@ -68,15 +68,15 @@ class ADODB_postgres7 extends ADODB_postgres64 { SELECT fum.ftblname AS lookup_table, split_part(fum.rf, ')'::text, 1) AS lookup_field, fum.ltable AS dep_table, split_part(fum.lf, ')'::text, 1) AS dep_field FROM ( - SELECT fee.ltable, fee.ftblname, fee.consrc, split_part(fee.consrc,'('::text, 2) AS lf, + SELECT fee.ltable, fee.ftblname, fee.consrc, split_part(fee.consrc,'('::text, 2) AS lf, split_part(fee.consrc, '('::text, 3) AS rf FROM ( SELECT foo.relname AS ltable, foo.ftblname, pg_get_constraintdef(foo.oid) AS consrc FROM ( SELECT c.oid, c.conname AS name, t.relname, ft.relname AS ftblname - FROM pg_constraint c - JOIN pg_class t ON (t.oid = c.conrelid) + FROM pg_constraint c + JOIN pg_class t ON (t.oid = c.conrelid) JOIN pg_class ft ON (ft.oid = c.confrelid) JOIN pg_namespace nft ON (nft.oid = ft.relnamespace) LEFT JOIN pg_description ds ON (ds.objoid = c.oid) @@ -89,9 +89,9 @@ class ADODB_postgres7 extends ADODB_postgres64 { ORDER BY fum.ftblname, fum.ltable, split_part(fum.lf, ')'::text, 1) "; $rs = $this->Execute($sql); - + if (!$rs || $rs->EOF) return false; - + $a = array(); while (!$rs->EOF) { if ($upper) { @@ -101,11 +101,11 @@ class ADODB_postgres7 extends ADODB_postgres64 { } $rs->MoveNext(); } - + return $a; - + } - + // from Edward Jaramilla, improved version - works on pg 7.4 function _old_MetaForeignKeys($table, $owner=false, $upper=false) { @@ -120,20 +120,20 @@ class ADODB_postgres7 extends ADODB_postgres64 { c.relname = \''.strtolower($table).'\' ORDER BY t.tgrelid'; - + $rs = $this->Execute($sql); - + if (!$rs || $rs->EOF) return false; - + $arr = $rs->GetArray(); $a = array(); foreach($arr as $v) { $data = explode(chr(0), $v['args']); $size = count($data)-1; //-1 because the last node is empty for($i = 4; $i < $size; $i++) { - if ($upper) + if ($upper) $a[strtoupper($data[2])][] = strtoupper($data[$i].'='.$data[++$i]); - else + else $a[$data[2]][] = $data[$i].'='.$data[++$i]; } } @@ -158,7 +158,7 @@ class ADODB_postgres7 extends ADODB_postgres64 { else $sql .= $v.' $'.$i; $i++; } - + $rez = pg_query_params($this->_connectionID,$sql, $inputarr); } else { $rez = pg_query($this->_connectionID,$sql); @@ -170,10 +170,10 @@ class ADODB_postgres7 extends ADODB_postgres64 { } $this->_resultid = $rez; return true; - } + } return $rez; } - + // this is a set of functions for managing client encoding - very important if the encodings // of your database and your output target (i.e. HTML) don't match //for instance, you may have UNICODE database and server it on-site as WIN1251 etc. @@ -191,7 +191,7 @@ class ADODB_postgres7 extends ADODB_postgres64 { return $this->charSet; } } - + // SetCharSet - switch the client encoding function SetCharSet($charset_name) { @@ -205,7 +205,7 @@ class ADODB_postgres7 extends ADODB_postgres64 { } } - + /*-------------------------------------------------------------------------------------- Class Name: Recordset --------------------------------------------------------------------------------------*/ @@ -213,21 +213,21 @@ class ADODB_postgres7 extends ADODB_postgres64 { class ADORecordSet_postgres7 extends ADORecordSet_postgres64{ var $databaseType = "postgres7"; - - - function __construct($queryID,$mode=false) + + + function __construct($queryID,$mode=false) { - parent::__construct($queryID,$mode); + parent::__construct($queryID,$mode); } - + // 10% speedup to move MoveNext to child class - function MoveNext() + function MoveNext() { if (!$this->EOF) { $this->_currentRow++; if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) { $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); - + if (is_array($this->fields)) { if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); return true; @@ -237,43 +237,43 @@ class ADORecordSet_postgres7 extends ADORecordSet_postgres64{ $this->EOF = true; } return false; - } + } } class ADORecordSet_assoc_postgres7 extends ADORecordSet_postgres64{ var $databaseType = "postgres7"; - - - function ADORecordSet_assoc_postgres7($queryID,$mode=false) + + + function ADORecordSet_assoc_postgres7($queryID,$mode=false) { $this->ADORecordSet_postgres64($queryID,$mode); } - + function _fetch() { if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) return false; $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); - + if ($this->fields) { if (isset($this->_blobArr)) $this->_fixblobs(); $this->_updatefields(); } - + return (is_array($this->fields)); } - + // Create associative array function _updatefields() { if (ADODB_ASSOC_CASE == 2) return; // native - + $arr = array(); $lowercase = (ADODB_ASSOC_CASE == 0); - + foreach($this->fields as $k => $v) { if (is_integer($k)) $arr[$k] = $v; else { @@ -285,25 +285,25 @@ class ADORecordSet_assoc_postgres7 extends ADORecordSet_postgres64{ } $this->fields = $arr; } - - function MoveNext() + + function MoveNext() { if (!$this->EOF) { $this->_currentRow++; if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) { $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); - + if (is_array($this->fields)) { if ($this->fields) { if (isset($this->_blobArr)) $this->_fixblobs(); - + $this->_updatefields(); } return true; } } - - + + $this->fields = false; $this->EOF = true; } diff --git a/.tests/tests/vendor-phppgadmin.sh b/.tests/tests/vendor-phppgadmin.sh index f484239e..1750e9d2 100755 --- a/.tests/tests/vendor-phppgadmin.sh +++ b/.tests/tests/vendor-phppgadmin.sh @@ -13,7 +13,7 @@ DVLBOX_PATH="$( cd "${SCRIPT_PATH}/../.." && pwd -P )" . "${SCRIPT_PATH}/../scripts/.lib.sh" RETRIES=10 -DISABLED_VERSIONS=("8.0" "8.1") +DISABLED_VERSIONS=() echo diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6af294f4..5545b6f0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -230,6 +230,20 @@ phpPgAdmin requires some adjustments to work with the Devilbox intranet. See bel + session_start(); + } ``` +`libraries/adodb/drivers/adodb-postgres64.inc.php` +```diff +- function ADODB_postgres64() ++ function __construct() +``` + +`libraries/adodb/drivers/adodb-postgres7.inc.php` +```diff +- function ADODB_postgres7() ++ public function __construct() + { +- $this->ADODB_postgres64(); ++ parent::__construct(); +``` ### Tests