Re: DB_DataObject multiple deletes
| From: | Etienne van Tonder | Date: | Wed, 27 Jul 2005 23:32:22 +0000 |
| Subject: | Re: DB_DataObject multiple deletes | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-20168@lists.php.net to get a copy of this message | ||
Hi Justin,
I did, everything seems to work fine upto the code I sent you. I've traced
into the code a bit further and this is what seems to be happening:
First get(52) works fine and $_query array contains all elements reset to ''
due to $this->_query = $query_before;
I then call delete() which resets $_query and sets the condition array
element, ie
$this->_query = array(); // as it's probably unset!
$this->_query['condition'] = ''; // default behaviour not to use where
condition
$this->_build_condition($this->table(),$keys);
performs the delete without any problems, the problem is now $_query
contains:
$_query['condition'] = " WHERE profile.profile_id_pf = 52"
When I do the second get(53) it calls find(1) and fails here as mentioned
earlier, ie
$sql = 'SELECT ' .
$this->_query['data_select'] .
' FROM ' . ($quoteIdentifiers ?
$DB->quoteIdentifier($this->__table) : $this->__table) . " " .
$this->_join .
$this->_query['condition'] . ' '.
$this->_query['group_by'] . ' '.
$this->_query['having'] . ' '.
$this->_query['order_by'] . ' ';
as the only element in the $_query array is $_query['condition']. So it
seems the problem is that the delete function is not resetting the $_query
array. If I add the following code it does not generate the error as I
manual reset the array, ie:
$_query = array(
'condition' => '', // the WHERE condition
'group_by' => '', // the GROUP BY condition
'order_by' => '', // the ORDER BY condition
'having' => '', // the HAVING condition
'limit_start' => '', // the LIMIT condition
'limit_count' => '', // the LIMIT condition
'data_select' => '*', // the columns to be SELECTed
);
foreach($ridarray as $rid => $val)
{
$dbtable->_query = $_query;
if ($rid > 0)
{
if ($dbtable->get($rid) > 0)
{
$dbtable->delete();
}
}
}
This overcomes the index not defined error, but then I face the next issue
which is that on the second get(53) the object still contains the data from
the previous get(52) which means it will try and build a where clause with
the data elements, which means the record will never be found as it contains
a mixture of new and old data.
So a delete in a loop will not work unless:
1. the $_query array is reset after the delete to overcome the undefined
index problem
2. there is a method to clear all the data from the previous get.
Regards,
Etienne.
"Justin Patrin" <papercrane@gmail.com> wrote in message
news:432beae050727154656f61b78@mail.gmail.com...
On 7/27/05, Etienne van Tonder <evt@infoware.com.au> wrote:
> Hi Justin,
>
> It produces the following error and does not perform the find sql:
>
> Undefined index: data_select
[snip]
Yes, I saw all that before. Did you try checking the debug output like I
asked?