Пример #1
0
 /**
  * 検索を実行する
  *
  * @return StatementIterator
  */
 public final function find()
 {
     $this->verify_class_access("call C(DAO_CLASS)->find()");
     $args = func_get_args();
     $query = new Q();
     call_user_func_array(array($query, "add"), $args);
     if (!$query->isOrder_by()) {
         foreach ($this->primary_columns() as $column) {
             $query->order($column->name());
         }
     }
     $paginator = $query->paginator();
     if ($paginator instanceof Paginator) {
         $paginator->total(call_user_func_array(array($this, "find_count"), $query->arAnd_block()));
     }
     $sql = $this->call_module("select_sql", $this, $query, $paginator);
     $statement = $this->prepare($sql->sql);
     $statement->execute($sql->vars);
     $errors = $statement->errorInfo();
     if (sizeof($errors) == 3) {
         throw new LogicException("[" . $errors[1] . "] " . $errors[2]);
     }
     return new StatementIterator($this, $statement);
 }
Пример #2
0
 protected function where_sql(Dao $dao, Q $q, array $self_columns, $require_where = null)
 {
     if ($q->isBlock()) {
         $vars = $and = array();
         foreach ($q->arAnd_block() as $qa) {
             list($where, $var) = $this->where_sql($dao, $qa, $self_columns);
             if (!empty($where)) {
                 $and[] = $where;
                 $vars = array_merge($vars, $var);
             }
         }
         $where_sql = empty($and) ? "" : "(" . implode(" and ", $and) . ") ";
         foreach ($q->arOr_block() as $or_block) {
             foreach ($or_block as $qa) {
                 list($where, $var) = $this->where_sql($dao, $qa, $self_columns);
                 if (!empty($where)) {
                     $where_sql .= " or (" . $where . ") ";
                     $vars = array_merge($vars, $var);
                 }
             }
         }
         if (empty($where_sql)) {
             $where_sql = $require_where;
         } else {
             if (!empty($require_where)) {
                 $where_sql = "(" . $require_where . ") and (" . $where_sql . ")";
             }
         }
         return array($where_sql, $vars);
     }
     if ($q->type() == Q::MATCH) {
         return $this->where_sql($dao, $this->where_match($q, $self_columns), $self_columns);
     }
     return $this->where_cond($dao, $q, $self_columns);
 }