/** * @inheritdoc */ protected function generate() { $command = 'SELECT ' . ($this->getPart(CmdSelect::PART_DISTINCT) ? 'DISTINCT ' : '') . Assembly::appendDirectly($this->getPart(CmdSelect::PART_COLUMNS) ?: array('*'), ','); $union = $this->getPart(CmdSelect::PART_UNION); $from = $this->getPart(CmdSelect::PART_FROM); if (!$from && !$union) { return $command; } $lock = $this->getPart(CmdSelect::PART_LOCK); $command .= Assembly::append('FROM', $from, ' ') . Assembly::appendWhere($this->getPart(CmdSelect::PART_WHERE)) . Assembly::append('GROUP BY', $this->getPart(CmdSelect::PART_GROUP_BY)) . ($this->getPart(CmdSelect::PART_WITH_ROLL_UP) ? 'WITH ROLLUP ' : '') . Assembly::append('HAVING', $this->getPart(CmdSelect::PART_HAVING)) . Assembly::append('ORDER BY', $this->getPart(CmdSelect::PART_ORDER_BY)) . Assembly::append('LIMIT', $this->getPart(CmdSelect::PART_LIMIT)); if ($union) { $union = implode(' ', $union); $command = "({$command}) {$union}"; } return $command . ($lock ? "{$lock} " : ''); }
/** * Combined all the parts into one sql. * @return string Created query. */ protected function generate() { return 'UPDATE ' . ($this->getPart(CmdUpdate::PART_IGNORE) ? 'IGNORE ' : '') . $this->getPart(CmdUpdate::PART_TABLE) . ' ' . Assembly::appendSet($this->getPart(CmdUpdate::PART_SET), true) . Assembly::appendWhere($this->getPart(CmdUpdate::PART_WHERE), true) . Assembly::appendOrderBy($this->getPart(CmdUpdate::PART_ORDER_BY)) . Assembly::appendLimit($this->getPart(CmdUpdate::PART_LIMIT), $this->getBind(CmdUpdate::PART_LIMIT)); }
/** * Combine all the parts into one sql. * @return string Created query. */ protected function generate() { return 'DELETE FROM ' . $this->getPart(CmdDelete::PART_FROM) . ' ' . Assembly::appendWhere($this->getPart(CmdDelete::PART_WHERE), true) . Assembly::appendOrderBy($this->getPart(CmdDelete::PART_ORDER_BY)) . Assembly::appendLimit($this->getPart(CmdDelete::PART_LIMIT), $this->getBind(CmdDelete::PART_LIMIT)); }