OCI8 patch to allow cursor resultsets

From: Date: Thu, 01 Aug 2002 23:47:17 +0000
Subject: OCI8 patch to allow cursor resultsets
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-8139@lists.php.net to get a copy of this message
Never done this before, so I don't know if this is the right way, but here goes :) Attached are two text files named for the files affected by the patch, and each one contains the function modified. (Well in the case of oci8.txt a new function). I'll also paste the two functions below this in case the attachments aren't working. Without wanting to get flamed too badly, could someone reply and let me know if this was the right way to go about this? Thanks in advance :) Cheers, Keith. ======= replace in common.php ========= // }}} // {{{ query() /** * Send a query to the database and return any results with a * DB_result object. * * @access public * * @param string $query the SQL query or the statement to prepare * @param string $cursor optional cursor * @param string $params the data to be added to the query * @return mixed a DB_result object or DB_OK on success, a DB * error on failure * * @see DB::isError * @see DB_common::prepare * @see DB_common::execute */ function &query($query, $cursor=null, $params = array()) { if (sizeof($params) > 0) { $sth = $this->prepare($query); if (DB::isError($sth)) { return $sth; } return $this->execute($sth, $params); } else { if(is_null($cursor)) $result = $this->simpleQuery($query); else $result = $this->cursorQuery($query,$cursor); if (DB::isError($result) || $result === DB_OK) { return $result; } else { return new DB_result($this, $result); } } } ======= end common.php changes ======= ========= add to oci8.php =========== // }}} // {{{ cursorQuery() /** * Send a query to oracle and return the results as an oci8 resource * identifier. * * This query type is useful if you are using cursors to return data * from packages/procedures. * * @param $query the SQL query * @param $cursor the cursor name to bind with * * @return int returns a valid oci8 result for successful SELECT * queries, DB_OK for other successful queries. A DB error code * is returned on failure. */ function cursorQuery($query,$cursor) { echo '<h2>$query is:'.$query.' :: $cursor is: '.$cursor.'</h2>'; //declare a cursor $curs=@OCINewCursor($this->connection); if(!$curs){ return $this->oci8RaiseError(); } //parse the SQL to make sure it is valid $result=@OCIParse($this->connection,$query); if(!$result){ return $this->oci8RaiseError(); } //bind the cursor to the parsed SQL OCIBindByName($result,$cursor,&$curs,-1,OCI_B_CURSOR); if($this->autoCommit){ $success=@OCIExecute($result,OCI_COMMIT_ON_SUCCESS); }else{ $success=@OCIExecute($result,OCI_DEFAULT); } if(!$success){ return $this->oci8RaiseError($result); } //now we apply the cursor to the query $success=@OCIExecute($curs); if(!$success){ return $this->oci8RaiseError($curs); } $this->last_stmt=$curs; return $curs; } ======= end oci8.php changes ==========

// }}} // {{{ cursorQuery() /** * Send a query to oracle and return the results as an oci8 resource * identifier. * * This query type is useful if you are using cursors to return data * from packages/procedures. * * @param $query the SQL query * @param $cursor the cursor name to bind with * * @return int returns a valid oci8 result for successful SELECT * queries, DB_OK for other successful queries. A DB error code * is returned on failure. */ function cursorQuery($query,$cursor) { echo '<h2>$query is:'.$query.' :: $cursor is: '.$cursor.'</h2>'; //declare a cursor $curs=@OCINewCursor($this->connection); if(!$curs){ return $this->oci8RaiseError(); } //parse the SQL to make sure it is valid $result=@OCIParse($this->connection,$query); if(!$result){ return $this->oci8RaiseError(); } //bind the cursor to the parsed SQL OCIBindByName($result,$cursor,&$curs,-1,OCI_B_CURSOR); if($this->autoCommit){ $success=@OCIExecute($result,OCI_COMMIT_ON_SUCCESS); }else{ $success=@OCIExecute($result,OCI_DEFAULT); } if(!$success){ return $this->oci8RaiseError($result); } //now we apply the cursor to the query $success=@OCIExecute($curs); if(!$success){ return $this->oci8RaiseError($curs); } $this->last_stmt=$curs; return $curs; } // }}} // {{{ query() /** * Send a query to the database and return any results with a * DB_result object. * * @access public * * @param string $query the SQL query or the statement to prepare * @param string $cursor optional cursor * @param string $params the data to be added to the query * @return mixed a DB_result object or DB_OK on success, a DB * error on failure * * @see DB::isError * @see DB_common::prepare * @see DB_common::execute */ function &query($query, $cursor=null, $params = array()) { if (sizeof($params) > 0) { $sth = $this->prepare($query); if (DB::isError($sth)) { return $sth; } return $this->execute($sth, $params); } else { if(is_null($cursor)) $result = $this->simpleQuery($query); else $result = $this->cursorQuery($query,$cursor); if (DB::isError($result) || $result === DB_OK) { return $result; } else { return new DB_result($this, $result); } } }
« previous php.pear.dev (#8139) next »