cvs: pear /MDB/MDB oci8.php /MDB/MDB/Modules/Manager oci8.php

From: Date: Sat, 01 Feb 2003 18:26:12 +0000
Subject: cvs: pear /MDB/MDB oci8.php /MDB/MDB/Modules/Manager oci8.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-8644@lists.php.net to get a copy of this message
lsmith Sat Feb 1 13:26:12 2003 EDT Modified files: /pear/MDB/MDB/Modules/Manager oci8.php /pear/MDB/MDB oci8.php Log: fixed countless errors still has the following issues: - connect as DBA on oracle 9i - isResultNull() does not work (doesn't work on Metabase either) - selectedRowRange - ondemand sequence creation in nextId() - lob storage

Index: pear/MDB/MDB/Modules/Manager/oci8.php diff -u pear/MDB/MDB/Modules/Manager/oci8.php:1.4 pear/MDB/MDB/Modules/Manager/oci8.php:1.5 --- pear/MDB/MDB/Modules/Manager/oci8.php:1.4 Sun Jan 19 06:12:00 2003 +++ pear/MDB/MDB/Modules/Manager/oci8.php Sat Feb 1 13:26:12 2003 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.4 2003/01/19 11:12:00 lsmith Exp $ +// $Id: oci8.php,v 1.5 2003/02/01 18:26:12 lsmith Exp $ if (!defined('MDB_MANAGER_OCI8_INCLUDED')) { define('MDB_MANAGER_OCI8_INCLUDED', 1); @@ -70,6 +70,7 @@ */ function createDatabase(&$db, $name) { +return(MDB_OK); $user = $db->getOption('DBAUser'); if (MDB::isError($user)) { return($db->raiseError(MDB_ERROR_INSUFFICIENT_DATA, '', '', 'Create database', @@ -80,27 +81,27 @@ return($db->raiseError(MDB_ERROR_INSUFFICIENT_DATA, '', '', 'Create database', 'it was not specified the Oracle DBAPassword option')); } - if (MDB::isError($db->connect($user, $password, 0))) { + if (!MDB::isError($result = $db->connect($user, $password, 0))) { $tablespace = $db->getOption('DefaultTablespace'); if(MDB::isError($tablespace)) { $tablespace = ''; } else { $tablespace = ' DEFAULT TABLESPACE '.$tablespace; } - if ($db->_doQuery('CREATE USER '.$db->user.' IDENTIFIED BY '.$db->password.$tablespace)) { - if (MDB::isError($result = $db->_doQuery('GRANT CREATE SESSION, CREATE TABLE,UNLIMITED TABLESPACE,CREATE SEQUENCE TO '.$db->user))) { + if (!MDB::isError($result = $db->_doQuery('CREATE USER '.$db->user.' IDENTIFIED BY '.$db->password.$tablespace))) { + if (!MDB::isError($result = $db->_doQuery('GRANT CREATE SESSION, CREATE TABLE,UNLIMITED TABLESPACE,CREATE SEQUENCE TO '.$db->user))) { + return(MDB_OK); + } else { if (MDB::isError($result2 = $db->_doQuery('DROP USER '.$db->user.' CASCADE'))) { - return($db->raiseError(MDB_Error, '','', 'Create database', + return($db->raiseError(MDB_ERROR, '','', 'Create database', 'could not setup the database user ('.$result->getUserinfo().') and then could drop its records ('.$result2->getUserinfo().')')); } - return($db->raiseError(MDB_Error, '','', 'Create database', + return($db->raiseError(MDB_ERROR, '','', 'Create database', 'could not setup the database user ('.$result->getUserinfo().')')); - } else { - return(MDB_OK); } } } - return($db->raiseError()); + return($result); } // }}} @@ -264,8 +265,8 @@ $query .= key($fields); } $query .= ')'; - if (!$db->query("ALTER TABLE $name $query")) { - return($db->raiseError()); + if (MDB::isError($result = $db->query("ALTER TABLE $name $query"))) { + return($result); } $query = ''; } @@ -322,6 +323,29 @@ } return(MDB_OK); } + return($db->raiseError()); + } + + // }}} + // {{{ listDatabases() + + /** + * list all databases + * + * @param object $db database object that is extended by this class + * @return mixed data array on success, a MDB error on failure + * @access public + */ + function listDatabases(&$db) + { + $this->queryCol("SELECT table_name, tablespace_name FROM user_tables"); + $result = array(); + for ($i=0; $this->next_record(); $i++) { + $result[$i]["table_name"] = $this->m_record["table_name"]; + $result[$i]["tablespace_name"] = $this->m_record["tablespace_name"]; + $result[$i]["database"] = $this->m_database; + } + return($result); } // }}} @@ -338,7 +362,8 @@ */ function createSequence(&$db, $seq_name, $start) { - return($db->query("CREATE SEQUENCE $seq_name START WITH $start INCREMENT BY 1".($start < 1 ? " MINVALUE $start" : ''))); + $sequence_name = $db->getSequenceName($seq_name); + return($db->query("CREATE SEQUENCE $sequence_name START WITH $start INCREMENT BY 1".($start < 1 ? " MINVALUE $start" : ''))); } // }}} @@ -354,7 +379,8 @@ */ function dropSequence(&$db, $seq_name) { - return($db->query("DROP SEQUENCE $seq_name")); + $sequence_name = $db->getSequenceName($seq_name); + return($db->query("DROP SEQUENCE $sequence_name")); } } Index: pear/MDB/MDB/oci8.php diff -u pear/MDB/MDB/oci8.php:1.6 pear/MDB/MDB/oci8.php:1.7 --- pear/MDB/MDB/oci8.php:1.6 Sun Jan 19 06:12:00 2003 +++ pear/MDB/MDB/oci8.php Sat Feb 1 13:26:12 2003 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.6 2003/01/19 11:12:00 lsmith Exp $ +// $Id: oci8.php,v 1.7 2003/02/01 18:26:12 lsmith Exp $ if (!defined('MDB_OCI8_INCLUDED')) { define('MDB_OCI8_INCLUDED', 1); @@ -63,10 +63,6 @@ var $escape_quotes = "'"; - var $manager_class_name = 'MDB_Manager_oci8'; - var $manager_include = 'MDB/Manager/oci8.php'; - var $manager_included_constant = 'MDB_MANAGER_OCI8_INCLUDED'; - var $auto_commit = 1; var $uncommitedqueries = 0; @@ -282,8 +278,8 @@ if($persistent === NULL) { $persistent = $this->persistent; } - if (isset($this->options['SID'])) { - $sid = $this->options['SID']; + if (isset($this->host)) { + $sid = $this->host; } else { $sid = getenv('ORACLE_SID'); } @@ -406,7 +402,7 @@ { $position = key($this->blobs[$prepared_query]); if (!@OCIBindByName($statement, ':blob'.$position, $descriptors[$position], -1, OCI_B_BLOB)) { - $success = $this->oci8RaiseError(MDB_ERROR, '', '', + $success = $this->oci8RaiseError(NULL, 'Do query: Could not bind blob upload descriptor'); break; } @@ -430,7 +426,7 @@ $value.= $data; } if (!MDB::isError($success) && !$descriptors[$position]->save($value)) { - $success = $this->oci8RaiseError(MDB_ERROR, '', '', + $success = $this->oci8RaiseError(NULL, 'Do query: Could not upload clob data'); } } @@ -446,7 +442,7 @@ $value.= $data; } if (!MDB::isError($success) && !$descriptors[$position]->save($value)) { - $success = $this->oci8RaiseError(MDB_ERROR, '', '', + $success = $this->oci8RaiseError(NULL, 'Do query: Could not upload blob data'); } } @@ -456,12 +452,12 @@ if ($lobs) { if (MDB::isError($success)) { if (!@OCIRollback($this->connection)) { - $success = $this->oci8RaiseError(MDB_ERROR, '', '', + $success = $this->oci8RaiseError(NULL, 'Do query: '.$success->getUserinfo().' and then could not rollback LOB updating transaction'); } } else { if (!@OCICommit($this->connection)) { - $success = $this->oci8RaiseError(MDB_ERROR, '', '', + $success = $this->oci8RaiseError(NULL, 'Do query: Could not commit pending LOB updating transaction'); } } @@ -487,7 +483,7 @@ $result = $statement; } } else { - return($this->oci8RaiseError(NULL, 'Do query: Could not execute query')); + return($this->oci8RaiseError($statement, 'Do query: Could not execute query')); } } } else { @@ -524,7 +520,19 @@ if (MDB::isError($connect = $this->connect())) { return($connect); } - return($this->_doQuery($query, $first, $limit)); + if(!MDB::isError($result = $this->_doQuery($query, $first, $limit))) { + if ($types != NULL) { + if (!is_array($types)) { + $types = array($types); + } + if (MDB::isError($err = $this->setResultTypes($result, $types))) { + $this->freeResult($result); + return($err); + } + } + return($result); + } + return($this->oci8RaiseError()); } // }}} @@ -553,7 +561,7 @@ } // }}} - // {{{ _skipFirstRows() + // {{{ _skipLimitOffset() /** * Skip the first row of a result set. @@ -562,7 +570,7 @@ * @return mixed a result handle or MDB_OK on success, a MDB error on failure * @access private */ - function _skipFirstRows($result) + function _skipLimitOffset($result) { $result_value = intval($result); $first = $this->limits[$result_value][0]; @@ -576,14 +584,24 @@ return(MDB_OK); } + // }}} + // {{{ _getColumn() + /** + * Get key for a given field with a result set. + * + * @param resource $result + * @param mixed $field integer or string key for the column + * @return mixed column from the result handle or a MDB error on failure + * @access private + */ function _getColumn($result, $field) { $result_value = intval($result); - if (MDB::isError($this->getColumnNames($result,$column_names))) { + if (MDB::isError($names = $this->getColumnNames($result))) { return($names); } - if (getType($field) == 'integer') { + if (gettype($field) == 'integer') { if (($column = $field) < 0 || $column >= count($this->columns[$result_value])) { @@ -628,12 +646,11 @@ if (!isset($this->columns[$result_value])) { $this->columns[$result_value] = array(); $columns = @OCINumCols($result); - for($column = 0;$column < $columns;$column++) { + for($column = 0; $column < $columns; $column++) { $this->columns[$result_value][strtolower(@OCIColumnName($result, $column + 1))] = $column; } } - $column_names = $this->columns[$result_value]; - return(MDB_OK); + return($this->columns[$result_value]); } // }}} @@ -677,20 +694,20 @@ return($this->highest_fetched_row[$result_value] >= $this->rows[$result_value]-1); } if (isset($this->row_buffer[$result_value])) { - return($this->raiseError()); + return(FALSE); } if (isset($this->limits[$result_value])) { - if (MDB::isError($this->_skipFirstRows($result)) || $this->current_row[$result_value] + 1 >= $this->limits[$result_value][1]) { + if (MDB::isError($this->_skipLimitOffset($result)) || $this->current_row[$result_value] + 1 >= $this->limits[$result_value][1]) { $this->rows[$result_value] = 0; - return(MDB_OK); + return(TRUE); } } if (@OCIFetchInto($result, $this->row_buffer[$result_value])) { - return($this->raiseError()); + return(FALSE); } unset($this->row_buffer[$result_value]); $this->rows[$result_value] = $this->current_row[$result_value] + 1; - return(MDB_OK); + return(TRUE); } // }}} @@ -714,10 +731,10 @@ $result = $this->lobs[$lob]['Result']; $row = $this->lobs[$lob]['Row']; $field = $this->lobs[$lob]['Field']; - $lob_object = $this->fetchResult($result, $row, $field); + $lob_object = $this->fetch($result, $row, $field); if (gettype($lob_object) != 'object') { if (($column = $this->_getColumn($result, $field)) == -1) { - return($this->raiseError()); + return($column); } if (isset($this->results[intval($result)][$row][$column])) { return($this->raiseError(MDB_ERROR, '', '', @@ -750,11 +767,13 @@ if (MDB::isError($column = $this->_getColumn($result, $field))) { return($column); } + if (MDB::isError($fetchinto = $this->fetchInto($result, MDB_FETCHMODE_ORDERED, $row))) { - return($fetchInto); + return($fetchinto); } + if (!isset($this->results[$result_value][$row][$column])) { - return($this->raiseError()); + return(NULL); } $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $row); return($this->results[$result_value][$row][$column]); @@ -775,7 +794,7 @@ */ function fetchClob($result, $row, $field) { - return($this->fetchLOBResult($result, $row, $field)); + return($this->fetchLOB($result, $row, $field)); } // }}} // {{{ fetchBlob() @@ -790,7 +809,7 @@ */ function fetchBlob($result, $row, $field) { - return($this->fetchLOBResult($result, $row, $field)); + return($this->fetchLOB($result, $row, $field)); } // }}} @@ -834,21 +853,17 @@ { switch ($type) { case MDB_TYPE_BOOLEAN: - $value = (strcmp($value, 'Y') ? 0 : 1); - return(MDB_OK); + return(strcmp($value, 'Y') ? 0 : 1); case MDB_TYPE_DECIMAL: - return(MDB_OK); + return(str_replace(',', '.', $value)); case MDB_TYPE_FLOAT: - $value = doubleval($value); - return(MDB_OK); + return(doubleval(str_replace(',', '.', $value))); case MDB_TYPE_DATE: - $value = substr($value, 0, strlen('YYYY-MM-DD')); - return(MDB_OK); + return(substr($value, 0, strlen('YYYY-MM-DD'))); case MDB_TYPE_TIME: - $value = substr($value, strlen('YYYY-MM-DD '), strlen('HH:MI:SS')); - return(MDB_OK); + return(substr($value, strlen('YYYY-MM-DD '), strlen('HH:MI:SS'))); case MDB_TYPE_TIMESTAMP: - return(MDB_OK); + return($value); default: return($this->baseConvertResult($value, $type)); } @@ -872,11 +887,11 @@ 'Number of rows: attemped to obtain the number of rows contained in an unknown query result')); } if (!isset($this->rows[$result_value])) { - if (MDB::isError($getcolumnnames = $this->getColumnNames($result, $column_names))) { + if (MDB::isError($getcolumnnames = $this->getColumnNames($result))) { return($getcolumnnames); } if (isset($this->limits[$result_value])) { - if (MDB::isError($skipfirstrow = $this->_skipFirstRows($result))) { + if (MDB::isError($skipfirstrow = $this->_skipLimitOffset($result))) { $this->rows[$result_value] = 0; return($skipfirstrow); } @@ -914,14 +929,30 @@ return($this->raiseError(MDB_ERROR, '', '', 'Free result: attemped to free an unknown query result')); } - unset($this->highest_fetched_row[$result_value]); - unset($this->row_buffer[$result_value]); - unset($this->limits[$result_value]); - unset($this->current_row[$result_value]); - unset($this->results[$result_value]); - unset($this->columns[$result_value]); - unset($this->rows[$result_value]); - unset($this->result_types[$result]); + if(isset($this->highest_fetched_row[$result])) { + unset($this->highest_fetched_row[$result]); + } + if(isset($this->row_buffer[$result_value])) { + unset($this->row_buffer[$result_value]); + } + if(isset($this->limits[$result_value])) { + unset($this->limits[$result_value]); + } + if(isset($this->current_row[$result_value])) { + unset($this->current_row[$result_value]); + } + if(isset($this->results[$result_value])) { + unset($this->results[$result_value]); + } + if(isset($this->columns[$result])) { + unset($this->columns[$result]); + } + if(isset($this->rows[$result_value])) { + unset($this->rows[$result_value]); + } + if(isset($this->result_types[$result])) { + unset($this->result_types[$result]); + } return(@OCIFreeCursor($result)); } @@ -1435,7 +1466,7 @@ $repeat = 0; do { $this->expectError(MDB_ERROR_NOSUCHTABLE); - $result = $this->_doQuery("SELECT ${sequence_name}.nextval FROM dual"); + $result = $this->_doQuery("SELECT ${sequence_name}.nextval FROM dual", 0, 0); $this->popExpect(); if ($ondemand && MDB::isError($result) && $result->getCode() == MDB_ERROR_NOSUCHTABLE) { @@ -1451,7 +1482,7 @@ if (MDB::isError($result)) { return($this->raiseError($result)); } - return($db->fetchOne($result, 'integer', DB_FETCHMODE_ORDERED)); + return($this->fetchOne($result, 'integer')); } // }}} @@ -1466,14 +1497,17 @@ * @return int data array on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = 0) + function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = NULL) { $result_value = intval($result); if(!isset($this->current_row[$result_value])) { return($this->raiseError('Fetch row: attempted to fetch a row from an unknown query result')); } + if($rownum == NULL) { + $rownum = $this->highest_fetched_row[$result_value]+1; + } if(isset($this->results[$result_value][$rownum])) { - return($this->raiseError()); + return($this->results[$result_value][$rownum]); } if(isset($this->rows[$result_value])) { return($this->raiseError('Fetch row: there are no more rows to retrieve')); @@ -1482,8 +1516,11 @@ if($rownum >= $this->limits[$result_value][1]) { return($this->raiseError('Fetch row: attempted to fetch a row beyhond the number rows available in the query result')); } - if(!MDB::isError($this->_skipFirstRows($result))) { - return(MDB_OK); + if(!MDB::isError($this->_skipLimitOffset($result))) { + if($this->options['autofree']) { + $this->freeResult($result); + } + return(NULL); } } if(isset($this->row_buffer[$result_value])) { @@ -1491,7 +1528,7 @@ $this->results[$result_value][$this->current_row[$result_value]] = $this->row_buffer[$result_value]; unset($this->row_buffer[$result_value]); } - for(;$this->current_row[$result_value] < $row; + for(;$this->current_row[$result_value] < $rownum; $this->current_row[$result_value]++) { if ($fetchmode & MDB_FETCHMODE_ASSOC) {
« previous php.pear.cvs (#8644) next »