/**
  * @param string $form  The form name.
  * @param boolean $parent. Defaults to false.    If it is scalar and non-boolean, it is consider to be the ID of the parent, 
  * and then we get all forms with parent the given id.
  * @param mixed $where_data array or class implementing ArrayAccess, Iterator, and Countable (e.g. MagicDataNode) . the where data.  
  * @param array $ordering. An array of fields to order by.  Defaults to the empty array.  Prepend a - to order by in descending order.
  * @param mixed $limit. Defaults to false.  It true, returns only one result.  If an integer it is the numeber of records to limit to.
  *  If it is as an array of two integers, it is the offset and then number of results to limit to.  
  * @returns mixed an array of matching form ids.  However, ff $limit_one is true or 1 or 
  * array ($offset,1) then then we return either the id or false,  if none found or there was an error.
  */
 public function search($form, $parent = false, $where_data = array(), $ordering = array(), $limit = false)
 {
     $qry = $this->getFields($form, array('id' => 'id'), $parent, $where_data, $ordering, $limit);
     $limit_one = false;
     if (is_array($limit)) {
         if (count($limit) == 2) {
             end($limit);
             if (current($limit) == 1) {
                 $limit_one = true;
             }
         }
     } else {
         $limit_one = $limit === true || is_numeric($limit) && $limit == 1;
     }
     if (!$qry) {
         // The form may not exist yet so nothing to query so return false since nothing can be found.
         if ($limit_one) {
             return false;
         } else {
             return array();
         }
     }
     if (!$qry) {
         return parent::search($form, $parent, $where_data, $ordering, $limit);
     }
     $results = $this->db->query($qry);
     if (I2CE::pearError($results, "Bad query -- {$qry}")) {
         return parent::search($form, $parent, $where_data, $ordering, $limit);
     }
     $this->queryLastListCount($form);
     if ($limit_one) {
         //if (($data = $results->fetchRow()) !== false) {
         if ($data = $results->fetchRow()) {
             return $data->id;
         } else {
             return false;
         }
     } else {
         $res = array();
         while ($data = $results->fetchRow()) {
             $res[] = $data->id;
         }
         $results->free();
         return $res;
     }
 }