Exemplo n.º 1
0
 /**
  * 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, ', ');
 }
Exemplo n.º 2
0
 /**
  * @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} " : '');
 }
Exemplo n.º 3
0
 /**
  * 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), ', ');
 }
Exemplo n.º 4
0
 /**
  * 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), ', ');
 }