Home > Archive > PHP Pear > July 2005 > Re: [PEAR] DB_DataObject multiple deletes
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: [PEAR] DB_DataObject multiple deletes
|
|
| Justin Patrin 2005-07-27, 10:00 pm |
| On 7/27/05, Etienne van Tonder <evt@infoware.com.au> wrote:
> Hi Justin,
>=20
> It produces the following error and does not perform the find sql:
>=20
> Undefined index: data_select
[snip]
Yes, I saw all that before. Did you try checking the debug output like I as=
ked?
> "Justin Patrin" <papercrane@gmail.com> wrote in message
> news:432beae050727091955040f73@mail.gmail.com...
>=20
> Yes, this should work fine. You should also be able to delete with a
> fetch() loop. Are you sure the data is being fetch properly? Try
> doing:
> DB_DataObject::debugLevel(1);
> and watching for errors. You can use up to 5 for more information.
> --
> Justin Patrin
>=20
--=20
Justin Patrin
| |
| Etienne van Tonder 2005-07-27, 10:01 pm |
| 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?
|
|
|
|
|