private function _compile_select() { $values = array(); $sql = 'SELECT ' . (isset($this->select_distinct) ? 'DISTINCT ' : ''); $sql .= Columns::create($this->_parameter('select'))->sql(); if (isset($this->from)) { $sql .= "\nFROM " . implode(', ', $this->_parameter('from')); } if (isset($this->join)) { foreach ($this->_parameter('join') as $join) { $type = $join['direction'] !== null ? strtoupper($join['direction']) . ' ' : ''; $sql .= "\n{$type}JOIN " . Columns::create($join['table'])->sql(); $on = Conditions::create()->add($join['on'])->compile(); $sql .= "\n\tON " . $on['sql']; $values = array_merge($values, $on['values']); } } if (isset($this->where)) { $where = Conditions::create()->add($this->_parameter('where'))->compile(); $sql .= "\nWHERE " . $where['sql']; $values = array_merge($values, $where['values']); } if (isset($this->group_by)) { $sql .= "\nGROUP BY " . Columns::create($this->_parameter('group_by'))->sql(); } if (isset($this->order_by)) { $sql .= "\nORDER BY "; $order_by = array(); foreach ($this->_parameter('order_by') as $column) { $s = Columns::create($column['column'])->sql(); if (isset($column['collate'])) { $s .= " COLLATE {$column['collate']}"; } if (isset($column['order'])) { $s .= ' ' . strtoupper($column['order']); } $order_by[] = $s; } $sql .= implode(', ', $order_by); } if (isset($this->limit)) { $sql .= "\nLIMIT " . $this->_parameter_first('limit'); } return array('sql' => $sql, 'values' => $values); }
public function testCreate() { $c = \Snowfire\Database\Query\Columns::create('column'); $this->assertEquals('`column`', $c->sql()); }