cvs: pear /LiveUser_Admin/Storage DB.php MDB.php SQL.php
| From: | Lukas Smith | Date: | Sat, 12 Nov 2005 15:05:42 +0000 |
| Subject: | cvs: pear /LiveUser_Admin/Storage DB.php MDB.php SQL.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-36240@lists.php.net to get a copy of this message | ||
lsmith Sat Nov 12 10:05:42 2005 EDT
Modified files:
/pear/LiveUser_Admin/Storage DB.php MDB.php SQL.php
Log:
- phpdoc fixes
- renamed query() to exec() to match the MDB2 beta7 API
http://cvs.php.net/diff.php/pear/LiveUser_Admin/Storage/DB.php?r1=1.15&r2=1.16&ty=u Index: pear/LiveUser_Admin/Storage/DB.php diff -u pear/LiveUser_Admin/Storage/DB.php:1.15 pear/LiveUser_Admin/Storage/DB.php:1.16 --- pear/LiveUser_Admin/Storage/DB.php:1.15 Thu Sep 29 15:54:37 2005 +++ pear/LiveUser_Admin/Storage/DB.php Sat Nov 12 10:05:41 2005 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: DB.php,v 1.15 2005/09/29 19:54:37 lsmith Exp $ + * @version CVS: $Id: DB.php,v 1.16 2005/11/12 15:05:41 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -73,12 +73,12 @@ * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: - * - File "Liveuser.php" (contains the parent class "LiveUser") + * - File "Liveuser/Admin.php" (contains the parent class "LiveUser_Admin") * - Array of connection options or a PEAR::DB connection object must be - * passed to the constructor. + * passed to the init() method * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR - * &$conn (PEAR::DB connection object) + * array('connection' => &$conn) ($conn is a PEAR::DB connection object) * * @category authentication * @package LiveUser_Admin @@ -190,15 +190,15 @@ } /** - * Execute query + * Execute DML query * - * @param string $query query - * @return boolean | integer + * @param string $query DML query + * @return boolean | integer of the affected rows * * @access public * @uses DB::query DB::affectedRows */ - function query($query) + function exec($query) { $result = $this->dbc->query($query); if (PEAR::isError($result)) { @@ -213,15 +213,13 @@ /** * Execute the specified query, fetch the value from the first column of - * the first row of the result set and then frees - * the result set. + * the first row of the result set and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param string $type argument that specifies the expected - * datatype of the result set field, so that an eventual conversion - * may be performed. The default datatype is text, meaning that no - * conversion is performed - * @return boolean | array + * @param string $type argument that specifies the expected datatype of the + * result set field, so that an eventual conversion may be performed. + * The default datatype is text, meaning no conversion is performed. + * @return boolean | scalar * * @access public * @uses DB::getOne @@ -245,10 +243,9 @@ * the result set. * * @param string $query the SELECT query statement to be executed. - * @param array $type array argument that specifies a list of - * expected datatypes of the result set columns, so that the eventual - * conversions may be performed. The default list of datatypes is - * empty, meaning that no conversion is performed. + * @param array $type argument that specifies a list of expected datatypes + * of theresult set columns, so that the conversions may be performed. + * The default datatype is text, meaning no conversion is performed. * @return boolean | array * * @access public @@ -272,10 +269,9 @@ * each row of the result set into an array and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param string $type argument that specifies the expected - * datatype of the result set field, so that an eventual conversion - * may be performed. The default datatype is text, meaning that no - * conversion is performed + * @param string $type argument that specifies the expected datatype of the + * result set field, so that an eventual conversion may be performed. + * The default datatype is text, meaning no conversion is performed. * @return boolean | array * * @access public @@ -299,11 +295,10 @@ * a two dimensional array and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param array $types array argument that specifies a list of - * expected datatypes of the result set columns, so that the eventual - * conversions may be performed. The default list of datatypes is - * empty, meaning that no conversion is performed. - * @param boolean $rekey if set to true, the $all will have the first + * @param array $type argument that specifies a list of expected datatypes + * of theresult set columns, so that the conversions may be performed. + * The default datatype is text, meaning no conversion is performed. + * @param boolean $rekey if set to true, returned array will have the first * column as its first dimension * @param boolean $group if set to true and $rekey is set to true, then * all values with the same first column will be wrapped in an array @@ -354,8 +349,8 @@ } /** - * returns the next free id of a sequence if the RDBMS - * does not support auto increment + * Since DB does not support determining if auto increment is supported, + * the call is redirected to nextID() * * @param string $table name of the table into which a new row was inserted * @param boolean $ondemand when true the seqence is @@ -363,26 +358,15 @@ * @return boolean | integer * * @access public - * @uses DB::nextId */ function getBeforeId($table, $ondemand = true) { - $result = $this->dbc->nextId($table, $ondemand); - if (PEAR::isError($result)) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', - array('reason' => $result->getMessage() . '-' . $result->getUserInfo()) - ); - return false; - } - return $result; + return $this->nextId($table, $ondemand); } /** - * returns the autoincrement ID if supported or $id - * - * getAfterId isn't implemented in DB so we return the $id that - * was passed by the user + * Since DB does not support determining if auto increment is supported, + * the call just returns the $id parameter * * @param string $id value as returned by getBeforeId() * @param string $table name of the table into which a new row was inserted http://cvs.php.net/diff.php/pear/LiveUser_Admin/Storage/MDB.php?r1=1.15&r2=1.16&ty=u Index: pear/LiveUser_Admin/Storage/MDB.php diff -u pear/LiveUser_Admin/Storage/MDB.php:1.15 pear/LiveUser_Admin/Storage/MDB.php:1.16 --- pear/LiveUser_Admin/Storage/MDB.php:1.15 Thu Sep 29 15:54:37 2005 +++ pear/LiveUser_Admin/Storage/MDB.php Sat Nov 12 10:05:41 2005 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version $Id: MDB.php,v 1.15 2005/09/29 19:54:37 lsmith Exp $ + * @version CVS: $Id: MDB.php,v 1.16 2005/11/12 15:05:41 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -73,12 +73,12 @@ * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: - * - File "Liveuser.php" (contains the parent class "LiveUser") + * - File "Liveuser/Admin.php" (contains the parent class "LiveUser_Admin") * - Array of connection options or a PEAR::MDB connection object must be - * passed to the constructor. + * passed to the init() method * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR - * &$conn (PEAR::MDB connection object) + * array('connection' => &$conn) ($conn is a PEAR::MDB connection object) * * @category authentication * @package LiveUser_Admin @@ -159,7 +159,6 @@ * * @param array $array data array * @param string $type determines type of the field - * * @return string comma seperated values * * @access public @@ -182,7 +181,7 @@ * @param string $limit number of rows to select * @param string $offset first row to select * - * @return + * @return boolean * * @access public * @uses MDB::setSelectedRowRange @@ -190,20 +189,28 @@ function setLimit($limit, $offset) { if ($limit || $offset) { - return $this->dbc->setSelectedRowRange($offset, $limit); + $result = $this->dbc->setSelectedRowRange($offset, $limit); + if (PEAR::isError($result)) { + $this->_stack->push( + LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', + array('reason' => $result->getMessage() . '-' . $result->getUserInfo()) + ); + return false; + } } + return true; } /** - * Execute query + * Execute DML query * - * @param string $query query - * @return boolean | integer + * @param string $query DML query + * @return boolean | integer of the affected rows * * @access public * @uses MDB::query MDB::affectedRows */ - function query($query) + function exec($query) { $result = $this->dbc->query($query); if (PEAR::isError($result)) { @@ -218,15 +225,13 @@ /** * Execute the specified query, fetch the value from the first column of - * the first row of the result set and then frees - * the result set. + * the first row of the result set and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param string $type argument that specifies the expected - * datatype of the result set field, so that an eventual conversion - * may be performed. The default datatype is text, meaning that no - * conversion is performed - * @return boolean | array + * @param string $type argument that specifies the expected datatype of the + * result set field, so that an eventual conversion may be performed. + * The default datatype is text, meaning no conversion is performed. + * @return boolean | scalar * * @access public * @uses MDB::queryOne @@ -254,10 +259,9 @@ * the result set. * * @param string $query the SELECT query statement to be executed. - * @param array $type array argument that specifies a list of - * expected datatypes of the result set columns, so that the eventual - * conversions may be performed. The default list of datatypes is - * empty, meaning that no conversion is performed. + * @param array $type argument that specifies a list of expected datatypes + * of theresult set columns, so that the conversions may be performed. + * The default datatype is text, meaning no conversion is performed. * @return boolean | array * * @access public @@ -281,10 +285,9 @@ * each row of the result set into an array and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param string $type argument that specifies the expected - * datatype of the result set field, so that an eventual conversion - * may be performed. The default datatype is text, meaning that no - * conversion is performed + * @param string $type argument that specifies the expected datatype of the + * result set field, so that an eventual conversion may be performed. + * The default datatype is text, meaning no conversion is performed. * @return boolean | array * * @access public @@ -295,6 +298,7 @@ if (is_array($type)) { $type = reset($type); } + $result = $this->dbc->queryCol($query, $type); if (PEAR::isError($result)) { $this->_stack->push( @@ -311,11 +315,10 @@ * a two dimensional array and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param array $types array argument that specifies a list of - * expected datatypes of the result set columns, so that the eventual - * conversions may be performed. The default list of datatypes is - * empty, meaning that no conversion is performed. - * @param boolean $rekey if set to true, the $all will have the first + * @param array $type argument that specifies a list of expected datatypes + * of theresult set columns, so that the conversions may be performed. + * The default datatype is text, meaning no conversion is performed. + * @param boolean $rekey if set to true, returned array will have the first * column as its first dimension * @param boolean $group if set to true and $rekey is set to true, then * all values with the same first column will be wrapped in an array @@ -343,7 +346,7 @@ * @param string $seqname name of the sequence * @param boolean $ondemand when true the seqence is * automatic created, if it not exists - * @return boolean | integer + * @return boolean | integer false on failure or next id for the table * * @access public * @uses MDB::nextId @@ -362,8 +365,8 @@ } /** - * returns the next free id of a sequence if the RDBMS - * does not support auto increment + * Since MDB does not support determining if auto increment is supported, + * the call is redirected to nextID() * * @param string $table name of the table into which a new row was inserted * @param boolean $ondemand when true the seqence is @@ -371,26 +374,15 @@ * @return boolean | integer * * @access public - * @uses MDB::nextId */ function getBeforeId($table, $ondemand = true) { - $result = $this->dbc->nextId($table, $ondemand); - if (PEAR::isError($result)) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', - array('reason' => $result->getMessage() . '-' . $result->getUserInfo()) - ); - return false; - } - return $result; + return $this->nextId($table, $ondemand); } /** - * returns the autoincrement ID if supported or $id - * - * getAfterId isn't implemented in MDB so we return the $id that - * was passed by the user + * Since MDB does not support determining if auto increment is supported, + * the call just returns the $id parameter * * @param string $id value as returned by getBeforeId() * @param string $table name of the table into which a new row was inserted http://cvs.php.net/diff.php/pear/LiveUser_Admin/Storage/SQL.php?r1=1.41&r2=1.42&ty=u Index: pear/LiveUser_Admin/Storage/SQL.php diff -u pear/LiveUser_Admin/Storage/SQL.php:1.41 pear/LiveUser_Admin/Storage/SQL.php:1.42 --- pear/LiveUser_Admin/Storage/SQL.php:1.41 Mon Oct 17 15:22:10 2005 +++ pear/LiveUser_Admin/Storage/SQL.php Sat Nov 12 10:05:41 2005 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: SQL.php,v 1.41 2005/10/17 19:22:10 lsmith Exp $ + * @version CVS: $Id: SQL.php,v 1.42 2005/11/12 15:05:41 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -92,7 +92,7 @@ /** * dsn that was connected to * - * @var object + * @var string * @access private */ var $dsn = null; @@ -106,8 +106,7 @@ var $dbc = null; /** - * Table prefix - * Prefix for all db tables the container has. + * Table prefix for all db tables the container has. * * @var string * @access public @@ -117,10 +116,9 @@ /** * Insert data into a table * - * - * @param string $table - * @param array $data - * @return mixed false on error, true (or new id) on success + * @param string $table name of the table + * @param array $data key value pairs + * @return integer|boolean false on error, true (or new id) on success * * @access public */ @@ -161,7 +159,7 @@ $values[] = $value_quoted; } - $result = $this->query($this->createInsert($table, $fields, $values)); + $result = $this->exec($this->createInsert($table, $fields, $values)); if ($result === false) { return false; } @@ -177,10 +175,9 @@ /** * Create the SQL necessary for an insert * - * - * @param string $table - * @param array $fields - * @param array $values + * @param string $table name of the table + * @param array $fields array of field names + * @param array $values array of quoted values * @return string SQL insert query * * @access public @@ -196,11 +193,10 @@ /** * Update data in a table based given filters * - * - * @param string $table - * @param array $data - * @param array $filteres - * @return mixed false on error, the affected rows on success + * @param string $table name of the table + * @param array $data key value pairs + * @param array $filters key values pairs (value may be a string or an array) + * @return integer|boolean false on error, the affected rows on success * * @access public */ @@ -226,7 +222,7 @@ $fields[] = $this->alias[$field] . ' = ' . $value_quoted; } - $result = $this->query($this->createUpdate($table, $fields, $filters)); + $result = $this->exec($this->createUpdate($table, $fields, $filters)); return $result; } @@ -234,9 +230,9 @@ * Create the SQL necessary for an update * * - * @param string $table - * @param array $fields - * @param array $filters + * @param string $table name of the table + * @param array $fields array of field names + * @param array $filters array containing the filtering to apply * @return string SQL update query * * @access public @@ -250,12 +246,11 @@ } /** - * Update from a table based given filters + * Delete from a table based given filters * - * - * @param string $table - * @param array $filters - * @return mixed false on error, the affected rows on success + * @param string $table name of the table + * @param array $filters key values pairs (value may be a string or an array) + * @return integer|boolean false on error, the affected rows on success * * @access public */ @@ -267,20 +262,34 @@ if ($result === false) { return false; } - $query = 'DELETE FROM ' . $this->prefix . $this->alias[$table]; - $query .= $this->createWhere($filters); - $result = $this->query($query); + $result = $this->exec($this->createDelete($table, $filters)); return $result; } /** - * Fetches the count of many rows contain the filtered data + * Create the SQL necessary for an delete + * * + * @param string $table name of the table + * @param array $filters array containing the filtering to apply + * @return string SQL delete query + * + * @access public + */ + function createDelete($table, $filters) + { + $query = 'DELETE FROM ' . $this->prefix . $this->alias[$table]; + $query .= $this->createWhere($filters); + return $query; + } + + /** + * Fetches the count of many rows contain the filtered data * - * @param string $table - * @param string $field - * @param array $filters + * @param string $table name of the table + * @param string $field field name to count + * @param array $filters key values pairs (value may be a string or an array) * @return boolean | integer false on failure and integer of how many * rows contain the filtered data * @@ -315,16 +324,21 @@ * Select data from a set of tables * * - * @param array $select - * @param array $fields - * @param array $filters - * @param array $orders - * @param boolean $rekey - * @param boolean $group - * @param integer $limit - * @param integer $offset - * @param string $root_table - * @param array $selectable_tables + * @param string $select determines what query method to use: + * 'one' -> queryOne, 'row' -> queryRow, 'col' -> queryCol, + * 'all' ->queryAll (default) + * @param array $fields list of fields to fetch + * @param array $filters key values pairs (value may be a string or an array) + * @param array $orders key value pairs (values 'ASC' or 'DESC') + * @param boolean $rekey if set to true, returned array will have the first + * column as its first dimension + * @param boolean $group if set to true and $rekey is set to true, then + * all values with the same first column will be wrapped in an array + * @param string $limit number of rows to select + * @param string $offset first row to select + * @param string $root_table name of the table from which to start looking + * for join points + * @param array $selectable_tables list of tables that may be joined to * @return boolean | array false on failure or array with selected data * * @access public @@ -367,11 +381,12 @@ * Create the SQL necessary for a select * * - * @param array $fields - * @param array $filters - * @param array $orders - * @param string $root_table - * @param array $selectable_tables + * @param array $fields list of fields to fetch + * @param array $filters key values pairs (value may be a string or an array) + * @param array $orders key value pairs (values 'ASC' or 'DESC') + * @param string $root_table name of the table from which to start looking + * for join points + * @param array $selectable_tables list of tables that may be joined to * @return boolean | string false on failure or a string with SQL query * * @access public @@ -428,8 +443,8 @@ * Create the SQL necessary for a where statement * * - * @param array $filters - * @param array $joinfilters + * @param array $filters key values pairs (value may be a string or an array) + * @param array $joinfilters key values pairs of join related filters * @return boolean | string false on failure or string with SQL WHERE * * @access public @@ -494,9 +509,9 @@ * list and is a valid field * * - * @param array $field - * @param array $selectable_tables - * @return mixed | array, null or false on failure + * @param string $field (qualified) field name + * @param array $selectable_tables list of tables that may be joined to + * @return boolean|array null or false on failure * * @access private */ @@ -527,11 +542,11 @@ * all requested columns and to be able to filter the joined rows * * - * @param array &$fields - * @param array &$filters - * @param array &$orders - * @param array $selectable_tables - * @return boolean | array false on failure + * @param array &$fields list of fields to fetch + * @param array &$filters key values pairs (value may be a string or an array) + * @param array &$orders key value pairs (values 'ASC' or 'DESC') + * @param array $selectable_tables list of tables that may be joined to + * @return boolean | array of table names required or false on failure * * @access public */ @@ -665,11 +680,12 @@ * Recursively find all the tables that need to be joined to be able to select * all requested columns and to be able to filter the joined rows * - * @param string $root_table - * @param array $filters - * @param array $tables - * @param array $selectable_tables - * @param array $visited + * @param string $root_table name of the table from which to start looking + * for join points + * @param array $fields list of fields to fetch + * @param array $tables list of tables that are joined + * @param array $selectable_tables list of tables that may be joined to + * @param array $visited array of table already visisted to prevent infinite recursions * @return boolean | array false on failure * * @access public
http://cvs.php.net/diff.php/pear/LiveUser_Admin/Storage/DB.php?r1=1.15&r2=1.16&ty=u Index: pear/LiveUser_Admin/Storage/DB.php diff -u pear/LiveUser_Admin/Storage/DB.php:1.15 pear/LiveUser_Admin/Storage/DB.php:1.16 --- pear/LiveUser_Admin/Storage/DB.php:1.15 Thu Sep 29 15:54:37 2005 +++ pear/LiveUser_Admin/Storage/DB.php Sat Nov 12 10:05:41 2005 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: DB.php,v 1.15 2005/09/29 19:54:37 lsmith Exp $ + * @version CVS: $Id: DB.php,v 1.16 2005/11/12 15:05:41 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -73,12 +73,12 @@ * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: - * - File "Liveuser.php" (contains the parent class "LiveUser") + * - File "Liveuser/Admin.php" (contains the parent class "LiveUser_Admin") * - Array of connection options or a PEAR::DB connection object must be - * passed to the constructor. + * passed to the init() method * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR - * &$conn (PEAR::DB connection object) + * array('connection' => &$conn) ($conn is a PEAR::DB connection object) * * @category authentication * @package LiveUser_Admin @@ -190,15 +190,15 @@ } /** - * Execute query + * Execute DML query * - * @param string $query query - * @return boolean | integer + * @param string $query DML query + * @return boolean | integer of the affected rows * * @access public * @uses DB::query DB::affectedRows */ - function query($query) + function exec($query) { $result = $this->dbc->query($query); if (PEAR::isError($result)) { @@ -213,15 +213,13 @@ /** * Execute the specified query, fetch the value from the first column of - * the first row of the result set and then frees - * the result set. + * the first row of the result set and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param string $type argument that specifies the expected - * datatype of the result set field, so that an eventual conversion - * may be performed. The default datatype is text, meaning that no - * conversion is performed - * @return boolean | array + * @param string $type argument that specifies the expected datatype of the + * result set field, so that an eventual conversion may be performed. + * The default datatype is text, meaning no conversion is performed. + * @return boolean | scalar * * @access public * @uses DB::getOne @@ -245,10 +243,9 @@ * the result set. * * @param string $query the SELECT query statement to be executed. - * @param array $type array argument that specifies a list of - * expected datatypes of the result set columns, so that the eventual - * conversions may be performed. The default list of datatypes is - * empty, meaning that no conversion is performed. + * @param array $type argument that specifies a list of expected datatypes + * of theresult set columns, so that the conversions may be performed. + * The default datatype is text, meaning no conversion is performed. * @return boolean | array * * @access public @@ -272,10 +269,9 @@ * each row of the result set into an array and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param string $type argument that specifies the expected - * datatype of the result set field, so that an eventual conversion - * may be performed. The default datatype is text, meaning that no - * conversion is performed + * @param string $type argument that specifies the expected datatype of the + * result set field, so that an eventual conversion may be performed. + * The default datatype is text, meaning no conversion is performed. * @return boolean | array * * @access public @@ -299,11 +295,10 @@ * a two dimensional array and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param array $types array argument that specifies a list of - * expected datatypes of the result set columns, so that the eventual - * conversions may be performed. The default list of datatypes is - * empty, meaning that no conversion is performed. - * @param boolean $rekey if set to true, the $all will have the first + * @param array $type argument that specifies a list of expected datatypes + * of theresult set columns, so that the conversions may be performed. + * The default datatype is text, meaning no conversion is performed. + * @param boolean $rekey if set to true, returned array will have the first * column as its first dimension * @param boolean $group if set to true and $rekey is set to true, then * all values with the same first column will be wrapped in an array @@ -354,8 +349,8 @@ } /** - * returns the next free id of a sequence if the RDBMS - * does not support auto increment + * Since DB does not support determining if auto increment is supported, + * the call is redirected to nextID() * * @param string $table name of the table into which a new row was inserted * @param boolean $ondemand when true the seqence is @@ -363,26 +358,15 @@ * @return boolean | integer * * @access public - * @uses DB::nextId */ function getBeforeId($table, $ondemand = true) { - $result = $this->dbc->nextId($table, $ondemand); - if (PEAR::isError($result)) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', - array('reason' => $result->getMessage() . '-' . $result->getUserInfo()) - ); - return false; - } - return $result; + return $this->nextId($table, $ondemand); } /** - * returns the autoincrement ID if supported or $id - * - * getAfterId isn't implemented in DB so we return the $id that - * was passed by the user + * Since DB does not support determining if auto increment is supported, + * the call just returns the $id parameter * * @param string $id value as returned by getBeforeId() * @param string $table name of the table into which a new row was inserted http://cvs.php.net/diff.php/pear/LiveUser_Admin/Storage/MDB.php?r1=1.15&r2=1.16&ty=u Index: pear/LiveUser_Admin/Storage/MDB.php diff -u pear/LiveUser_Admin/Storage/MDB.php:1.15 pear/LiveUser_Admin/Storage/MDB.php:1.16 --- pear/LiveUser_Admin/Storage/MDB.php:1.15 Thu Sep 29 15:54:37 2005 +++ pear/LiveUser_Admin/Storage/MDB.php Sat Nov 12 10:05:41 2005 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version $Id: MDB.php,v 1.15 2005/09/29 19:54:37 lsmith Exp $ + * @version CVS: $Id: MDB.php,v 1.16 2005/11/12 15:05:41 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -73,12 +73,12 @@ * existing connection. Alternatively, a DSN can be passed to open a new one. * * Requirements: - * - File "Liveuser.php" (contains the parent class "LiveUser") + * - File "Liveuser/Admin.php" (contains the parent class "LiveUser_Admin") * - Array of connection options or a PEAR::MDB connection object must be - * passed to the constructor. + * passed to the init() method * Example: array('dsn' => 'mysql://user:pass@host/db_name') * OR - * &$conn (PEAR::MDB connection object) + * array('connection' => &$conn) ($conn is a PEAR::MDB connection object) * * @category authentication * @package LiveUser_Admin @@ -159,7 +159,6 @@ * * @param array $array data array * @param string $type determines type of the field - * * @return string comma seperated values * * @access public @@ -182,7 +181,7 @@ * @param string $limit number of rows to select * @param string $offset first row to select * - * @return + * @return boolean * * @access public * @uses MDB::setSelectedRowRange @@ -190,20 +189,28 @@ function setLimit($limit, $offset) { if ($limit || $offset) { - return $this->dbc->setSelectedRowRange($offset, $limit); + $result = $this->dbc->setSelectedRowRange($offset, $limit); + if (PEAR::isError($result)) { + $this->_stack->push( + LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', + array('reason' => $result->getMessage() . '-' . $result->getUserInfo()) + ); + return false; + } } + return true; } /** - * Execute query + * Execute DML query * - * @param string $query query - * @return boolean | integer + * @param string $query DML query + * @return boolean | integer of the affected rows * * @access public * @uses MDB::query MDB::affectedRows */ - function query($query) + function exec($query) { $result = $this->dbc->query($query); if (PEAR::isError($result)) { @@ -218,15 +225,13 @@ /** * Execute the specified query, fetch the value from the first column of - * the first row of the result set and then frees - * the result set. + * the first row of the result set and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param string $type argument that specifies the expected - * datatype of the result set field, so that an eventual conversion - * may be performed. The default datatype is text, meaning that no - * conversion is performed - * @return boolean | array + * @param string $type argument that specifies the expected datatype of the + * result set field, so that an eventual conversion may be performed. + * The default datatype is text, meaning no conversion is performed. + * @return boolean | scalar * * @access public * @uses MDB::queryOne @@ -254,10 +259,9 @@ * the result set. * * @param string $query the SELECT query statement to be executed. - * @param array $type array argument that specifies a list of - * expected datatypes of the result set columns, so that the eventual - * conversions may be performed. The default list of datatypes is - * empty, meaning that no conversion is performed. + * @param array $type argument that specifies a list of expected datatypes + * of theresult set columns, so that the conversions may be performed. + * The default datatype is text, meaning no conversion is performed. * @return boolean | array * * @access public @@ -281,10 +285,9 @@ * each row of the result set into an array and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param string $type argument that specifies the expected - * datatype of the result set field, so that an eventual conversion - * may be performed. The default datatype is text, meaning that no - * conversion is performed + * @param string $type argument that specifies the expected datatype of the + * result set field, so that an eventual conversion may be performed. + * The default datatype is text, meaning no conversion is performed. * @return boolean | array * * @access public @@ -295,6 +298,7 @@ if (is_array($type)) { $type = reset($type); } + $result = $this->dbc->queryCol($query, $type); if (PEAR::isError($result)) { $this->_stack->push( @@ -311,11 +315,10 @@ * a two dimensional array and then frees the result set. * * @param string $query the SELECT query statement to be executed. - * @param array $types array argument that specifies a list of - * expected datatypes of the result set columns, so that the eventual - * conversions may be performed. The default list of datatypes is - * empty, meaning that no conversion is performed. - * @param boolean $rekey if set to true, the $all will have the first + * @param array $type argument that specifies a list of expected datatypes + * of theresult set columns, so that the conversions may be performed. + * The default datatype is text, meaning no conversion is performed. + * @param boolean $rekey if set to true, returned array will have the first * column as its first dimension * @param boolean $group if set to true and $rekey is set to true, then * all values with the same first column will be wrapped in an array @@ -343,7 +346,7 @@ * @param string $seqname name of the sequence * @param boolean $ondemand when true the seqence is * automatic created, if it not exists - * @return boolean | integer + * @return boolean | integer false on failure or next id for the table * * @access public * @uses MDB::nextId @@ -362,8 +365,8 @@ } /** - * returns the next free id of a sequence if the RDBMS - * does not support auto increment + * Since MDB does not support determining if auto increment is supported, + * the call is redirected to nextID() * * @param string $table name of the table into which a new row was inserted * @param boolean $ondemand when true the seqence is @@ -371,26 +374,15 @@ * @return boolean | integer * * @access public - * @uses MDB::nextId */ function getBeforeId($table, $ondemand = true) { - $result = $this->dbc->nextId($table, $ondemand); - if (PEAR::isError($result)) { - $this->_stack->push( - LIVEUSER_ADMIN_ERROR_QUERY_BUILDER, 'exception', - array('reason' => $result->getMessage() . '-' . $result->getUserInfo()) - ); - return false; - } - return $result; + return $this->nextId($table, $ondemand); } /** - * returns the autoincrement ID if supported or $id - * - * getAfterId isn't implemented in MDB so we return the $id that - * was passed by the user + * Since MDB does not support determining if auto increment is supported, + * the call just returns the $id parameter * * @param string $id value as returned by getBeforeId() * @param string $table name of the table into which a new row was inserted http://cvs.php.net/diff.php/pear/LiveUser_Admin/Storage/SQL.php?r1=1.41&r2=1.42&ty=u Index: pear/LiveUser_Admin/Storage/SQL.php diff -u pear/LiveUser_Admin/Storage/SQL.php:1.41 pear/LiveUser_Admin/Storage/SQL.php:1.42 --- pear/LiveUser_Admin/Storage/SQL.php:1.41 Mon Oct 17 15:22:10 2005 +++ pear/LiveUser_Admin/Storage/SQL.php Sat Nov 12 10:05:41 2005 @@ -57,7 +57,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: SQL.php,v 1.41 2005/10/17 19:22:10 lsmith Exp $ + * @version CVS: $Id: SQL.php,v 1.42 2005/11/12 15:05:41 lsmith Exp $ * @link http://pear.php.net/LiveUser_Admin */ @@ -92,7 +92,7 @@ /** * dsn that was connected to * - * @var object + * @var string * @access private */ var $dsn = null; @@ -106,8 +106,7 @@ var $dbc = null; /** - * Table prefix - * Prefix for all db tables the container has. + * Table prefix for all db tables the container has. * * @var string * @access public @@ -117,10 +116,9 @@ /** * Insert data into a table * - * - * @param string $table - * @param array $data - * @return mixed false on error, true (or new id) on success + * @param string $table name of the table + * @param array $data key value pairs + * @return integer|boolean false on error, true (or new id) on success * * @access public */ @@ -161,7 +159,7 @@ $values[] = $value_quoted; } - $result = $this->query($this->createInsert($table, $fields, $values)); + $result = $this->exec($this->createInsert($table, $fields, $values)); if ($result === false) { return false; } @@ -177,10 +175,9 @@ /** * Create the SQL necessary for an insert * - * - * @param string $table - * @param array $fields - * @param array $values + * @param string $table name of the table + * @param array $fields array of field names + * @param array $values array of quoted values * @return string SQL insert query * * @access public @@ -196,11 +193,10 @@ /** * Update data in a table based given filters * - * - * @param string $table - * @param array $data - * @param array $filteres - * @return mixed false on error, the affected rows on success + * @param string $table name of the table + * @param array $data key value pairs + * @param array $filters key values pairs (value may be a string or an array) + * @return integer|boolean false on error, the affected rows on success * * @access public */ @@ -226,7 +222,7 @@ $fields[] = $this->alias[$field] . ' = ' . $value_quoted; } - $result = $this->query($this->createUpdate($table, $fields, $filters)); + $result = $this->exec($this->createUpdate($table, $fields, $filters)); return $result; } @@ -234,9 +230,9 @@ * Create the SQL necessary for an update * * - * @param string $table - * @param array $fields - * @param array $filters + * @param string $table name of the table + * @param array $fields array of field names + * @param array $filters array containing the filtering to apply * @return string SQL update query * * @access public @@ -250,12 +246,11 @@ } /** - * Update from a table based given filters + * Delete from a table based given filters * - * - * @param string $table - * @param array $filters - * @return mixed false on error, the affected rows on success + * @param string $table name of the table + * @param array $filters key values pairs (value may be a string or an array) + * @return integer|boolean false on error, the affected rows on success * * @access public */ @@ -267,20 +262,34 @@ if ($result === false) { return false; } - $query = 'DELETE FROM ' . $this->prefix . $this->alias[$table]; - $query .= $this->createWhere($filters); - $result = $this->query($query); + $result = $this->exec($this->createDelete($table, $filters)); return $result; } /** - * Fetches the count of many rows contain the filtered data + * Create the SQL necessary for an delete + * * + * @param string $table name of the table + * @param array $filters array containing the filtering to apply + * @return string SQL delete query + * + * @access public + */ + function createDelete($table, $filters) + { + $query = 'DELETE FROM ' . $this->prefix . $this->alias[$table]; + $query .= $this->createWhere($filters); + return $query; + } + + /** + * Fetches the count of many rows contain the filtered data * - * @param string $table - * @param string $field - * @param array $filters + * @param string $table name of the table + * @param string $field field name to count + * @param array $filters key values pairs (value may be a string or an array) * @return boolean | integer false on failure and integer of how many * rows contain the filtered data * @@ -315,16 +324,21 @@ * Select data from a set of tables * * - * @param array $select - * @param array $fields - * @param array $filters - * @param array $orders - * @param boolean $rekey - * @param boolean $group - * @param integer $limit - * @param integer $offset - * @param string $root_table - * @param array $selectable_tables + * @param string $select determines what query method to use: + * 'one' -> queryOne, 'row' -> queryRow, 'col' -> queryCol, + * 'all' ->queryAll (default) + * @param array $fields list of fields to fetch + * @param array $filters key values pairs (value may be a string or an array) + * @param array $orders key value pairs (values 'ASC' or 'DESC') + * @param boolean $rekey if set to true, returned array will have the first + * column as its first dimension + * @param boolean $group if set to true and $rekey is set to true, then + * all values with the same first column will be wrapped in an array + * @param string $limit number of rows to select + * @param string $offset first row to select + * @param string $root_table name of the table from which to start looking + * for join points + * @param array $selectable_tables list of tables that may be joined to * @return boolean | array false on failure or array with selected data * * @access public @@ -367,11 +381,12 @@ * Create the SQL necessary for a select * * - * @param array $fields - * @param array $filters - * @param array $orders - * @param string $root_table - * @param array $selectable_tables + * @param array $fields list of fields to fetch + * @param array $filters key values pairs (value may be a string or an array) + * @param array $orders key value pairs (values 'ASC' or 'DESC') + * @param string $root_table name of the table from which to start looking + * for join points + * @param array $selectable_tables list of tables that may be joined to * @return boolean | string false on failure or a string with SQL query * * @access public @@ -428,8 +443,8 @@ * Create the SQL necessary for a where statement * * - * @param array $filters - * @param array $joinfilters + * @param array $filters key values pairs (value may be a string or an array) + * @param array $joinfilters key values pairs of join related filters * @return boolean | string false on failure or string with SQL WHERE * * @access public @@ -494,9 +509,9 @@ * list and is a valid field * * - * @param array $field - * @param array $selectable_tables - * @return mixed | array, null or false on failure + * @param string $field (qualified) field name + * @param array $selectable_tables list of tables that may be joined to + * @return boolean|array null or false on failure * * @access private */ @@ -527,11 +542,11 @@ * all requested columns and to be able to filter the joined rows * * - * @param array &$fields - * @param array &$filters - * @param array &$orders - * @param array $selectable_tables - * @return boolean | array false on failure + * @param array &$fields list of fields to fetch + * @param array &$filters key values pairs (value may be a string or an array) + * @param array &$orders key value pairs (values 'ASC' or 'DESC') + * @param array $selectable_tables list of tables that may be joined to + * @return boolean | array of table names required or false on failure * * @access public */ @@ -665,11 +680,12 @@ * Recursively find all the tables that need to be joined to be able to select * all requested columns and to be able to filter the joined rows * - * @param string $root_table - * @param array $filters - * @param array $tables - * @param array $selectable_tables - * @param array $visited + * @param string $root_table name of the table from which to start looking + * for join points + * @param array $fields list of fields to fetch + * @param array $tables list of tables that are joined + * @param array $selectable_tables list of tables that may be joined to + * @param array $visited array of table already visisted to prevent infinite recursions * @return boolean | array false on failure * * @access public