6.0.0-beta1
10/17/25

[#5079] DataTree_SQL getId is buggy
Summary DataTree_SQL getId is buggy
Queue Horde Framework Packages
Queue Version HEAD
Type Bug
State Resolved
Priority 1. Low
Owners
Requester x3n (at) molinier (dot) eu
Created 03/07/2007 (6799 days ago)
Due
Updated 03/13/2007 (6793 days ago)
Assigned
Resolved 03/13/2007 (6793 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
03/13/2007 10:12:44 PM Chuck Hagenbuch Comment #2
State ⇒ Resolved
Reply to this comment
Committed, thanks.
03/07/2007 05:38:19 PM x3n (at) molinier (dot) eu Comment #1
State ⇒ Unconfirmed
Priority ⇒ 1. Low
Type ⇒ Bug
Summary ⇒ DataTree_SQL getId is buggy
Queue ⇒ Horde Framework Packages
Reply to this comment
This bug has been originally posted by roel@gloudemans.info on the DEV 
list, but I think here is the right place !



A short description: the function _getId in the file DataTree/Sql.php 
is not working because the name stored in the database is not the 
absolute name (with ':') but a relative one. The $name value is 
something like 'horde.syncml:user:device', and we are querying 
directly this name to the database. Where is the orignal :



         $query = 'SELECT datatree_id FROM ' . $this->_params['table'] .

             ' WHERE group_uid = ? AND datatree_name = ?';

         $values = array($this->_params['group'], $name);

         Horde::logMessage('SQL Query by DataTree_sql::_getId(): ' . 
$query, __FILE__, __LINE__, PEAR_LOG_DEBUG);



         $result = $this->_db->getOne($query, $values);

         if (is_a($result, 'PEAR_Error')) {

             return null;

         } else {

             return $result;

         }



I propuse his solution, which simply retrieves ID of parents node, to 
create the root line. And then I'm asking the real name !



         $query = 'SELECT datatree_id FROM ' . $this->_params['table'] .

                  ' WHERE group_uid = ? AND datatree_name = ?' .

                  ' AND datatree_parents = ?';



         $rootLine=explode(':', $name);

         $id=array();



         foreach($rootLine as $node) {

           $result = $this->_db->getOne($query,

array($this->_params['group'],$node,count($id)?':'.implode(':',$id):''));

           if (is_a($result, 'PEAR_Error')) {

               return null;

           } else {

               array_push($id,$result);

           }

         }

         return $id[count($id)-1];



I d'ont if there is a better way to do that !



Best regards,





x3n

http://www.molinier.eu

Saved Queries