diff options
Diffstat (limited to 'drivers/adodb-postgres64.inc.php')
| -rw-r--r-- | drivers/adodb-postgres64.inc.php | 128 |
1 files changed, 74 insertions, 54 deletions
diff --git a/drivers/adodb-postgres64.inc.php b/drivers/adodb-postgres64.inc.php index c5302e29..4f57af13 100644 --- a/drivers/adodb-postgres64.inc.php +++ b/drivers/adodb-postgres64.inc.php @@ -124,19 +124,40 @@ class ADODB_postgres64 extends ADOConnection{ // to know what the concequences are. The other values are correct (wheren't in 0.94) // -- Freek Dijkstra - function __construct() + /** + * Retrieve Server information. + * In addition to server version and description, the function also returns + * the client version. + * @param bool $detailed If true, retrieve detailed version string (executes + * a SQL query) in addition to the version number + * @return array|bool Server info or false if version could not be retrieved + * e.g. if there is no active connection + */ + function ServerInfo($detailed = true) { - // changes the metaColumnsSQL, adds columns: attnum[6] - } + if (empty($this->version['version'])) { + // We don't have a connection, so we can't retrieve server info + if (!$this->_connectionID) { + return false; + } - function ServerInfo() - { - if (isset($this->version)) return $this->version; + $version = pg_version($this->_connectionID); + $this->version = array( + // If PHP has been compiled with PostgreSQL 7.3 or lower, then + // server version is not set so we use pg_parameter_status() + // which includes logic to obtain values server_version + 'version' => isset($version['server']) + ? $version['server'] + : pg_parameter_status($this->_connectionID, 'server_version'), + 'client' => $version['client'], + 'description' => null, + ); + } + if ($detailed && $this->version['description'] === null) { + $this->version['description'] = $this->GetOne('select version()'); + } - $arr['description'] = $this->GetOne("select version()"); - $arr['version'] = ADOConnection::_findvers($arr['description']); - $this->version = $arr; - return $arr; + return $this->version; } function IfNull( $field, $ifNull ) @@ -249,16 +270,12 @@ class ADODB_postgres64 extends ADOConnection{ if (is_bool($s)) return $s ? 'true' : 'false'; if (!$magic_quotes) { - if (ADODB_PHPVER >= 0x5200 && $this->_connectionID) { - return "'".pg_escape_string($this->_connectionID,$s)."'"; - } - if (ADODB_PHPVER >= 0x4200) { - return "'".pg_escape_string($s)."'"; + if ($this->_connectionID) { + return "'" . pg_escape_string($this->_connectionID, $s) . "'"; } - if ($this->replaceQuote[0] == '\\'){ - $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\\000"),$s); + else { + return "'" . pg_escape_string($s) . "'"; } - return "'".str_replace("'",$this->replaceQuote,$s)."'"; } // undo magic quotes for " @@ -393,7 +410,7 @@ class ADODB_postgres64 extends ADOConnection{ } /* - Hueristic - not guaranteed to work. + Heuristic - not guaranteed to work. */ function GuessOID($oid) { @@ -430,24 +447,20 @@ class ADODB_postgres64 extends ADOConnection{ 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 - backend. - */ + /** + * Encode binary value prior to DB storage. + * + * See https://www.postgresql.org/docs/current/static/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 backend. + * + * @param string $blob + */ 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 + return pg_escape_bytea($this->_connectionID, $blob); } // assumes bytea for blob, and varchar for clob @@ -609,12 +622,12 @@ class ADODB_postgres64 extends ADOConnection{ function Param($name,$type='C') { if ($name) { - $this->_pnum += 1; + $this->_pnum++; } else { // Reset param num if $name is false - $this->_pnum = 1; + $this->_pnum = 0; } - return '$'.$this->_pnum; + return '$' . $this->_pnum; } function MetaIndexes ($table, $primary = FALSE, $owner = false) @@ -729,9 +742,9 @@ class ADODB_postgres64 extends ADOConnection{ 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 + $info = $this->ServerInfo(false); + + if (version_compare($info['version'], '7.1', '>=')) { $this->_nestedSQL = true; } @@ -739,8 +752,11 @@ class ADODB_postgres64 extends ADOConnection{ # PHP does not handle 'hex' properly ('x74657374' is returned as 't657374') # https://bugs.php.net/bug.php?id=59831 states this is in fact not a bug, # so we manually set bytea_output - if ( !empty($this->connection->noBlobs) && version_compare($info['version'], '9.0', '>=')) { - $this->Execute('set bytea_output=escape'); + if (!empty($this->connection->noBlobs) && version_compare($info['version'], '9.0', '>=')) { + $version = pg_version($this->connectionID); + if (version_compare($info['client'], '9.2', '<')) { + $this->Execute('set bytea_output=escape'); + } } return true; @@ -848,20 +864,23 @@ class ADODB_postgres64 extends ADOConnection{ /* Returns: the last error message from previous database operation */ function ErrorMsg() { - if ($this->_errorMsg !== false) return $this->_errorMsg; - if (ADODB_PHPVER >= 0x4300) { - if (!empty($this->_resultid)) { - $this->_errorMsg = @pg_result_error($this->_resultid); - if ($this->_errorMsg) return $this->_errorMsg; + if ($this->_errorMsg !== false) { + return $this->_errorMsg; + } + + if (!empty($this->_resultid)) { + $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(); + if (!empty($this->_connectionID)) { + $this->_errorMsg = @pg_last_error($this->_connectionID); } else { - if (empty($this->_connectionID)) $this->_errconnect(); - else $this->_errorMsg = @pg_errormessage($this->_connectionID); + $this->_errorMsg = $this->_errconnect(); } + return $this->_errorMsg; } @@ -1068,6 +1087,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{ case 'NAME': case 'BPCHAR': case '_VARCHAR': + case 'CIDR': case 'INET': case 'MACADDR': if ($len <= $this->blobSize) return 'C'; @@ -1111,7 +1131,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{ return 'R'; default: - return 'N'; + return ADODB_DEFAULT_METATYPE; } } |
