Ejemplo n.º 1
0
 public function toSql()
 {
     $sql = "UPDATE ";
     $params = array();
     $placeholders = array();
     // Table name
     if (is_array($this->table_name)) {
         list($table_name, $alias) = $this->table_name;
         $sql .= $this->sanitizeField($table_name) . " AS " . $this->sanitizeField($alias);
     } else {
         $sql .= $this->sanitizeField($this->table_name);
     }
     // SET
     $sql .= "\n\tSET\n";
     foreach ($this->values as $column => $value) {
         if ($value instanceof Raw) {
             $params = array_merge($params, $value->getParams());
             $placeholders[] = "\t\t" . $this->sanitizeField($column) . " = " . $value;
         } else {
             $params[] = $value;
             $placeholders[] = "\t\t" . $this->sanitizeField($column) . " = ?";
         }
     }
     $sql .= implode(",\n", $placeholders) . "\n";
     // Where
     if (count($this->where) > 0) {
         $criteria_builder = new CriteriaBuilder($this->adapter, $this->where);
         $where = $criteria_builder->toSql();
         $sql .= "\tWHERE " . $where['sql'];
         $params = array_merge($params, $where['params']);
     }
     return compact('sql', 'params');
 }
Ejemplo n.º 2
0
 public function toSql()
 {
     $sql = "DELETE FROM ";
     $params = array();
     // Table name
     if (is_array($this->table_name)) {
         list($table_name, $alias) = $this->table_name;
         $sql .= $this->sanitizeField($table_name) . " AS " . $this->sanitizeField($alias);
     } else {
         $sql .= $this->sanitizeField($this->table_name);
     }
     // Where
     if (count($this->where) > 0) {
         $criteria_builder = new CriteriaBuilder($this->adapter, $this->where);
         $where = $criteria_builder->toSql();
         $sql .= "\n\tWHERE " . $where['sql'];
         $params = $where['params'];
     }
     return compact('sql', 'params');
 }
Ejemplo n.º 3
0
 public function toSql()
 {
     extract(parent::toSql());
     if (is_array($this->table)) {
         list($table, $alias) = $this->table;
         $table = $this->sanitizeField($table) . " AS " . $this->sanitizeField($alias);
     } else {
         if ($this->table instanceof Raw) {
             $table = (string) $raw;
         } else {
             $table = $this->sanitizeField($this->table);
         }
     }
     $sql = $this->join_type . " JOIN " . $table . " ON " . $sql;
     return compact('sql', 'params');
 }
Ejemplo n.º 4
0
 public function toSql()
 {
     $sql = "SELECT ";
     $params = array();
     if (count($this->columns) > 0) {
         $sql .= implode(", ", $this->columns) . "\n";
     } else {
         $sql .= "*\n";
     }
     if (is_array($this->table_name)) {
         list($table_name, $alias) = $this->table_name;
         $table_name = $this->sanitizeField($table_name) . " AS " . $this->sanitizeField($alias);
     } else {
         $table_name = $this->sanitizeField($this->table_name);
     }
     $sql .= "\tFROM " . $table_name . "\n";
     // Joins
     if (count($this->joins) > 0) {
         foreach ($this->joins as $join_builder) {
             $join = $join_builder->toSql();
             $sql .= "\t" . $join['sql'] . "\n";
         }
     }
     // Where
     if (count($this->where) > 0) {
         $criteria_builder = new CriteriaBuilder($this->adapter, $this->where);
         $where = $criteria_builder->toSql();
         $sql .= "\tWHERE " . $where['sql'] . "\n";
         $params = array_merge($params, $where['params']);
     }
     // Group by
     if (count($this->group_by) > 0) {
         $sql .= "\tGROUP BY " . implode(", ", $this->group_by) . "\n";
     }
     // Having
     if (count($this->having) > 0) {
         $criteria_builder = new CriteriaBuilder($this->adapter, $this->having);
         $having = $criteria_builder->toSql();
         $sql .= "\tHAVING " . $having['sql'] . "\n";
         $params = array_merge($params, $having['params']);
     }
     // Order by
     if (count($this->order_by) > 0) {
         $sql .= "\tORDER BY " . implode(", ", $this->order_by) . "\n";
     }
     // Limit
     if ($this->limit_row_count !== null) {
         $sql .= "\tLIMIT ";
         if ($this->limit_offset !== null) {
             $sql .= $this->limit_offset . ", ";
         }
         $sql .= $this->limit_row_count . "\n";
     }
     return compact('sql', 'params');
 }