Beispiel #1
0
 public static function _find($model, $a)
 {
     $cond = array_shift($a);
     if (empty($cond)) {
         return array();
     }
     $ti = self::modelinfo($model);
     if (!$ti) {
         return NULL;
     }
     $limit = array_shift($a);
     if (!empty($limit) && !preg_match('/^\\s*\\d+\\s*(,\\s*\\d+)?\\s*$/', $limit)) {
         # FIXME report a better error here
         error_log("invalid limit {$limit}");
         return array();
     }
     $orderby = array_shift($a);
     list($where, $a) = self::_conditions_to_query($ti, $cond);
     if (preg_match('/^\\s*select/', $where)) {
         $q = $where;
     } else {
         $q = "select * from " . $ti['tableQ'] . " where {$where}";
     }
     if ($orderby) {
         # FIXME protect against $orderby being possibly tainted
         $q .= " order by " . $orderby;
     }
     if ($limit) {
         $q .= " limit {$limit}";
     }
     $sth = self::modeldbh($model)->prepare($q);
     $sth->execute($a);
     #error_log($sth->_stmt());
     $r = array();
     while ($o = $sth->fetchrow_object($model)) {
         $o = ObjectCache::singleton($o);
         $o->checkpoint();
         $o->_Query_bound_to_row = true;
         $r[] = $o;
     }
     return $r;
 }