Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.0b5

Request #3644 Abstract way to execute stored procedures
Submitted: 2005-02-28 18:52 UTC
From: nrf Assigned: lsmith
Status: Closed Package: MDB2
PHP Version: 5.0.3 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2005-02-28 18:52 UTC] nrf
Description: ------------ This patch adds MDB2_Driver_Common::executeStoredProc() and implements it for mssql and pgsql. It provides an abstract way to execute a stored procedure. Reproduce code: --------------- Index: MDB2.php =================================================================== RCS file: /repository/pear/MDB2/MDB2.php,v retrieving revision 1.81 diff -u -r1.81 MDB2.php --- MDB2.php 22 Feb 2005 09:51:18 -0000 1.81 +++ MDB2.php 28 Feb 2005 17:32:24 -0000 @@ -1765,6 +1765,29 @@ } // }}} + // {{{ executeStoredProc() + + /** + * Execute a stored procedure and return any results + * + * @param string $name string that identifies the function to execute + * @param mixed $params array that contains the paramaters to pass the stored proc + * @param mixed $types array that contains the types of the columns in + * the result set + * @param mixed $result_class string which specifies which result class to use + * @param mixed $result_wrap_class string which specifies which class to wrap results in + * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function &executeStoredProc($name, $params = null, $types = null, $result_class = false, $result_wrap_class = false) + { + $this->debug($query, 'query'); + $error =& $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, + 'query: method not implemented'); + return $error; + } + + // }}} // {{{ _wrapResult() /** Index: MDB2/Driver/mssql.php =================================================================== RCS file: /repository/pear/MDB2/MDB2/Driver/mssql.php,v retrieving revision 1.56 diff -u -r1.56 mssql.php --- MDB2/Driver/mssql.php 22 Feb 2005 09:51:19 -0000 1.56 +++ MDB2/Driver/mssql.php 28 Feb 2005 17:32:25 -0000 @@ -389,6 +389,27 @@ } // }}} + // {{{ executeStoredProc() + + /** + * Execute a stored procedure and return any results + * + * @param string $name string that identifies the function to execute + * @param mixed $params array that contains the paramaters to pass the stored proc + * @param mixed $types array that contains the types of the columns in + * the result set + * @param mixed $result_class string which specifies which result class to use + * @param mixed $result_wrap_class string which specifies which class to wrap results in + * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function &executeStoredProc($name, $params, $types = null, $result_class = false, $result_wrap_class = false) + { + $query = 'EXECUTE '.$name; + if ($params) $query .= ' '.implode(',', $params); + return $this->query($query, $types, $result_class, $result_wrap_class); + } + // }}} // {{{ nextID() /** Index: MDB2/Driver/pgsql.php =================================================================== RCS file: /repository/pear/MDB2/MDB2/Driver/pgsql.php,v retrieving revision 1.52 diff -u -r1.52 pgsql.php --- MDB2/Driver/pgsql.php 22 Feb 2005 09:51:42 -0000 1.52 +++ MDB2/Driver/pgsql.php 28 Feb 2005 17:32:25 -0000 @@ -450,6 +450,27 @@ } // }}} + // {{{ executeStoredProc() + + /** + * Execute a stored procedure and return any results + * + * @param string $name string that identifies the function to execute + * @param mixed $params array that contains the paramaters to pass the stored proc + * @param mixed $types array that contains the types of the columns in + * the result set + * @param mixed $result_class string which specifies which result class to use + * @param mixed $result_wrap_class string which specifies which class to wrap results in + * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function &executeStoredProc($name, $params, $types = null, $result_class = false, $result_wrap_class = false) + { + $query = 'SELECT * FROM '.$name; + $query .= $params ? '('.implode(',', $params).')' : '()'; + return $this->query($query, $types, $result_class, $result_wrap_class); + } + // }}} // {{{ nextID() /**

Comments

 [2005-03-08 11:33 UTC] smith at backendmedia dot com
IIRC these methods only apply to stored procedures that return data? Daniel do you have a take on if we want to start adding things like this?
 [2005-03-08 14:59 UTC] danielc
Right off the bat, params should be passed by reference so the input/output can be bound to particular PHP variables. The approach Nathan is putting forth seems reasonable, but I haven't put any real thought into it.
 [2005-03-24 12:17 UTC] smith at backendmedia dot com
Ok .. dont expect this to be added any time soon though. There are several more pressing things I want to address and I dont want to rush into this. However as it seems you guys are using PHP5 you might want to consider turning your code into a custom module that can be called very conviniently using the newly added __call() facility.
 [2005-10-17 21:19 UTC] lsmith
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.