Ejemplo n.º 1
0
 public function create_sql(Dao $dao)
 {
     $insert = $vars = array();
     $autoid = null;
     foreach ($dao->self_columns() as $column) {
         $insert[] = '`' . $column->column() . '`';
         $vars[] = $this->update_value($dao, $column->name());
         if ($column->auto()) {
             $autoid = $column->name();
         }
     }
     return Dao::daq('insert into `' . $column->table() . '`(' . implode(',', $insert) . ') values (' . implode(',', array_fill(0, count($insert), '?')) . ');', $vars, $autoid);
 }
Ejemplo n.º 2
0
 public function select_sql(Dao $dao, Q $query, $paginator)
 {
     $select = $from = $order = array();
     $self_columns = $dao->self_columns();
     foreach ($dao->columns() as $column) {
         $select[] = $column->table_alias() . ".`" . $column->column() . "` " . $column->column_alias();
         $from[$column->table_alias()] = $column->table() . " " . $column->table_alias();
     }
     foreach ($query->order_by() as $q) {
         foreach ($q->arArg1() as $column_str) {
             $order[] = $this->column($column_str, $self_columns)->column_alias() . ($q->type() == Q::ORDER_ASC ? " asc" : " desc");
         }
     }
     list($where_sql, $where_vars) = $this->where_sql($dao, $query, $self_columns, $this->where_cond_columns($dao, $from));
     return (object) array("sql" => "select " . implode(",", $select) . " from " . implode(",", $from) . (empty($where_sql) ? "" : " where " . $where_sql) . (empty($order) ? "" : " order by " . implode(",", $order)) . ($paginator instanceof Paginator ? sprintf(" limit %d,%d ", $paginator->offset(), $paginator->limit()) : ""), "vars" => $where_vars);
 }