/** * Append set clause. * @param array $values Expressions of the set clause * @param bool $forceExist If true, $values must have at least one value * @return string * @throws SquidException */ public static function appendSet($values, $forceExist = false) { if ($forceExist && !$values) { throw new SquidException('SET clause must be present for this type of command!'); } return Assembly::append('SET', $values, ', '); }
/** * @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} " : ''); }
/** * Combine all the parts into one sql. * @return string Created query. */ protected function generate() { return parent::generate() . Assembly::append('ON DUPLICATE KEY UPDATE', $this->getPart(CmdUpsert::$PART_SET), ', '); }
/** * 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)); }
/** * Combined all the parts into one sql. * @return string Created query. */ protected function generate() { if (!$this->getPart(CmdInsert::PART_INTO)) { throw new SquidException('Target table must be defined for Insert command. ' . 'into() was not called or called with empty value'); } $command = 'INSERT ' . ($this->getPart(CmdInsert::PART_IGNORE) ? 'IGNORE ' : '') . 'INTO `' . $this->getPart(CmdInsert::PART_INTO) . '` '; if ($this->fields) { $command .= '(`' . implode('`,`', $this->fields) . '`) '; } $as = $this->getPart(CmdInsert::PART_AS); if ($as) { return $command . $as; } return $command . Assembly::append('VALUES', $this->getPart(CmdInsert::PART_VALUES), ', '); }