diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2005-10-07 23:00:41 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2005-10-07 23:00:41 +0000 |
commit | 913c38768a21901187d2ded9427b3e2e533206f4 (patch) | |
tree | 7480cbd098b54782134f2f166573f56a585b8074 /phpBB/includes/db/oracle.php | |
parent | 8d72671cc1c983dcafac6948f07ac3cf7447c93c (diff) | |
download | forums-913c38768a21901187d2ded9427b3e2e533206f4.tar forums-913c38768a21901187d2ded9427b3e2e533206f4.tar.gz forums-913c38768a21901187d2ded9427b3e2e533206f4.tar.bz2 forums-913c38768a21901187d2ded9427b3e2e533206f4.tar.xz forums-913c38768a21901187d2ded9427b3e2e533206f4.zip |
- another try to break things. :)
- adjusted the dbal a little bit
- removed db2 support
git-svn-id: file:///svn/phpbb/trunk@5263 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/db/oracle.php')
-rw-r--r-- | phpBB/includes/db/oracle.php | 198 |
1 files changed, 85 insertions, 113 deletions
diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index e281140b73..d51c928f5e 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -25,6 +25,9 @@ class dbal_oracle extends dbal { var $last_query_text = ''; + /** + * Connect to server + */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false) { $this->persistency = $persistency; @@ -37,32 +40,9 @@ class dbal_oracle extends dbal return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); } - // - // Other base methods - // - function sql_close() - { - if (!$this->db_connect_id) - { - return false; - } - - if ($this->transaction) - { - @ocicommit($this->db_connect_id); - } - - if (sizeof($this->open_queries)) - { - foreach ($this->open_queries as $i_query_id => $query_id) - { - @ocifreestatement($query_id); - } - } - - return @ocilogoff($this->db_connect_id); - } - + /** + * sql transaction + */ function sql_transaction($status = 'begin') { switch ($status) @@ -94,7 +74,9 @@ class dbal_oracle extends dbal return $result; } - // Base query method + /** + * Base query method + */ function sql_query($query = '', $cache_ttl = 0) { if ($query != '') @@ -168,6 +150,9 @@ class dbal_oracle extends dbal return ($this->query_result) ? $this->query_result : false; } + /** + * Build LIMIT query + */ function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { if ($query != '') @@ -184,10 +169,10 @@ class dbal_oracle extends dbal } } - // Other query methods - // - // NOTE :: Want to remove _ALL_ reliance on sql_numrows from core code ... - // don't want this here by a middle Milestone + /** + * Return number of rows + * Not used within core code + */ function sql_numrows($query_id = false) { if (!$query_id) @@ -196,6 +181,7 @@ class dbal_oracle extends dbal } $result = @ocifetchstatement($query_id, $this->rowset); + // OCIFetchStatment kills our query result so we have to execute the statment again // if we ever want to use the query_id again. @ociexecute($query_id, OCI_DEFAULT); @@ -203,13 +189,17 @@ class dbal_oracle extends dbal return $result; } + /** + * Return number of affected rows + */ function sql_affectedrows() { - $query_id = $this->query_result; - - return ($query_id) ? @ocirowcount($query_id) : false; + return ($this->query_result) ? @ocirowcount($this->query_result) : false; } + /** + * Fetch current row + */ function sql_fetchrow($query_id = false) { global $cache; @@ -243,12 +233,15 @@ class dbal_oracle extends dbal $result_row[strtolower($key)] = $value; } - $this->row[$query_id] = $result_row; - return $this->row[$query_id]; + return ($query_id) ? $result_row : false; } - function sql_fetchrowset($query_id = false) + /** + * Fetch field + * if rownum is false, the current row is used, else it is pointing to the row (zero-based) + */ + function sql_fetchfield($field, $rownum = false, $query_id = false) { if (!$query_id) { @@ -257,78 +250,52 @@ class dbal_oracle extends dbal if ($query_id) { - unset($this->rowset[$query_id]); - unset($this->row[$query_id]); - - $result = array(); - while ($this->rowset[$query_id] = $this->sql_fetchrow($query_id)) + if ($rownum !== false) { - $result[] = $this->rowset[$query_id]; + $this->sql_rowseek($rownum, $query_id); } - return $result; + + $row = $this->sql_fetchrow($query_id); + return isset($row[$field]) ? $row[$field] : false; } return false; } - function sql_fetchfield($field, $rownum = -1, $query_id = false) + /** + * Seek to given row number + * rownum is zero-based + */ + function sql_rowseek($rownum, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } - if ($query_id) - { - if ($rownum > -1) - { - // Reset the internal rownum pointer. - @ociexecute($query_id, OCI_DEFAULT); - for ($i = 0; $i < $rownum; $i++) - { - // Move the interal pointer to the row we want - @ocifetch($query_id); - } - - // Get the field data. - $result = @ociresult($query_id, strtoupper($field)); - } - else - { - // The internal pointer should be where we want it - // so we just grab the field out of the current row. - $result = @ociresult($query_id, strtoupper($field)); - } - - return $result; - } - - return false; - } - - function sql_rowseek($rownum, $query_id = false) - { if (!$query_id) { - $query_id = $this->query_result; + return false; } - if ($query_id) - { - @ociexecute($query_id, OCI_DEFAULT); + // Reset internal pointer + @ociexecute($query_id, OCI_DEFAULT); - for ($i = 0; $i < $rownum; $i++) + // We do not fetch the row for rownum == 0 because then the next resultset would be the second row + for ($i = 0; $i < $rownum; $i++) + { + if (!$this->sql_fetchrow($query_id)) { - @ocifetch($query_id); + return false; } - $result = @ocifetch($query_id); - - return $result; } - - return false; + + return true; } + /** + * Get last inserted id after insert statement + */ function sql_nextid() { $query_id = $this->query_result; @@ -339,9 +306,10 @@ class dbal_oracle extends dbal { $query = 'SELECT ' . $tablename[1] . '_id_seq.currval FROM DUAL'; $stmt = @ociparse($this->db_connect_id, $query); - @ociexecute($stmt,OCI_DEFAULT ); + @ociexecute($stmt, OCI_DEFAULT ); $temp_result = @ocifetchinto($stmt, $temp_result, OCI_ASSOC + OCI_RETURN_NULLS); + @ocifreestatement($stmt); if ($temp_result) { @@ -357,6 +325,9 @@ class dbal_oracle extends dbal return false; } + /** + * Free sql result + */ function sql_freeresult($query_id = false) { if (!$query_id) @@ -373,12 +344,19 @@ class dbal_oracle extends dbal return false; } + /** + * Escape string used in sql query + */ function sql_escape($msg) { return str_replace("'", "''", str_replace('\\', '\\\\', $msg)); } - function db_sql_error() + /** + * return sql error array + * @private + */ + function _sql_error() { $error = @ocierror(); $error = (!$error) ? @ocierror($this->query_result) : $error; @@ -396,22 +374,25 @@ class dbal_oracle extends dbal return $error; } - function _sql_report($mode, $query = '') + /** + * Close sql connection + * @private + */ + function _sql_close() { - global $cache, $starttime, $phpbb_root_path; - static $curtime, $query_hold, $html_hold; - static $sql_report = ''; - static $cache_num_queries = 0; + return @ocilogoff($this->db_connect_id); + } + /** + * Build db-specific report + * @private + */ + function _sql_report($mode, $query = '') + { switch ($mode) { case 'start': - $query_hold = $query; - $html_hold = ''; - - $curtime = explode(' ', microtime()); - $curtime = $curtime[0] + $curtime[1]; - break; + break; case 'fromcache': $endtime = explode(' ', microtime()); @@ -421,27 +402,18 @@ class dbal_oracle extends dbal $success = @ociexecute($result, OCI_DEFAULT); $row = array(); - while ($void = @ocifetchinto($query_id, $row, OCI_ASSOC + OCI_RETURN_NULLS)) + while (@ocifetchinto($query_id, $row, OCI_ASSOC + OCI_RETURN_NULLS)) { // Take the time spent on parsing rows into account } + @ocifreestatement($result); + $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; - $time_cache = $endtime - $curtime; - $time_db = $splittime - $endtime; - $color = ($time_db > $time_cache) ? 'green' : 'red'; - - $sql_report .= '<hr width="100%"/><br /><table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0"><tr><th>Query results obtained from the cache</th></tr><tr><td class="row1"><textarea style="font-family:\'Courier New\',monospace;width:100%" rows="5">' . preg_replace('/\t(AND|OR)(\W)/', "\$1\$2", htmlspecialchars(preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n", $query))) . '</textarea></td></tr></table><p align="center">'; - - $sql_report .= 'Before: ' . sprintf('%.5f', $curtime - $starttime) . 's | After: ' . sprintf('%.5f', $endtime - $starttime) . 's | Elapsed [cache]: <b style="color: ' . $color . '">' . sprintf('%.5f', ($time_cache)) . 's</b> | Elapsed [db]: <b>' . sprintf('%.5f', $time_db) . 's</b></p>'; + $this->sql_report('record_fromcache', $query, $endtime, $splittime); - // Pad the start time to not interfere with page timing - $starttime += $time_db; - - @ocifreestatement($result); - $cache_num_queries++; - break; + break; } } |