cvs: pear /DBA DBA_Simple.php DBA_Table.php /DBA/tests test_table.php

From: Date: Wed, 10 Jul 2002 17:57:31 +0000
Subject: cvs: pear /DBA DBA_Simple.php DBA_Table.php /DBA/tests test_table.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-5021@lists.php.net to get a copy of this message
busterb Wed Jul 10 13:57:31 2002 EDT Modified files: /pear/DBA DBA_Simple.php DBA_Table.php /pear/DBA/tests test_table.php Log: Oops, let me try that again Index: pear/DBA/DBA_Simple.php diff -u pear/DBA/DBA_Simple.php:1.19 pear/DBA/DBA_Simple.php:1.20 --- pear/DBA/DBA_Simple.php:1.19 Mon Jul 8 13:15:59 2002 +++ pear/DBA/DBA_Simple.php Wed Jul 10 13:57:30 2002 @@ -18,7 +18,7 @@ // | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA| // +----------------------------------------------------------------------+ // -// $Id: DBA_Simple.php,v 1.19 2002/07/08 17:15:59 busterb Exp $ +// $Id: DBA_Simple.php,v 1.20 2002/07/10 17:57:30 busterb Exp $ require_once 'PEAR.php'; @@ -325,7 +325,7 @@ * @param string $key key to examine * @return mixed the requested value on success, false on failure */ - function fetch($key) + function &fetch($key) { if ($this->isReadable()) { if (!isset($this->_usedBlocks[$key])) { @@ -333,7 +333,7 @@ ', it does not exist'); } else { fseek($this->_datFP, $this->_usedBlocks[$key][DBA_LOC]); - return fread($this->_datFP, $this->_usedBlocks[$key][DBA_VSIZE]); + return fread($this->_datFP,$this->_usedBlocks[$key][DBA_VSIZE]); } } else { return $this->raiseError('DBA: cannot fetch '.$key.' on '. Index: pear/DBA/DBA_Table.php diff -u pear/DBA/DBA_Table.php:1.35 pear/DBA/DBA_Table.php:1.36 --- pear/DBA/DBA_Table.php:1.35 Mon Jul 8 13:15:59 2002 +++ pear/DBA/DBA_Table.php Wed Jul 10 13:57:30 2002 @@ -18,7 +18,7 @@ // | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA| // +----------------------------------------------------------------------+ // -// $Id: DBA_Table.php,v 1.35 2002/07/08 17:15:59 busterb Exp $ +// $Id: DBA_Table.php,v 1.36 2002/07/10 17:57:30 busterb Exp $ // require_once 'PEAR.php'; require_once 'DB/DBA/DBA.php'; @@ -694,7 +694,34 @@ } } else { - return $this->raiseError('DBA: table not open'); + return $this->raiseError('DBA: table not writable'); + } + } + + /** + * Replaces rows that match $rawQuery with $ + * + * @access public + * @param string $rawQuery query expression for performing the remove + * @param array $rows rows to select on + * @return object PEAR_Error on failure + */ + function replace($rawQuery, $data, $rows=null) + { + $rows =& $this->select($rawQuery, $rows); + if (PEAR::isError($rows)) { + return $rows; + } + + $packedRow =& $this->_packRow($data); + if (PEAR::isError($packedRow)) { + return $packedRow; + } + foreach (array_keys($rows) as $rowKey) { + $result = $this->_dba->replace($rowKey, $packedRow); + if (PEAR::isError($result)) { + return $result; + } } } @@ -706,23 +733,49 @@ * @param array $data assoc array or ordered list of data to insert * @return mixed PEAR_Error on failure, the row index on success */ - function replace($key, $data) + function replaceKey($key, $data) { if ($this->isOpen()) { - return $this->_dba->replace($key, $this->_packRow($data)); + $packedRow =& $this->_packRow($data); + if (PEAR::isError($packedRow)) { + return $packedRow; + } + return $this->_dba->replace($key, $packedRow); } else { return $this->raiseError('DBA: table not open'); } } /** - * Removes an existing row in a table + * Removes existing rows from table that match $rawQuery + * + * @access public + * @param string $rawQuery query expression for performing the remove + * @param array $rows rows to select on + * @return object PEAR_Error on failure + */ + function remove($rawQuery, $rows=null) + { + $rows =& $this->select($rawQuery, $rows); + if (PEAR::isError($rows)) { + return $rows; + } + foreach (array_keys($rows) as $rowKey) { + $result = $this->_dba->remove($rowKey); + if (PEAR::isError($result)) { + return $result; + } + } + } + + /** + * Removes an existing row from a table, referenced by the row key * * @access public * @param string $key row id to remove * @return object PEAR_Error on failure */ - function remove($key) + function removeKey($key) { return $this->_dba->remove($key); } @@ -931,7 +984,7 @@ * @param array $rows rows to select on * @return mixed PEAR_Error on failure, the row array on success */ - function select($rawQuery, $rows=null) + function &select($rawQuery, $rows=null) { if ($this->_dba->isOpen()) { Index: pear/DBA/tests/test_table.php diff -u pear/DBA/tests/test_table.php:1.13 pear/DBA/tests/test_table.php:1.14 --- pear/DBA/tests/test_table.php:1.13 Sat Jul 6 23:25:01 2002 +++ pear/DBA/tests/test_table.php Wed Jul 10 13:57:30 2002 @@ -20,7 +20,7 @@ // | Author: Brent Cook <busterb@mail.utexas.edu> | // +----------------------------------------------------------------------+ // -// $Id: test_table.php,v 1.13 2002/07/07 03:25:01 busterb Exp $ +// $Id: test_table.php,v 1.14 2002/07/10 17:57:30 busterb Exp $ // // test functionality of the dba table layer @@ -38,7 +38,8 @@ } // open and close table multiple times while inserting -$result = $table->open('hats', 'w'); +foreach (array('w','r') as $mode) { +$result = $table->open('hats', $mode); if (PEAR::isError($result)) { echo $result->getMessage()."\n"; exit; @@ -50,7 +51,7 @@ foreach ($hats as $hat) { $result = $table->insert($hat); if (PEAR::isError($result)) { - echo $result->getMessage()."\n"; + echo 'Could not insert: '.$result->getMessage()."\n"; } } } @@ -62,7 +63,9 @@ '$table->sort("quantity, hat_id", "a", $table->select("*"))', '$table->sort(array("quantity", "hat_id"), "a", $table->getRows())', '$table->sort("lastshipment", "d", $table->select("*"))', - '$table->unique($table->project("brand,quantity, type",$table->sort("quantity", "d", $table->select("type != \'top hat\'"))))' + '$table->unique($table->project("brand,quantity, type",$table->sort("quantity", "d", $table->select("type != \'top hat\'"))))', + '$table->remove("type == bowler")', + '$table->project("brand, type", $table->select("*"))', ); foreach ($queries as $query) { @@ -79,5 +82,6 @@ } $table->close(); +} ?>

« previous php.pear.cvs (#5021) next »