phpgroupware-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [phpGroupWare-developers] is the db class reentrant ? (following an


From: Dave Hall
Subject: Re: [phpGroupWare-developers] is the db class reentrant ? (following an old post of sigurd in 2005)
Date: Thu, 10 Apr 2008 07:38:01 +1000

On Wed, 2008-04-09 at 17:10 +0200, Benoit Hamet wrote:
> Hi all,
> 
> I was trying to "quickly fix" the note apps for some notices about
> get_var, when I notice some weird thing :
> 
> Notes display only one note ...


Nothing weird, the db class only allows one result set at a time.  See
below for the fix.

> Further investigations let me point this :
> 
> in notes/inc/class.sonotes.inc.php I got :
> 
> around line 130 :
>   while ($this->db->next_record())
>   {
>      $ngrants = $this->grants[$this->db->f('note_owner')];
>      $notes[$this->db->f('note_id')] = array
>      (
>       'note_id'       => $this->db->f('note_id'),
>       'owner_id'      => $this->db->f('note_owner'),
>       'owner'         =>
> $GLOBALS['phpgw']->accounts->id2name($this->db->f('note_owner')),
>       'access'        => $this->db->f('note_access'),
>       'date'          =>
> $GLOBALS['phpgw']->common->show_date($this->db->f('note_date')),
>       'cat_id'        => $this->db->f('note_category'),
>       'content'       => $this->db->f('note_content', true),
>       'grants'        => $ngrants
>      );
>   }
> 
> of course, removing the line 'owner'         =>
> $GLOBALS['phpgw']->accounts->id2name($this->db->f('note_owner')),
> 
> solve the problem, which let me think about a reentrant problem (so a
> new query is done using the same db object, and so next_record() is
> totaly wrong next time ...).

IMHO this should be moved the bo layer.  This is business logic not
storage logic.  Fetch the data quickly then move on.  In the bo layer
you can use a foreach loop which passes the element by reference.

Something like this

// example using new trunk code
foreach ( $notes as &$note )
{
        $note['owner'] = (string) 
$GLOBALS['phpgw']->accounts->get($note['owner_id'];
}

Gotta love PHP 5 :)

Cheers

Dave





reply via email to

[Prev in Thread] Current Thread [Next in Thread]