diff options
author | git-marijus <mario@mariovavti.com> | 2018-02-06 12:48:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-06 12:48:34 +0100 |
commit | 24a650d7ecc07e46a7d7cfb1ef3cd60cc7da791b (patch) | |
tree | 2a782957d6340dd0135eba8ca2db661827821d54 /include/dba/dba_postgres.php | |
parent | cb042e32bc6d521050c48a5e4fe6c74f7a33ed4f (diff) | |
parent | 210c91398da573d3c44bd1ff5bee4c65128c8686 (diff) | |
download | volse-hubzilla-24a650d7ecc07e46a7d7cfb1ef3cd60cc7da791b.tar.gz volse-hubzilla-24a650d7ecc07e46a7d7cfb1ef3cd60cc7da791b.tar.bz2 volse-hubzilla-24a650d7ecc07e46a7d7cfb1ef3cd60cc7da791b.zip |
Merge pull request #971 from dawnbreak/QA_testing
UnitTests for database classes and bit cleanup and docu
Diffstat (limited to 'include/dba/dba_postgres.php')
-rw-r--r-- | include/dba/dba_postgres.php | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/include/dba/dba_postgres.php b/include/dba/dba_postgres.php deleted file mode 100644 index 560d8da60..000000000 --- a/include/dba/dba_postgres.php +++ /dev/null @@ -1,117 +0,0 @@ -<?php - -require_once('include/dba/dba_driver.php'); - - -class dba_postgres extends dba_driver { - const INSTALL_SCRIPT='install/schema_postgres.sql'; - const NULL_DATE = '0001-01-01 00:00:00'; - const UTC_NOW = "now() at time zone 'UTC'"; - const TQUOT = '"'; - - function connect($server,$scheme,$port,$user,$pass,$db) { - if(!$port) $port = 5432; - $connstr = 'host=' . $server . ' port='.$port . ' user=' . $user . ' password=' . $pass . ' dbname='. $db; - $this->db = pg_connect($connstr); - if($this->db !== false) { - $this->connected = true; - } else { - $this->connected = false; - } - $this->q("SET standard_conforming_strings = 'off'; SET backslash_quote = 'on';"); // emulate mysql string escaping to prevent massive code-clobber - return $this->connected; - } - - function q($sql) { - if((! $this->db) || (! $this->connected)) - return false; - - if(!strpos($sql, ';')) - $sql .= ';'; - - if(strpos($sql, '`')) // this is a hack. quoted identifiers should be replaced everywhere in the code with dbesc_identifier(), remove this once it is - $sql = str_replace('`', '"', $sql); - - $this->error = ''; - $result = @pg_query($this->db, $sql); - if(file_exists('db-allqueries.out')) { - $bt = debug_backtrace(); - $trace = array(); - foreach($bt as $frame) { - if(!empty($frame['file']) && @strstr($frame['file'], $_SERVER['DOCUMENT_ROOT'])) - $frame['file'] = substr($frame['file'], strlen($_SERVER['DOCUMENT_ROOT'])+1); - - $trace[] = $frame['file'] . ':' . $frame['function'] . '():' . $frame['line'] ; - } - $compact = join(', ', $trace); - file_put_contents('db-allqueries.out', datetime_convert() . ": " . $sql . ' is_resource: '.var_export(is_resource($result), true).', backtrace: '.$compact."\n\n", FILE_APPEND); - } - - if($result === false) - $this->error = pg_last_error($this->db); - - if($result === false || $this->error) { - //db_logger('dba_postgres: ' . printable($sql) . ' returned false.' . "\n" . $this->error); - if(file_exists('dbfail.out')) - file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); - } - - if(($result === true) || ($result === false)) - return $result; - - if(pg_result_status($result) == PGSQL_COMMAND_OK) - return true; - - $r = array(); - if(pg_num_rows($result)) { - while($x = pg_fetch_array($result, null, PGSQL_ASSOC)) - $r[] = $x; - pg_free_result($result); - if($this->debug) - db_logger('dba_postgres: ' . printable(print_r($r,true))); - } - return $r; - } - - function escape($str) { - if($this->db && $this->connected) { - $x = @pg_escape_string($this->db, $str); - return $x; - } - } - - function escapebin($str) { - return pg_escape_bytea($str); - } - - function unescapebin($str) { - return pg_unescape_bytea($str); - } - - function close() { - if($this->db) - pg_close($this->db); - $this->connected = false; - } - - function quote_interval($txt) { - return "'$txt'"; - } - - function escape_identifier($str) { - return pg_escape_identifier($this->db, $str); - } - - function optimize_table($table) { - // perhaps do some equivalent thing here, vacuum, etc? I think this is the DBA's domain anyway. Applications should not need to muss with this. - // for now do nothing without a compelling reason. function overrides default legacy mysql. - } - - function concat($fld, $sep) { - return 'string_agg(' . $fld . ',\'' . $sep . '\')'; - } - - function getdriver() { - return 'pgsql'; - } -}
\ No newline at end of file |