From 4740e7dece880f5cda26976ba758fc31c769f231 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Wed, 17 Aug 2005 15:57:50 +0000 Subject: - changed dbal class layout git-svn-id: file:///svn/phpbb/trunk@5193 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/postgres.php | 164 +++-------------------------------------- 1 file changed, 10 insertions(+), 154 deletions(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 5db37d4da0..f16ecff2c6 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -1,7 +1,7 @@ db_connect_id); } - function sql_return_on_error($fail = false) - { - $this->return_on_error = $fail; - } - - function sql_num_queries() - { - return $this->num_queries; - } - function sql_transaction($status = 'begin') { switch ($status) @@ -208,62 +192,6 @@ class sql_db } } - // Idea for this from Ikonboard - function sql_build_array($query, $assoc_ary = false) - { - if (!is_array($assoc_ary)) - { - return false; - } - - $fields = array(); - $values = array(); - if ($query == 'INSERT') - { - foreach ($assoc_ary as $key => $var) - { - $fields[] = $key; - - if (is_null($var)) - { - $values[] = 'NULL'; - } - elseif (is_string($var)) - { - $values[] = "'" . $this->sql_escape($var) . "'"; - } - else - { - $values[] = (is_bool($var)) ? intval($var) : $var; - } - } - - $query = ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $values) . ')'; - } - else if ($query == 'UPDATE' || $query == 'SELECT') - { - $values = array(); - foreach ($assoc_ary as $key => $var) - { - if (is_null($var)) - { - $values[] = "$key = NULL"; - } - elseif (is_string($var)) - { - $values[] = "$key = '" . $this->sql_escape($var) . "'"; - } - else - { - $values[] = (is_bool($var)) ? "$key = " . intval($var) : "$key = $var"; - } - } - $query = implode(($query == 'UPDATE') ? ', ' : ' AND ', $values); - } - - return $query; - } - // Other query methods // // NOTE :: Want to remove _ALL_ reliance on sql_numrows from core code ... @@ -370,7 +298,7 @@ class sql_db { if (empty($this->row[$query_id]) && empty($this->rowset[$query_id])) { - if ($this->sql_fetchrow($query_id)) + if ($this->row[$query_id] = $this->sql_fetchrow($query_id)) { $result = $this->row[$query_id][$field]; } @@ -464,70 +392,23 @@ class sql_db return str_replace("'", "''", str_replace('\\', '\\\\', $msg)); } - function sql_error($sql = '') + function db_sql_error() { - if (!$this->return_on_error) - { - $this_page = (isset($_SERVER['PHP_SELF']) && !empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']; - $this_page .= '&' . ((isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : (isset($_ENV['QUERY_STRING']) ? $_ENV['QUERY_STRING'] : '')); - - $message = 'SQL ERROR [ ' . SQL_LAYER . ' ]

' . @pg_errormessage() . '

CALLING PAGE

' . htmlspecialchars($this_page) . (($sql != '') ? '

SQL

' . $sql : '') . '
'; - - if ($this->transaction) - { - $this->sql_transaction('rollback'); - } - - trigger_error($message, E_USER_ERROR); - } - - $result = array( + return array( 'message' => @pg_errormessage(), 'code' => '' ); - - return $result; } - function sql_report($mode, $query = '') + function _sql_report($mode, $query = '') { - if (empty($_GET['explain'])) - { - return; - } - global $cache, $starttime, $phpbb_root_path; static $curtime, $query_hold, $html_hold; static $sql_report = ''; static $cache_num_queries = 0; - if (!$query && !empty($query_hold)) - { - $query = $query_hold; - } - switch ($mode) { - case 'display': - if (!empty($cache)) - { - $cache->unload(); - } - $this->sql_close(); - - $mtime = explode(' ', microtime()); - $totaltime = $mtime[0] + $mtime[1] - $starttime; - - echo '' . $msg_title . ''; - echo '
phpBB LogoSQL Report      

Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries} queries" . (($cache_num_queries) ? " + $cache_num_queries " . (($cache_num_queries == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '
Time spent on MySQL queries: ' . round($this->sql_time, 5) . 's | Time spent on PHP: ' . round($totaltime - $this->sql_time, 5) . 's
'; - echo $sql_report; - echo '

'; - exit; - break; - case 'start': $query_hold = $query; $html_hold = ''; @@ -562,35 +443,10 @@ class sql_db @pg_freeresult($result); $cache_num_queries++; break; - - case 'stop': - $endtime = explode(' ', microtime()); - $endtime = $endtime[0] + $endtime[1]; - - $sql_report .= '

Query #' . $this->num_queries . '
' . $html_hold . '

'; - - if ($this->query_result) - { - if (preg_match('/^(UPDATE|DELETE|REPLACE)/', $query)) - { - $sql_report .= "Affected rows: " . $this->sql_affectedrows($this->query_result) . ' | '; - } - $sql_report .= 'Before: ' . sprintf('%.5f', $curtime - $starttime) . 's | After: ' . sprintf('%.5f', $endtime - $starttime) . 's | Elapsed: ' . sprintf('%.5f', $endtime - $curtime) . 's'; - } - else - { - $error = $this->sql_error(); - $sql_report .= 'FAILED - ' . SQL_LAYER . ' Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']); - } - - $sql_report .= '

'; - - $this->sql_time += $endtime - $curtime; - break; } } -} // class ... db_sql +} } // if ... defined -- cgit v1.2.1