cvs: pear /DB_DBA DBA.php DBA_Builtin.php DBA_Compat.php DBA_Relational.php DBA_Simple.php DBA_Table.php /DB_DBA/tests test_table.php
| From: | Brent Cook | Date: | Sun, 07 Jul 2002 03:25:01 +0000 |
| Subject: | cvs: pear /DB_DBA DBA.php DBA_Builtin.php DBA_Compat.php DBA_Relational.php DBA_Simple.php DBA_Table.php /DB_DBA/tests test_table.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4937@lists.php.net to get a copy of this message | ||
busterb Sat Jul 6 23:25:01 2002 EDT
Modified files:
/pear/DB_DBA DBA.php DBA_Builtin.php DBA_Compat.php
DBA_Relational.php DBA_Simple.php DBA_Table.php
/pear/DB_DBA/tests test_table.php
Log:
Loads of PHPDoc updates; wasn't sure whether to use @return or @returns, so I
used both. PHPDocumentor seems to even use both!
Index: pear/DB_DBA/DBA.php diff -u pear/DB_DBA/DBA.php:1.6 pear/DB_DBA/DBA.php:1.7 --- pear/DB_DBA/DBA.php:1.6 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA.php Sat Jul 6 23:25:00 2002 @@ -20,17 +20,29 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: DBA.php,v 1.6 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA.php,v 1.7 2002/07/07 03:25:00 busterb Exp $ // + +/** + * DBA is a set of classes for handling and extending Berkeley DB style + * databases. It works around some of the quirks in the built-in dba + * functions in PHP (e.g. gdbm does not support dba_replace), has its own + * dbm engine for installations where dba support is not included in PHP. + * + * @author Brent Cook <busterb@mail.utexas.edu> + * @version 0.0.14 + * @access public + * @package DBA + */ class DBA { /** - * Return a DBA object + * Creates a new DBA object * * @static - * @version 0.0.14 - * @param string $driver Type of storage object to return - * @return object DBA storage object, returned by reference + * @param string $driver type of storage object to return + * @return object + * @returns DBA storage object, returned by reference */ function &create($driver = 'simple') { Index: pear/DB_DBA/DBA_Builtin.php diff -u pear/DB_DBA/DBA_Builtin.php:1.6 pear/DB_DBA/DBA_Builtin.php:1.7 --- pear/DB_DBA/DBA_Builtin.php:1.6 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA_Builtin.php Sat Jul 6 23:25:00 2002 @@ -17,10 +17,8 @@ // | License along with this library; if not, write to the Free Software | // | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA| // +----------------------------------------------------------------------+ -// | Author: Brent Cook <busterb@mail.utexas.edu> | -// +----------------------------------------------------------------------+ // -// $Id: DBA_Builtin.php,v 1.6 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA_Builtin.php,v 1.7 2002/07/07 03:25:00 busterb Exp $ require_once 'PEAR.php'; @@ -30,10 +28,11 @@ * the DBA_Simple class. * * This class has been tested with DB3 and GDBM. Other drivers may have quirks - * that this class does not address yet. + * that this class does not address yet. CDB is known to be unsuitable as a + * driver due to its lack of writes. DB2 apparently segfaults PHP? * - * @author Brent Cook - * @version 0.0.12 + * @author Brent Cook <busterb@mail.utexas.edu> + * @version 0.0.14 * @access public * @package DBA */ @@ -91,7 +90,8 @@ * 'c' creates a new database if the database does not * exist and opens read-write. * @param string $driver dba driver to use - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function open ($dbName='', $mode='r', $driver=NULL) { @@ -129,7 +129,8 @@ $this->_readable = true; break; default: - return $this->raiseError("DBA: Invalid file mode: $mode", E_USER_ERROR); + return $this->raiseError("DBA: Invalid file mode: $mode", + E_USER_ERROR); } // open the index file @@ -138,15 +139,16 @@ $this->_writable = false; $this->_readable = false; return $this->raiseError("DBA: Could not open database: $dbName" - ." with mode $mode"); + ." with mode $mode"); } } /** * Closes an open database. * - * @access public - * @returns object PEAR_Error on failure + * @access public + * @return object + * @returns PEAR_Error on failure */ function close () { @@ -165,9 +167,10 @@ * If the database is already in the requested mode, then this function * does nothing. * - * @access public + * @access public * @param string $mode 'r' for read-only, 'w' for read/write - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function reopen ($mode) { @@ -200,8 +203,8 @@ /** * Returns the current read status for the database * - * @access public - * @returns boolean + * @access public + * @return boolean */ function isOpen() { @@ -211,8 +214,8 @@ /** * Returns the current read status for the database * - * @access public - * @returns boolean + * @access public + * @return boolean */ function isReadable() { @@ -222,8 +225,8 @@ /** * Returns the current write status for the database * - * @access public - * @returns boolean + * @access public + * @return boolean */ function isWritable() { @@ -233,9 +236,10 @@ /** * Deletes the value at location $key * - * @access public + * @access public * @param string $key key to delete - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function delete($key) { @@ -254,9 +258,10 @@ /** * Returns the value that is stored at $key. * - * @access public + * @access public * @param string $key key to examine - * @returns mixed the requested value on success, false on failure + * @return mixed + * @returns the requested value on success, false on failure */ function fetch($key) { @@ -277,8 +282,9 @@ /** * Returns the first key in the database * - * @access public - * @returns mixed string on success, false on failure + * @access public + * @return mixed + * @returns string on success, false on failure */ function firstkey() { @@ -293,8 +299,9 @@ /** * Returns the next key in the database, false if there is a problem * - * @access public - * @returns mixed string on success, false on failure + * @access public + * @return mixed + * @returns string on success, false on failure */ function nextkey() { @@ -313,7 +320,8 @@ * @access public * @param string $key key to insert * @param string $value value to store - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function insert($key, $value) { @@ -337,7 +345,8 @@ * @access public * @param $key string the key to insert * @param $val string the value to store - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function replace($key, $value) { @@ -363,10 +372,11 @@ * Creates a new database file if one does not exist. If it already exists, * updates the last-updated timestamp on the database * - * @access public + * @access public * @param string $dbName the database to create * @param string $driver the dba driver to use - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function create($dbName, $driver='gdbm') { @@ -379,9 +389,9 @@ /** * Indicates whether a database with given name exists * - * @access public + * @access public * @param string $dbName the database name to check for existence - * @returns boolean + * @return boolean */ function db_exists($dbName) { @@ -391,9 +401,9 @@ /** * Check whether key exists * - * @access public + * @access public * @param string $key - * @returns boolean + * @return boolean */ function exists($key) { Index: pear/DB_DBA/DBA_Compat.php diff -u pear/DB_DBA/DBA_Compat.php:1.5 pear/DB_DBA/DBA_Compat.php:1.6 --- pear/DB_DBA/DBA_Compat.php:1.5 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA_Compat.php Sat Jul 6 23:25:01 2002 @@ -17,10 +17,8 @@ // | License along with this library; if not, write to the Free Software | // | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA| // +----------------------------------------------------------------------+ -// | Author: Brent Cook <busterb@mail.utexas.edu> | -// +----------------------------------------------------------------------+ // -// $Id: DBA_Compat.php,v 1.5 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA_Compat.php,v 1.6 2002/07/07 03:25:01 busterb Exp $ /** * dba compatibility layer @@ -32,6 +30,8 @@ * * @author Brent Cook <busterb@mail.utexas.edu> * @version 0.0.14 + * @access public + * @package DBA * @see PHP dba Documentation */ Index: pear/DB_DBA/DBA_Relational.php diff -u pear/DB_DBA/DBA_Relational.php:1.22 pear/DB_DBA/DBA_Relational.php:1.23 --- pear/DB_DBA/DBA_Relational.php:1.22 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA_Relational.php Sat Jul 6 23:25:01 2002 @@ -20,29 +20,50 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: DBA_Relational.php,v 1.22 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA_Relational.php,v 1.23 2002/07/07 03:25:01 busterb Exp $ require_once 'PEAR.php'; require_once 'DB/DBA/DBA_Table.php'; /** - * a relational database manager for DBM-style databases + * A relational database manager using DBA_Table as a storage object. + * DBA_Relational extends DBA_Table by providing uniform access to multiple + * tables, automatically opening, closing and locking tables as needed by + * various operations, and provides a join operation. * - * @author Brent Cook <busterb@mail.utexas.edu> + * @author Brent Cook <busterb@mail.utexas.edu> + * @package DBA + * @access public * @version 0.0.14 */ class DBA_Relational extends PEAR { - // table handles + /** + * Handles to table objects + * @access private + * @var array + */ var $_tables=array(); - // handle to manager table; used for handling multi-table operations + /** + * Handle to manager table; used for handling multi-table operations + * @access private + * @var object + */ var $_manager; - // location of table data files + /** + * Location of table data files + * @access private + * @var string + */ var $_home; - // table driver to use + /** + * Table driver to use + * @access private + * @var string + */ var $_driver; /** @@ -50,7 +71,6 @@ * * @param string $home path where data files are stored * @param string $driver DBA driver to use - * */ function DBA_Relational($home = '', $driver = 'simple') { @@ -96,10 +116,11 @@ * Opens a table, keeps it in the list of tables. Can also reopen tables * to different file modes * - * @access private - * @param string $tableName name of the table to open - * @param char $mode mode to open the table; one of r,w,c,n - * @returns object PEAR_Error on failure + * @access private + * @param string $tableName name of the table to open + * @param char $mode mode to open the table; one of r,w,c,n + * @return object + * @returns PEAR_Error on failure */ function _openTable($tableName, $mode = 'r') { @@ -127,8 +148,8 @@ /** * Returns whether the specified table exists in the db home * - * @param string $tableName table to check existence of - * @returns boolean + * @param string $tableName table to check existence of + * @return boolean */ function tableExists($tableName) { @@ -138,10 +159,10 @@ /** * Generates a nice, ASCII table from a results set, a-la MySQL * - * @param array $results - * @param array $fields list of fields to display - * @param string $style style to display table in; 'oracle', 'mysql' - * @returns string + * @param array $results + * @param array $fields list of fields to display + * @param string $style style to display table in; 'oracle', 'mysql' + * @return string */ function formatTextResults($results, $fields = null, $style = 'oracle') { @@ -151,10 +172,11 @@ /** * Creates a new table * - * @access public + * @access public * @param string $tableName name of the table to create * @param array $schema field schema for the table - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function createTable($tableName, $schema) { @@ -175,7 +197,7 @@ * Returns an array with the stored schema for the table * * @param string $tableName - * @returns array + * @return array */ function getSchema($tableName) { @@ -190,7 +212,7 @@ /** * Returns the current read status for the database * - * @returns boolean + * @return boolean */ function isOpen($tableName) { @@ -206,7 +228,8 @@ * * @param string $tableName table on which to operate * @param array $data assoc array or ordered list of data to insert - * @returns mixed PEAR_Error on failure, the row index on success + * @return mixed + * @returns PEAR_Error on failure, the row index on success */ function insert($tableName, $data) { @@ -225,7 +248,8 @@ * @param string $tableName table on which to operate * @param string $key row id to replace * @param array $data assoc array or ordered list of data to insert - * @returns mixed PEAR_Error on failure, the row index on success + * @return mixed + * @returns PEAR_Error on failure, the row index on success */ function replace($tableName, $key, $data) { @@ -243,7 +267,8 @@ * @access public * @param string $tableName table on which to operate * @param string $key row id to delete - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function delete($tableName, $key) { @@ -261,7 +286,8 @@ * @access public * @param string $tableName table on which to operate * @param string $key row id to fetch - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function fetch($tableName, $key) { @@ -284,7 +310,8 @@ * @param string $tableName table on which to operate * @param string $rawQuery query expression for performing the select * @param array $rows rows to select on - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function select($tableName, $query, $rows=null) { @@ -307,7 +334,8 @@ * @param string $order 'a' for ascending, 'd' for descending * @param array $rows rows to sort, sorts the entire table if not * specified - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function sort($fields, $order='a', $rows) { @@ -322,7 +350,8 @@ * @param array $fields fields to project * @param array $rows rows to project, projects entire table if not * specified - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function project($fields, $rows) { @@ -335,7 +364,8 @@ * @access public * @param array $rows rows to process, uses entire table if not * specified - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function unique($rows) { @@ -356,7 +386,8 @@ * @param string $tableName table on which to operate * @param array $rows rows to finalize, if none are specified, returns * the whole table - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function finalize($tableName, $rows=null) { @@ -432,10 +463,12 @@ /** * Joins rows between two tables based on a query. * - * @access public - * @param string $tableA name of table to join - * @param string $tableB name of table to join - * @param string $rawQuery expression of how to join tableA and tableB + * @access public + * @param string $tableA name of table to join + * @param string $tableB name of table to join + * @param string $rawQuery expression of how to join tableA and tableB + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function join($tableA, $tableB, $rawQuery) { Index: pear/DB_DBA/DBA_Simple.php diff -u pear/DB_DBA/DBA_Simple.php:1.12 pear/DB_DBA/DBA_Simple.php:1.13 --- pear/DB_DBA/DBA_Simple.php:1.12 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA_Simple.php Sat Jul 6 23:25:01 2002 @@ -20,31 +20,27 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: DBA_Simple.php,v 1.12 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA_Simple.php,v 1.13 2002/07/07 03:25:01 busterb Exp $ require_once 'PEAR.php'; /** * Location in the index file for a block location - * @const DBA_LOC */ define('DBA_LOC',0); /** * Location in the index file for a block size - * @const DBA_SIZE */ define('DBA_SIZE',1); /** * Location in the index file for a block value size - * @const DBA_VSIZE */ define('DBA_VSIZE',2); /** * Location in the index file for a block key - * @const DBA_KEY */ define('DBA_KEY',3); @@ -122,7 +118,8 @@ * 'n' creates a new database and opens read-write. * 'c' creates a new database if the database does not * exist and opens read-write. - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function open($dbName='', $mode='r') { @@ -205,7 +202,8 @@ * Closes an open database. * * @access public - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function close() { @@ -231,7 +229,8 @@ * * @access public * @param string $mode 'r' for read-only, 'w' for read/write - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function reopen($mode) { @@ -278,7 +277,7 @@ * Returns the current read status for the database * * @access public - * @returns boolean + * @return boolean */ function isOpen() { @@ -289,7 +288,7 @@ * Returns the current read status for the database * * @access public - * @returns boolean + * @return boolean */ function isReadable() { @@ -300,7 +299,7 @@ * Returns the current write status for the database * * @access public - * @returns boolean + * @return boolean */ function isWritable() { @@ -312,7 +311,8 @@ * * @access public * @param string $key key to delete - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function delete($key) { @@ -336,7 +336,8 @@ * * @access public * @param string $key key to examine - * @returns mixed the requested value on success, false on failure + * @return mixed + * @returns the requested value on success, false on failure */ function fetch($key) { @@ -360,7 +361,8 @@ * Returns the first key in the database * * @access public - * @returns mixed string on success, false on failure + * @return mixed + * @returns string on success, false on failure */ function firstkey() { @@ -377,7 +379,8 @@ * Returns the next key in the database, false if there is a problem * * @access public - * @returns mixed string on success, false on failure + * @return mixed + * @returns string on success, false on failure */ function nextkey() { @@ -393,7 +396,7 @@ * Returns ths number of keys in the database * * @access public - * @returns int + * @return int */ function size() { @@ -412,7 +415,8 @@ * @access public * @param string $key key to insert * @param string $value value to store - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function insert($key, $value) { @@ -432,7 +436,8 @@ * @access public * @param $key string the key to insert * @param $val string the value to store - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function replace($key, $value) { @@ -570,7 +575,8 @@ * * @access public * @param string $dbName the database to create - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function create($dbName) { @@ -584,7 +590,7 @@ * * @access public * @param string $dbName the database name to check for existence - * @returns boolean + * @return boolean */ function db_exists($dbName) { @@ -596,7 +602,7 @@ * * @access public * @param string $key - * @returns boolean + * @return boolean */ function exists($key) { @@ -629,7 +635,6 @@ /** * Reads the entries in an index file * Assumes that $this->_idxFP is valid and readable - * * @access private */ function _readIdx() Index: pear/DB_DBA/DBA_Table.php diff -u pear/DB_DBA/DBA_Table.php:1.28 pear/DB_DBA/DBA_Table.php:1.29 --- pear/DB_DBA/DBA_Table.php:1.28 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA_Table.php Sat Jul 6 23:25:01 2002 @@ -20,29 +20,35 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: DBA_Table.php,v 1.28 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA_Table.php,v 1.29 2002/07/07 03:25:01 busterb Exp $ // require_once 'PEAR.php'; require_once 'DB/DBA/DBA.php'; /** * Reserved key used to store the schema record - * @const DBA_SCHEMA_KEY */ define('DBA_SCHEMA_KEY', '__schema__'); /** * Reserved character used to separate fields in a row - * @const DBA_FIELD_SEPARATOR */ define('DBA_FIELD_SEPARATOR', '|'); /** * DBA Table - * This class provides a simple, single-table database system. - * It uses a DBA class as the storage driver. + * This class provides a simple, table storage object. + * It uses a DBA storage object as returned by DBA::create(). + * This class is used extensively in DBA_Relational as part of + * a complete, relational database system. * - * @author Brent Cook <busterb@mail.utexas.edu> + * Enough functionality exists within this class to create and delete tables, + * insert, retrieve, delete and validate data based on a table schema, and + * perform basic database operations such as selects, projects and sorts. + * + * @author Brent Cook <busterb@mail.utexas.edu> + * @package DBA + * @access public * @version 0.0.14 */ class DBA_Table extends PEAR @@ -119,7 +125,8 @@ * @access public * @param string $tableName name of the table to open * @param char $mode mode to open the table; one of r,w,c,n - * @returns object PEAR_Error on failure + * @returns PEAR_Error on failure + * @return object */ function open($tableName, $mode = 'r') { @@ -153,7 +160,8 @@ * Closes a table * * @access public - * @returns object PEAR_Error on failure + * @returns PEAR_Error on failure + * @return object */ function close() { @@ -171,7 +179,8 @@ * * @param string $tableName name of the table to create * @param array $schema field schema for the table - * @returns object PEAR_Error on failure + * @returns PEAR_Error on failure + * @return object */ function create($tableName, $schema) { @@ -199,9 +208,11 @@ } /** - * Returns an array with the stored schema for the table + * Returns the stored schema for the table * - * @returns array + * @returns an array of the form 'fieldname'=>array(fieldmeta) on success, + * PEAR_Error on failure + * @return mixed */ function getSchema() { if ($this->isOpen()) { @@ -215,8 +226,9 @@ * Check whether table exists * * @access public - * @param string $key - * @returns boolean + * @param string $key + * @returns true if the table exists, false otherwise + * @return boolean */ function tableExists($tableName) { @@ -226,7 +238,8 @@ /** * Returns the current read status for the database * - * @returns boolean + * @returns true if the table exists, false otherwise + * @return boolean */ function isOpen() { @@ -236,7 +249,8 @@ /** * Returns the current read status for the database * - * @returns boolean + * @returns true if the table exists, false otherwise + * @return boolean */ function isReadable() { @@ -246,7 +260,8 @@ /** * Returns the current write status for the database * - * @returns boolean + * @returns true if the table exists, false otherwise + * @return boolean */ function isWritable() { @@ -256,7 +271,8 @@ /** * Returns whether a field exists in the current table's schema * - * @returns boolean + * @returns true if the table exists, false otherwise + * @return boolean */ function fieldExists($fieldName) { @@ -266,7 +282,8 @@ /** * Aquire an exclusive lock on the table * - * @returns object PEAR_Error on failure + * @returns PEAR_Error on failure + * @return object */ function lockEx() { @@ -276,7 +293,8 @@ /** * Aquire a shared lock on the table * - * @returns object PEAR_Error on failure + * @returns PEAR_Error on failure + * @return object */ function lockSh($table_name) { @@ -288,7 +306,8 @@ * This function returns the highest row index * * @access private - * @returns mixed a number or false if there are no keys + * @returns an integer or false if there are no keys + * @return mixed */ function _findMaxKey() { @@ -307,7 +326,8 @@ * Returns a unique key to be used as a row index * * @access private - * @returns integer a new key + * @returns a new key + * @return integer */ function _getUniqueKey() { @@ -332,7 +352,8 @@ * @access private * @param array $field field to pack * @param string $value value of this field to pack - * @returns string packed version of value, as per $field spec + * @returns packed version of value, as per $field spec + * @return string */ function _packField($field, $value) { @@ -420,9 +441,10 @@ /** * Converts a field from its packed representation to its original value * + * @access private * @param string $field field to convert * @param string $field packed value - * @returns mixed + * @return mixed */ function _unpackField($field, $value) { @@ -465,8 +487,10 @@ * varchar => name;varchar;size=<num>;default=<string> * numeric => name;[autoincrement];size=<num>;default=<string> * + * @access private * @param array $schema schema to pack - * @returns string the packed schema + * @returns the packed schema + * @return string */ function _packSchema($schema) { @@ -542,7 +566,7 @@ * * @access private * @param string $rawFieldString data to be unpacked into the schema - * @returns array + * @return array */ function _unpackSchema($rawFieldString) { @@ -581,7 +605,7 @@ * * @access private * @param array $data row data to pack, key=>field pairs - * @returns string + * @return string */ function _packRow($data, &$primaryKey) { @@ -641,8 +665,9 @@ * packed row. Think of this as a cross-language version of deserialize. * * @access private - * @param array packedData row data to unpack - * @returns array field=>value pairs + * @param array packedData row data to unpack + * @return array + * @returns field=>value pairs */ function _unpackRow($packedData) { @@ -659,8 +684,9 @@ * Inserts a new row in a table * * @access public - * @param array $data assoc array or ordered list of data to insert - * @returns mixed PEAR_Error on failure, the row index on success + * @param array $data assoc array or ordered list of data to insert + * @return mixed + * @returns PEAR_Error on failure, the row index on success */ function insert($data) { @@ -700,7 +726,8 @@ * @access public * @param string $key row id to replace * @param array $data assoc array or ordered list of data to insert - * @returns mixed PEAR_Error on failure, the row index on success + * @return mixed + * @returns PEAR_Error on failure, the row index on success */ function replace($key, $data) { @@ -716,7 +743,8 @@ * * @access public * @param string $key row id to delete - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function delete($key) { @@ -728,7 +756,8 @@ * * @access public * @param string $key row id to fetch - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function fetch($key) { @@ -749,7 +778,7 @@ * @access private * @param mixed $field * @param string $value - * @returns string + * @return string */ function _finalizeField($field, $value) { @@ -785,7 +814,8 @@ * @access public * @param array $rows rows to finalize, if none are specified, returns * the whole table - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function finalize($rows=null) { @@ -813,7 +843,8 @@ * @access public * @param array $rowKeys keys of rows to get, if none are specified, * returns the whole table - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function getRows($rowKeys=null) { @@ -844,7 +875,7 @@ * Returns an array of the defined field names in the table * * @access public - * @returns array + * @return array */ function getFieldNames() { @@ -858,7 +889,7 @@ * * @access private * @param string $string - * @returns string + * @return string */ function _cookQuery($query) { @@ -889,7 +920,8 @@ * @param string $rawQuery the incoming query * @param array $fieldTokens list of tokens that should be treated as * field names - * @returns string PHP code for performing a select + * @return string + * @returns PHP code for performing a select */ function _parsePHPQuery($rawQuery, $fieldTokens) { @@ -926,7 +958,8 @@ * @access public * @param string $rawQuery query expression for performing the select * @param array $rows rows to select on - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function select($rawQuery, $rows=null) { @@ -962,7 +995,7 @@ * Comparison function for sorting ascending order * * @access private - * @returns int + * @return int */ function _sortCmpA($a, $b) { @@ -977,7 +1010,7 @@ * Comparison function for sorting descending order * * @access private - * @returns int + * @return int */ function _sortCmpD($a, $b) { @@ -993,7 +1026,7 @@ * * @access private * @param string $fieldString field names to explode - * @returns array + * @return array */ function _parseFieldString($fieldString, $possibleFields) { @@ -1016,7 +1049,8 @@ * array of fields to sort by in order of preference * @param string $order 'a' for ascending, 'd' for descending * @param array $rows rows to sort - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function sort($fields, $order, $rows) { @@ -1056,7 +1090,8 @@ * @access public * @param array $fields fields to project * @param array $rows rows to project - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function project($fields, $rows) { @@ -1089,7 +1124,8 @@ * @access public * @param array $a row a * @param array $b row b - * @returns bool true if they are the same, false if they are not + * @return bool + * @returns true if they are the same, false if they are not */ function cmpRows($a, $b) { @@ -1107,7 +1143,8 @@ * * @access public * @param array $rows rows to process - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function unique($rows) { @@ -1128,10 +1165,10 @@ /** * Generates a text table from a results set, a-la MySQL * - * @param array $results - * @param array $fields list of fields to display - * @param string $style style to display table in; 'oracle', 'mysql' - * @returns string + * @param array $results + * @param array $fields list of fields to display + * @param string $style style to display table in; 'oracle', 'mysql' + * @return string */ function formatTextResults($results, $fields = null, $style = 'oracle') { Index: pear/DB_DBA/tests/test_table.php diff -u pear/DB_DBA/tests/test_table.php:1.12 pear/DB_DBA/tests/test_table.php:1.13 --- pear/DB_DBA/tests/test_table.php:1.12 Sat Jul 6 18:57:03 2002 +++ pear/DB_DBA/tests/test_table.php Sat Jul 6 23:25:01 2002 @@ -20,7 +20,7 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: test_table.php,v 1.12 2002/07/06 22:57:03 busterb Exp $ +// $Id: test_table.php,v 1.13 2002/07/07 03:25:01 busterb Exp $ // // test functionality of the dba table layer @@ -79,16 +79,5 @@ } $table->close(); -/* -$sortField = 'quantity'; -$results = $table->unique( - $table->project('brand, quantity', - $table->sort('quantity', 'd', - $table->select($query)))); -echo "Sorting by: $sortField, descending order\n"; -echo "Query: $query\n\n"; -echo DBA_Table::formatTextResults($results, array('brand', 'quantity'), 'mysql'); -*/ -//$table->close(); ?>
Index: pear/DB_DBA/DBA.php diff -u pear/DB_DBA/DBA.php:1.6 pear/DB_DBA/DBA.php:1.7 --- pear/DB_DBA/DBA.php:1.6 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA.php Sat Jul 6 23:25:00 2002 @@ -20,17 +20,29 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: DBA.php,v 1.6 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA.php,v 1.7 2002/07/07 03:25:00 busterb Exp $ // + +/** + * DBA is a set of classes for handling and extending Berkeley DB style + * databases. It works around some of the quirks in the built-in dba + * functions in PHP (e.g. gdbm does not support dba_replace), has its own + * dbm engine for installations where dba support is not included in PHP. + * + * @author Brent Cook <busterb@mail.utexas.edu> + * @version 0.0.14 + * @access public + * @package DBA + */ class DBA { /** - * Return a DBA object + * Creates a new DBA object * * @static - * @version 0.0.14 - * @param string $driver Type of storage object to return - * @return object DBA storage object, returned by reference + * @param string $driver type of storage object to return + * @return object + * @returns DBA storage object, returned by reference */ function &create($driver = 'simple') { Index: pear/DB_DBA/DBA_Builtin.php diff -u pear/DB_DBA/DBA_Builtin.php:1.6 pear/DB_DBA/DBA_Builtin.php:1.7 --- pear/DB_DBA/DBA_Builtin.php:1.6 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA_Builtin.php Sat Jul 6 23:25:00 2002 @@ -17,10 +17,8 @@ // | License along with this library; if not, write to the Free Software | // | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA| // +----------------------------------------------------------------------+ -// | Author: Brent Cook <busterb@mail.utexas.edu> | -// +----------------------------------------------------------------------+ // -// $Id: DBA_Builtin.php,v 1.6 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA_Builtin.php,v 1.7 2002/07/07 03:25:00 busterb Exp $ require_once 'PEAR.php'; @@ -30,10 +28,11 @@ * the DBA_Simple class. * * This class has been tested with DB3 and GDBM. Other drivers may have quirks - * that this class does not address yet. + * that this class does not address yet. CDB is known to be unsuitable as a + * driver due to its lack of writes. DB2 apparently segfaults PHP? * - * @author Brent Cook - * @version 0.0.12 + * @author Brent Cook <busterb@mail.utexas.edu> + * @version 0.0.14 * @access public * @package DBA */ @@ -91,7 +90,8 @@ * 'c' creates a new database if the database does not * exist and opens read-write. * @param string $driver dba driver to use - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function open ($dbName='', $mode='r', $driver=NULL) { @@ -129,7 +129,8 @@ $this->_readable = true; break; default: - return $this->raiseError("DBA: Invalid file mode: $mode", E_USER_ERROR); + return $this->raiseError("DBA: Invalid file mode: $mode", + E_USER_ERROR); } // open the index file @@ -138,15 +139,16 @@ $this->_writable = false; $this->_readable = false; return $this->raiseError("DBA: Could not open database: $dbName" - ." with mode $mode"); + ." with mode $mode"); } } /** * Closes an open database. * - * @access public - * @returns object PEAR_Error on failure + * @access public + * @return object + * @returns PEAR_Error on failure */ function close () { @@ -165,9 +167,10 @@ * If the database is already in the requested mode, then this function * does nothing. * - * @access public + * @access public * @param string $mode 'r' for read-only, 'w' for read/write - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function reopen ($mode) { @@ -200,8 +203,8 @@ /** * Returns the current read status for the database * - * @access public - * @returns boolean + * @access public + * @return boolean */ function isOpen() { @@ -211,8 +214,8 @@ /** * Returns the current read status for the database * - * @access public - * @returns boolean + * @access public + * @return boolean */ function isReadable() { @@ -222,8 +225,8 @@ /** * Returns the current write status for the database * - * @access public - * @returns boolean + * @access public + * @return boolean */ function isWritable() { @@ -233,9 +236,10 @@ /** * Deletes the value at location $key * - * @access public + * @access public * @param string $key key to delete - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function delete($key) { @@ -254,9 +258,10 @@ /** * Returns the value that is stored at $key. * - * @access public + * @access public * @param string $key key to examine - * @returns mixed the requested value on success, false on failure + * @return mixed + * @returns the requested value on success, false on failure */ function fetch($key) { @@ -277,8 +282,9 @@ /** * Returns the first key in the database * - * @access public - * @returns mixed string on success, false on failure + * @access public + * @return mixed + * @returns string on success, false on failure */ function firstkey() { @@ -293,8 +299,9 @@ /** * Returns the next key in the database, false if there is a problem * - * @access public - * @returns mixed string on success, false on failure + * @access public + * @return mixed + * @returns string on success, false on failure */ function nextkey() { @@ -313,7 +320,8 @@ * @access public * @param string $key key to insert * @param string $value value to store - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function insert($key, $value) { @@ -337,7 +345,8 @@ * @access public * @param $key string the key to insert * @param $val string the value to store - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function replace($key, $value) { @@ -363,10 +372,11 @@ * Creates a new database file if one does not exist. If it already exists, * updates the last-updated timestamp on the database * - * @access public + * @access public * @param string $dbName the database to create * @param string $driver the dba driver to use - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function create($dbName, $driver='gdbm') { @@ -379,9 +389,9 @@ /** * Indicates whether a database with given name exists * - * @access public + * @access public * @param string $dbName the database name to check for existence - * @returns boolean + * @return boolean */ function db_exists($dbName) { @@ -391,9 +401,9 @@ /** * Check whether key exists * - * @access public + * @access public * @param string $key - * @returns boolean + * @return boolean */ function exists($key) { Index: pear/DB_DBA/DBA_Compat.php diff -u pear/DB_DBA/DBA_Compat.php:1.5 pear/DB_DBA/DBA_Compat.php:1.6 --- pear/DB_DBA/DBA_Compat.php:1.5 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA_Compat.php Sat Jul 6 23:25:01 2002 @@ -17,10 +17,8 @@ // | License along with this library; if not, write to the Free Software | // | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA| // +----------------------------------------------------------------------+ -// | Author: Brent Cook <busterb@mail.utexas.edu> | -// +----------------------------------------------------------------------+ // -// $Id: DBA_Compat.php,v 1.5 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA_Compat.php,v 1.6 2002/07/07 03:25:01 busterb Exp $ /** * dba compatibility layer @@ -32,6 +30,8 @@ * * @author Brent Cook <busterb@mail.utexas.edu> * @version 0.0.14 + * @access public + * @package DBA * @see PHP dba Documentation */ Index: pear/DB_DBA/DBA_Relational.php diff -u pear/DB_DBA/DBA_Relational.php:1.22 pear/DB_DBA/DBA_Relational.php:1.23 --- pear/DB_DBA/DBA_Relational.php:1.22 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA_Relational.php Sat Jul 6 23:25:01 2002 @@ -20,29 +20,50 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: DBA_Relational.php,v 1.22 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA_Relational.php,v 1.23 2002/07/07 03:25:01 busterb Exp $ require_once 'PEAR.php'; require_once 'DB/DBA/DBA_Table.php'; /** - * a relational database manager for DBM-style databases + * A relational database manager using DBA_Table as a storage object. + * DBA_Relational extends DBA_Table by providing uniform access to multiple + * tables, automatically opening, closing and locking tables as needed by + * various operations, and provides a join operation. * - * @author Brent Cook <busterb@mail.utexas.edu> + * @author Brent Cook <busterb@mail.utexas.edu> + * @package DBA + * @access public * @version 0.0.14 */ class DBA_Relational extends PEAR { - // table handles + /** + * Handles to table objects + * @access private + * @var array + */ var $_tables=array(); - // handle to manager table; used for handling multi-table operations + /** + * Handle to manager table; used for handling multi-table operations + * @access private + * @var object + */ var $_manager; - // location of table data files + /** + * Location of table data files + * @access private + * @var string + */ var $_home; - // table driver to use + /** + * Table driver to use + * @access private + * @var string + */ var $_driver; /** @@ -50,7 +71,6 @@ * * @param string $home path where data files are stored * @param string $driver DBA driver to use - * */ function DBA_Relational($home = '', $driver = 'simple') { @@ -96,10 +116,11 @@ * Opens a table, keeps it in the list of tables. Can also reopen tables * to different file modes * - * @access private - * @param string $tableName name of the table to open - * @param char $mode mode to open the table; one of r,w,c,n - * @returns object PEAR_Error on failure + * @access private + * @param string $tableName name of the table to open + * @param char $mode mode to open the table; one of r,w,c,n + * @return object + * @returns PEAR_Error on failure */ function _openTable($tableName, $mode = 'r') { @@ -127,8 +148,8 @@ /** * Returns whether the specified table exists in the db home * - * @param string $tableName table to check existence of - * @returns boolean + * @param string $tableName table to check existence of + * @return boolean */ function tableExists($tableName) { @@ -138,10 +159,10 @@ /** * Generates a nice, ASCII table from a results set, a-la MySQL * - * @param array $results - * @param array $fields list of fields to display - * @param string $style style to display table in; 'oracle', 'mysql' - * @returns string + * @param array $results + * @param array $fields list of fields to display + * @param string $style style to display table in; 'oracle', 'mysql' + * @return string */ function formatTextResults($results, $fields = null, $style = 'oracle') { @@ -151,10 +172,11 @@ /** * Creates a new table * - * @access public + * @access public * @param string $tableName name of the table to create * @param array $schema field schema for the table - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function createTable($tableName, $schema) { @@ -175,7 +197,7 @@ * Returns an array with the stored schema for the table * * @param string $tableName - * @returns array + * @return array */ function getSchema($tableName) { @@ -190,7 +212,7 @@ /** * Returns the current read status for the database * - * @returns boolean + * @return boolean */ function isOpen($tableName) { @@ -206,7 +228,8 @@ * * @param string $tableName table on which to operate * @param array $data assoc array or ordered list of data to insert - * @returns mixed PEAR_Error on failure, the row index on success + * @return mixed + * @returns PEAR_Error on failure, the row index on success */ function insert($tableName, $data) { @@ -225,7 +248,8 @@ * @param string $tableName table on which to operate * @param string $key row id to replace * @param array $data assoc array or ordered list of data to insert - * @returns mixed PEAR_Error on failure, the row index on success + * @return mixed + * @returns PEAR_Error on failure, the row index on success */ function replace($tableName, $key, $data) { @@ -243,7 +267,8 @@ * @access public * @param string $tableName table on which to operate * @param string $key row id to delete - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function delete($tableName, $key) { @@ -261,7 +286,8 @@ * @access public * @param string $tableName table on which to operate * @param string $key row id to fetch - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function fetch($tableName, $key) { @@ -284,7 +310,8 @@ * @param string $tableName table on which to operate * @param string $rawQuery query expression for performing the select * @param array $rows rows to select on - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function select($tableName, $query, $rows=null) { @@ -307,7 +334,8 @@ * @param string $order 'a' for ascending, 'd' for descending * @param array $rows rows to sort, sorts the entire table if not * specified - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function sort($fields, $order='a', $rows) { @@ -322,7 +350,8 @@ * @param array $fields fields to project * @param array $rows rows to project, projects entire table if not * specified - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function project($fields, $rows) { @@ -335,7 +364,8 @@ * @access public * @param array $rows rows to process, uses entire table if not * specified - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function unique($rows) { @@ -356,7 +386,8 @@ * @param string $tableName table on which to operate * @param array $rows rows to finalize, if none are specified, returns * the whole table - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function finalize($tableName, $rows=null) { @@ -432,10 +463,12 @@ /** * Joins rows between two tables based on a query. * - * @access public - * @param string $tableA name of table to join - * @param string $tableB name of table to join - * @param string $rawQuery expression of how to join tableA and tableB + * @access public + * @param string $tableA name of table to join + * @param string $tableB name of table to join + * @param string $rawQuery expression of how to join tableA and tableB + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function join($tableA, $tableB, $rawQuery) { Index: pear/DB_DBA/DBA_Simple.php diff -u pear/DB_DBA/DBA_Simple.php:1.12 pear/DB_DBA/DBA_Simple.php:1.13 --- pear/DB_DBA/DBA_Simple.php:1.12 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA_Simple.php Sat Jul 6 23:25:01 2002 @@ -20,31 +20,27 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: DBA_Simple.php,v 1.12 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA_Simple.php,v 1.13 2002/07/07 03:25:01 busterb Exp $ require_once 'PEAR.php'; /** * Location in the index file for a block location - * @const DBA_LOC */ define('DBA_LOC',0); /** * Location in the index file for a block size - * @const DBA_SIZE */ define('DBA_SIZE',1); /** * Location in the index file for a block value size - * @const DBA_VSIZE */ define('DBA_VSIZE',2); /** * Location in the index file for a block key - * @const DBA_KEY */ define('DBA_KEY',3); @@ -122,7 +118,8 @@ * 'n' creates a new database and opens read-write. * 'c' creates a new database if the database does not * exist and opens read-write. - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function open($dbName='', $mode='r') { @@ -205,7 +202,8 @@ * Closes an open database. * * @access public - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function close() { @@ -231,7 +229,8 @@ * * @access public * @param string $mode 'r' for read-only, 'w' for read/write - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function reopen($mode) { @@ -278,7 +277,7 @@ * Returns the current read status for the database * * @access public - * @returns boolean + * @return boolean */ function isOpen() { @@ -289,7 +288,7 @@ * Returns the current read status for the database * * @access public - * @returns boolean + * @return boolean */ function isReadable() { @@ -300,7 +299,7 @@ * Returns the current write status for the database * * @access public - * @returns boolean + * @return boolean */ function isWritable() { @@ -312,7 +311,8 @@ * * @access public * @param string $key key to delete - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function delete($key) { @@ -336,7 +336,8 @@ * * @access public * @param string $key key to examine - * @returns mixed the requested value on success, false on failure + * @return mixed + * @returns the requested value on success, false on failure */ function fetch($key) { @@ -360,7 +361,8 @@ * Returns the first key in the database * * @access public - * @returns mixed string on success, false on failure + * @return mixed + * @returns string on success, false on failure */ function firstkey() { @@ -377,7 +379,8 @@ * Returns the next key in the database, false if there is a problem * * @access public - * @returns mixed string on success, false on failure + * @return mixed + * @returns string on success, false on failure */ function nextkey() { @@ -393,7 +396,7 @@ * Returns ths number of keys in the database * * @access public - * @returns int + * @return int */ function size() { @@ -412,7 +415,8 @@ * @access public * @param string $key key to insert * @param string $value value to store - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function insert($key, $value) { @@ -432,7 +436,8 @@ * @access public * @param $key string the key to insert * @param $val string the value to store - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function replace($key, $value) { @@ -570,7 +575,8 @@ * * @access public * @param string $dbName the database to create - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function create($dbName) { @@ -584,7 +590,7 @@ * * @access public * @param string $dbName the database name to check for existence - * @returns boolean + * @return boolean */ function db_exists($dbName) { @@ -596,7 +602,7 @@ * * @access public * @param string $key - * @returns boolean + * @return boolean */ function exists($key) { @@ -629,7 +635,6 @@ /** * Reads the entries in an index file * Assumes that $this->_idxFP is valid and readable - * * @access private */ function _readIdx() Index: pear/DB_DBA/DBA_Table.php diff -u pear/DB_DBA/DBA_Table.php:1.28 pear/DB_DBA/DBA_Table.php:1.29 --- pear/DB_DBA/DBA_Table.php:1.28 Sat Jul 6 18:57:02 2002 +++ pear/DB_DBA/DBA_Table.php Sat Jul 6 23:25:01 2002 @@ -20,29 +20,35 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: DBA_Table.php,v 1.28 2002/07/06 22:57:02 busterb Exp $ +// $Id: DBA_Table.php,v 1.29 2002/07/07 03:25:01 busterb Exp $ // require_once 'PEAR.php'; require_once 'DB/DBA/DBA.php'; /** * Reserved key used to store the schema record - * @const DBA_SCHEMA_KEY */ define('DBA_SCHEMA_KEY', '__schema__'); /** * Reserved character used to separate fields in a row - * @const DBA_FIELD_SEPARATOR */ define('DBA_FIELD_SEPARATOR', '|'); /** * DBA Table - * This class provides a simple, single-table database system. - * It uses a DBA class as the storage driver. + * This class provides a simple, table storage object. + * It uses a DBA storage object as returned by DBA::create(). + * This class is used extensively in DBA_Relational as part of + * a complete, relational database system. * - * @author Brent Cook <busterb@mail.utexas.edu> + * Enough functionality exists within this class to create and delete tables, + * insert, retrieve, delete and validate data based on a table schema, and + * perform basic database operations such as selects, projects and sorts. + * + * @author Brent Cook <busterb@mail.utexas.edu> + * @package DBA + * @access public * @version 0.0.14 */ class DBA_Table extends PEAR @@ -119,7 +125,8 @@ * @access public * @param string $tableName name of the table to open * @param char $mode mode to open the table; one of r,w,c,n - * @returns object PEAR_Error on failure + * @returns PEAR_Error on failure + * @return object */ function open($tableName, $mode = 'r') { @@ -153,7 +160,8 @@ * Closes a table * * @access public - * @returns object PEAR_Error on failure + * @returns PEAR_Error on failure + * @return object */ function close() { @@ -171,7 +179,8 @@ * * @param string $tableName name of the table to create * @param array $schema field schema for the table - * @returns object PEAR_Error on failure + * @returns PEAR_Error on failure + * @return object */ function create($tableName, $schema) { @@ -199,9 +208,11 @@ } /** - * Returns an array with the stored schema for the table + * Returns the stored schema for the table * - * @returns array + * @returns an array of the form 'fieldname'=>array(fieldmeta) on success, + * PEAR_Error on failure + * @return mixed */ function getSchema() { if ($this->isOpen()) { @@ -215,8 +226,9 @@ * Check whether table exists * * @access public - * @param string $key - * @returns boolean + * @param string $key + * @returns true if the table exists, false otherwise + * @return boolean */ function tableExists($tableName) { @@ -226,7 +238,8 @@ /** * Returns the current read status for the database * - * @returns boolean + * @returns true if the table exists, false otherwise + * @return boolean */ function isOpen() { @@ -236,7 +249,8 @@ /** * Returns the current read status for the database * - * @returns boolean + * @returns true if the table exists, false otherwise + * @return boolean */ function isReadable() { @@ -246,7 +260,8 @@ /** * Returns the current write status for the database * - * @returns boolean + * @returns true if the table exists, false otherwise + * @return boolean */ function isWritable() { @@ -256,7 +271,8 @@ /** * Returns whether a field exists in the current table's schema * - * @returns boolean + * @returns true if the table exists, false otherwise + * @return boolean */ function fieldExists($fieldName) { @@ -266,7 +282,8 @@ /** * Aquire an exclusive lock on the table * - * @returns object PEAR_Error on failure + * @returns PEAR_Error on failure + * @return object */ function lockEx() { @@ -276,7 +293,8 @@ /** * Aquire a shared lock on the table * - * @returns object PEAR_Error on failure + * @returns PEAR_Error on failure + * @return object */ function lockSh($table_name) { @@ -288,7 +306,8 @@ * This function returns the highest row index * * @access private - * @returns mixed a number or false if there are no keys + * @returns an integer or false if there are no keys + * @return mixed */ function _findMaxKey() { @@ -307,7 +326,8 @@ * Returns a unique key to be used as a row index * * @access private - * @returns integer a new key + * @returns a new key + * @return integer */ function _getUniqueKey() { @@ -332,7 +352,8 @@ * @access private * @param array $field field to pack * @param string $value value of this field to pack - * @returns string packed version of value, as per $field spec + * @returns packed version of value, as per $field spec + * @return string */ function _packField($field, $value) { @@ -420,9 +441,10 @@ /** * Converts a field from its packed representation to its original value * + * @access private * @param string $field field to convert * @param string $field packed value - * @returns mixed + * @return mixed */ function _unpackField($field, $value) { @@ -465,8 +487,10 @@ * varchar => name;varchar;size=<num>;default=<string> * numeric => name;[autoincrement];size=<num>;default=<string> * + * @access private * @param array $schema schema to pack - * @returns string the packed schema + * @returns the packed schema + * @return string */ function _packSchema($schema) { @@ -542,7 +566,7 @@ * * @access private * @param string $rawFieldString data to be unpacked into the schema - * @returns array + * @return array */ function _unpackSchema($rawFieldString) { @@ -581,7 +605,7 @@ * * @access private * @param array $data row data to pack, key=>field pairs - * @returns string + * @return string */ function _packRow($data, &$primaryKey) { @@ -641,8 +665,9 @@ * packed row. Think of this as a cross-language version of deserialize. * * @access private - * @param array packedData row data to unpack - * @returns array field=>value pairs + * @param array packedData row data to unpack + * @return array + * @returns field=>value pairs */ function _unpackRow($packedData) { @@ -659,8 +684,9 @@ * Inserts a new row in a table * * @access public - * @param array $data assoc array or ordered list of data to insert - * @returns mixed PEAR_Error on failure, the row index on success + * @param array $data assoc array or ordered list of data to insert + * @return mixed + * @returns PEAR_Error on failure, the row index on success */ function insert($data) { @@ -700,7 +726,8 @@ * @access public * @param string $key row id to replace * @param array $data assoc array or ordered list of data to insert - * @returns mixed PEAR_Error on failure, the row index on success + * @return mixed + * @returns PEAR_Error on failure, the row index on success */ function replace($key, $data) { @@ -716,7 +743,8 @@ * * @access public * @param string $key row id to delete - * @returns object PEAR_Error on failure + * @return object + * @returns PEAR_Error on failure */ function delete($key) { @@ -728,7 +756,8 @@ * * @access public * @param string $key row id to fetch - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function fetch($key) { @@ -749,7 +778,7 @@ * @access private * @param mixed $field * @param string $value - * @returns string + * @return string */ function _finalizeField($field, $value) { @@ -785,7 +814,8 @@ * @access public * @param array $rows rows to finalize, if none are specified, returns * the whole table - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function finalize($rows=null) { @@ -813,7 +843,8 @@ * @access public * @param array $rowKeys keys of rows to get, if none are specified, * returns the whole table - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function getRows($rowKeys=null) { @@ -844,7 +875,7 @@ * Returns an array of the defined field names in the table * * @access public - * @returns array + * @return array */ function getFieldNames() { @@ -858,7 +889,7 @@ * * @access private * @param string $string - * @returns string + * @return string */ function _cookQuery($query) { @@ -889,7 +920,8 @@ * @param string $rawQuery the incoming query * @param array $fieldTokens list of tokens that should be treated as * field names - * @returns string PHP code for performing a select + * @return string + * @returns PHP code for performing a select */ function _parsePHPQuery($rawQuery, $fieldTokens) { @@ -926,7 +958,8 @@ * @access public * @param string $rawQuery query expression for performing the select * @param array $rows rows to select on - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function select($rawQuery, $rows=null) { @@ -962,7 +995,7 @@ * Comparison function for sorting ascending order * * @access private - * @returns int + * @return int */ function _sortCmpA($a, $b) { @@ -977,7 +1010,7 @@ * Comparison function for sorting descending order * * @access private - * @returns int + * @return int */ function _sortCmpD($a, $b) { @@ -993,7 +1026,7 @@ * * @access private * @param string $fieldString field names to explode - * @returns array + * @return array */ function _parseFieldString($fieldString, $possibleFields) { @@ -1016,7 +1049,8 @@ * array of fields to sort by in order of preference * @param string $order 'a' for ascending, 'd' for descending * @param array $rows rows to sort - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function sort($fields, $order, $rows) { @@ -1056,7 +1090,8 @@ * @access public * @param array $fields fields to project * @param array $rows rows to project - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function project($fields, $rows) { @@ -1089,7 +1124,8 @@ * @access public * @param array $a row a * @param array $b row b - * @returns bool true if they are the same, false if they are not + * @return bool + * @returns true if they are the same, false if they are not */ function cmpRows($a, $b) { @@ -1107,7 +1143,8 @@ * * @access public * @param array $rows rows to process - * @returns mixed PEAR_Error on failure, the row array on success + * @return mixed + * @returns PEAR_Error on failure, the row array on success */ function unique($rows) { @@ -1128,10 +1165,10 @@ /** * Generates a text table from a results set, a-la MySQL * - * @param array $results - * @param array $fields list of fields to display - * @param string $style style to display table in; 'oracle', 'mysql' - * @returns string + * @param array $results + * @param array $fields list of fields to display + * @param string $style style to display table in; 'oracle', 'mysql' + * @return string */ function formatTextResults($results, $fields = null, $style = 'oracle') { Index: pear/DB_DBA/tests/test_table.php diff -u pear/DB_DBA/tests/test_table.php:1.12 pear/DB_DBA/tests/test_table.php:1.13 --- pear/DB_DBA/tests/test_table.php:1.12 Sat Jul 6 18:57:03 2002 +++ pear/DB_DBA/tests/test_table.php Sat Jul 6 23:25:01 2002 @@ -20,7 +20,7 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: test_table.php,v 1.12 2002/07/06 22:57:03 busterb Exp $ +// $Id: test_table.php,v 1.13 2002/07/07 03:25:01 busterb Exp $ // // test functionality of the dba table layer @@ -79,16 +79,5 @@ } $table->close(); -/* -$sortField = 'quantity'; -$results = $table->unique( - $table->project('brand, quantity', - $table->sort('quantity', 'd', - $table->select($query)))); -echo "Sorting by: $sortField, descending order\n"; -echo "Query: $query\n\n"; -echo DBA_Table::formatTextResults($results, array('brand', 'quantity'), 'mysql'); -*/ -//$table->close(); ?>