cvs: pear /Structures_DataGrid/DataGrid/DataSource DBTable.php

From: Date: Tue, 24 Oct 2006 17:03:13 +0000
Subject: cvs: pear /Structures_DataGrid/DataGrid/DataSource DBTable.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-42791@lists.php.net to get a copy of this message
wiesemann Tue Oct 24 17:03:13 2006 UTC Modified files: /pear/Structures_DataGrid/DataGrid/DataSource DBTable.php Log: - added support for primary keys consisting of multiple fields - comment updates http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/DataGrid/DataSource/DBTable.php?r1=1.20&r2=1.21&diff_format=u Index: pear/Structures_DataGrid/DataGrid/DataSource/DBTable.php diff -u pear/Structures_DataGrid/DataGrid/DataSource/DBTable.php:1.20 pear/Structures_DataGrid/DataGrid/DataSource/DBTable.php:1.21 --- pear/Structures_DataGrid/DataGrid/DataSource/DBTable.php:1.20 Sun Oct 22 17:08:45 2006 +++ pear/Structures_DataGrid/DataGrid/DataSource/DBTable.php Tue Oct 24 17:03:12 2006 @@ -21,9 +21,9 @@ * +----------------------------------------------------------------------+ * </pre> * - * CSV file id: $Id: DBTable.php,v 1.20 2006/10/22 17:08:45 wiesemann Exp $ + * CSV file id: $Id: DBTable.php,v 1.21 2006/10/24 17:03:12 wiesemann Exp $ * - * @version $Revision: 1.20 $ + * @version $Revision: 1.21 $ * @package Structures_DataGrid_DataSource_DBTable * @category Structures */ @@ -59,7 +59,7 @@ * for example, created your database table yourself and did not setup the $idx * array, you can use the 'primary_key' option to define the primary key field. * - * @version $Revision: 1.20 $ + * @version $Revision: 1.21 $ * @author Andrew S. Nagy <asnagy@php.net> * @author Mark Wiesemann <wiesemann@php.net> * @access public @@ -239,7 +239,7 @@ /** * Return the primary key field name or numerical index * - * @return mixed on success: Field name or numerical index + * @return mixed on success: Field name(s) of primary/unique fields * on error: PEAR_Error with message 'No primary key found' * @access protected */ @@ -252,13 +252,8 @@ foreach ($this->_object->idx as $idxname => $val) { list($type, $cols) = DB_Table_Manager::_getIndexTypeAndColumns($val, $idxname); - if (($type == 'primary' || $type == 'unique')) { - if ( is_string($cols) - || (is_array($cols) && count($cols) == 1) - ) { - return $cols; - } - // FIXME: add handling for keys consisting of multiple fields + if ($type == 'primary' || $type == 'unique') { + return (array)$cols; } } return PEAR::raiseError('No primary key found'); @@ -282,7 +277,7 @@ } /** - * Record updating method prototype + * Record updating method * * @param string $key Unique record identifier * @param array $data Associative array of the form: @@ -296,9 +291,12 @@ if (PEAR::isError($primary_key)) { return $primary_key; } - // FIXME: add handling for keys consisting of multiple fields - $where = $primary_key . '=' . $this->_object->quote($key); - $result = $this->_object->update($data, $where); + $where = array(); + foreach ($primary_key as $single_key) { + $where[] = $single_key . '=' . $this->_object->quote($key[$single_key]); + } + $where_str = join(' AND ', $where); + $result = $this->_object->update($data, $where_str); if (PEAR::isError($result)) { return $result; } @@ -318,9 +316,12 @@ if (PEAR::isError($primary_key)) { return $primary_key; } - // FIXME: add handling for keys consisting of multiple fields - $where = $this->getPrimaryKey() . '=' . $this->_object->quote($key); - $result = $this->_object->delete($where); + $where = array(); + foreach ($primary_key as $single_key) { + $where[] = $single_key . '=' . $this->_object->quote($key[$single_key]); + } + $where_str = join(' AND ', $where); + $result = $this->_object->delete($where_str); if (PEAR::isError($result)) { return $result; }

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