public function toDialectString(Dialect $dialect) { if ($this->field instanceof SelectQuery || $this->field instanceof LogicalObject) { return '(' . $dialect->fieldToString($this->field) . ')'; } else { return parent::toDialectString($dialect); } }
public function toDialectString(Dialect $dialect) { if ($this->type == DataType::JSON || $this->type == DataType::JSONB) { return $dialect->quoteJson($this->getValue(), $this->type); } else { return $dialect->quoteArray($this->getValue(), $this->type); } }
public function toDialectString(Dialect $dialect) { $string = '(' . $dialect->toFieldString($this->left) . ' ' . $this->logic . ' '; $right = $this->right; if ($right instanceof DialectString) { $string .= '(' . $right->toDialectString($dialect) . ')'; } elseif (is_array($right)) { $string .= SQLArray::create($right)->toDialectString($dialect); } else { throw new WrongArgumentException('sql select or array accepted by ' . $this->logic); } $string .= ')'; return $string; }
public function toDialectString(Dialect $dialect) { if ($this->where) { $deleteStr = 'DELETE FROM ' . $dialect->quoteTable($this->table) . parent::toDialectString($dialect); $this->checkReturning($dialect); if (empty($this->returning)) { return $deleteStr; } else { $query = $deleteStr . ' RETURNING ' . $this->toDialectStringReturning($dialect); return $query; } } else { throw new WrongArgumentException("leave '{$this->table}' table alone in peace, bastard"); } }
private function dumpTargets(Dialect $dialect, $prepend = null, $append = null) { if (count($this->targets) == 1) { return $prepend . $dialect->quoteTable(reset($this->targets)); } else { $tables = []; foreach ($this->targets as $target) { if ($target instanceof DialectString) { $table = $dialect->quoteTable($target->toDialectString($dialect)); } else { $table = $dialect->quoteTable($target); } $tables[] = $prepend . $table; } return implode($append . ' ', $tables); } }
public function toDialectString(Dialect $dialect) { $query = 'UPDATE ' . $dialect->quoteTable($this->table) . ' SET '; $sets = []; foreach ($this->fields as $var => $val) { if ($val instanceof DialectString) { $sets[] = $dialect->quoteField($var) . ' = (' . $val->toDialectString($dialect) . ')'; } elseif ($val === null) { $sets[] = $dialect->quoteField($var) . ' = ' . $dialect->literalToString(Dialect::LITERAL_NULL); } elseif (true === $val) { $sets[] = $dialect->quoteField($var) . ' = ' . $dialect->literalToString(Dialect::LITERAL_TRUE); } elseif (false === $val) { $sets[] = $dialect->quoteField($var) . ' = ' . $dialect->literalToString(Dialect::LITERAL_FALSE); } else { $sets[] = $dialect->quoteField($var) . ' = ' . $dialect->quoteValue($val); } } return $query . implode(', ', $sets) . $this->joiner->toDialectString($dialect) . parent::toDialectString($dialect); }
public function literalToString($literal) { switch ($literal) { case self::LITERAL_FALSE: return $this->quoteValue('0'); case self::LITERAL_TRUE: return $this->quoteValue('1'); } return parent::literalToString($literal); }
public function toDialectString(Dialect $dialect) { $name = $this->table->getName(); $middle = "CREATE TABLE {$dialect->quoteTable($name)} (\n "; $prepend = []; $columns = []; $primary = []; $order = $this->table->getOrder(); foreach ($order as $column) { if ($column->isAutoincrement()) { if ($pre = $dialect->preAutoincrement($column)) { $prepend[] = $pre; } $columns[] = implode(' ', [$column->toDialectString($dialect), $dialect->postAutoincrement($column)]); } else { $columns[] = $column->toDialectString($dialect); } $name = $column->getName(); if ($column->isPrimaryKey()) { $primary[] = $dialect->quoteField($name); } } $out = ($prepend ? implode("\n", $prepend) . "\n" : null) . $middle . implode(",\n ", $columns); if ($primary) { $out .= ",\n PRIMARY KEY(" . implode(', ', $primary) . ')'; } if ($uniques = $this->table->getUniques()) { $names = []; foreach ($uniques as $row) { foreach ($row as $name) { $names[] = $dialect->quoteField($name); } $out .= ",\n UNIQUE(" . implode(', ', $names) . ')'; } } return $out . "\n);\n"; }
public function typeToString(DataType $type) { if ($type->getId() == DataType::BINARY) { return 'BYTEA'; } if (defined('POSTGRES_IP4_ENABLED')) { if ($type->getId() == DataType::IP) { return 'ip4'; } if ($type->getId() == DataType::IP_RANGE) { return 'ip4r'; } } return parent::typeToString($type); }
public function toDialectString(Dialect $dialect) { return 'DROP TABLE ' . $dialect->quoteTable($this->name) . $dialect->dropTableMode($this->cascade) . ';'; }
public function toDialectString(Dialect $dialect) { return $dialect->quoteValue($this->getId()); }
public function toDialectString(Dialect $dialect) { $sql = $dialect->toFieldString($this->left) . ' ' . $dialect->logicToString($this->logic) . ' ' . $dialect->toValueString($this->right); return $this->brackets ? "({$sql})" : $sql; }
public static function findDifferences(Dialect $dialect, DBTable $source, DBTable $target) { $out = []; $head = 'ALTER TABLE ' . $dialect->quoteTable($target->getName()); $sourceColumns = $source->getColumns(); $targetColumns = $target->getColumns(); foreach ($sourceColumns as $name => $column) { if (isset($targetColumns[$name])) { if ($column->getType()->getId() != $targetColumns[$name]->getType()->getId()) { $targetColumn = $targetColumns[$name]; $out[] = $head . ' ALTER COLUMN ' . $dialect->quoteField($name) . ' TYPE ' . $targetColumn->getType()->toString() . ($targetColumn->getType()->hasSize() ? '(' . $targetColumn->getType()->getSize() . ($targetColumn->getType()->hasPrecision() ? ', ' . $targetColumn->getType()->getPrecision() : null) . ')' : null) . (in_array($targetColumn->getType()->getId(), array(DataType::JSON, DataType::JSONB)) ? ' USING NULL' : '') . ';'; } if ($column->getType()->isNull() != $targetColumns[$name]->getType()->isNull()) { $out[] = $head . ' ALTER COLUMN ' . $dialect->quoteField($name) . ' ' . ($targetColumns[$name]->getType()->isNull() ? 'DROP' : 'SET') . ' NOT NULL;'; } } else { $out[] = $head . ' DROP COLUMN ' . $dialect->quoteField($name) . ';'; } } foreach ($targetColumns as $name => $column) { if (!isset($sourceColumns[$name])) { $out[] = $head . ' ADD COLUMN ' . $column->toDialectString($dialect) . ';'; if ($column->hasReference()) { $out[] = 'CREATE INDEX ' . $dialect->quoteField($name . '_idx') . ' ON ' . $dialect->quoteTable($target->getName()) . '(' . $dialect->quoteField($name) . ');'; } } } return $out; }
public function toDialectString(Dialect $dialect) { $out = $dialect->quoteValue($this->value); return $this->cast ? $dialect->toCasted($out, $this->cast) : $out; }
public function toDialectString(Dialect $dialect) { return $dialect->quoteIpInRange($this->range, $this->ip); }
public function toDialectString(Dialect $dialect) { return '(' . $dialect->toFieldString($this->field) . ' BETWEEN ' . $dialect->toValueString($this->left) . ' AND ' . $dialect->toValueString($this->right) . ')'; }
public function toDialectString(Dialect $dialect) { return '(' . $dialect->toFieldString(SQLFunction::create('lower', $this->left)) . ' = ' . $dialect->toValueString(is_string($this->right) ? mb_strtolower($this->right) : SQLFunction::create('lower', $this->right)) . ')'; }
public function toDialectString(Dialect $dialect) { if ($this->field instanceof SelectQuery || $this->field instanceof LogicalObject) { $result = '(' . $dialect->fieldToString($this->field) . ')'; } else { $result = parent::toDialectString($dialect); } $result .= $this->direction->decide(' ASC', ' DESC') . $this->nulls->decide(' NULLS FIRST', ' NULLS LAST'); return $result; }
public function toDialectString(Dialect $dialect) { $out = $dialect->quoteField($this->name) . ' ' . $this->type->toDialectString($dialect); if (null !== $this->default) { if ($this->type->getId() == DataType::BOOLEAN) { $default = $this->default ? $dialect->literalToString(Dialect::LITERAL_TRUE) : $dialect->literalToString(Dialect::LITERAL_FALSE); } else { $default = $dialect->valueToString($this->default); } $out .= ' DEFAULT ' . $default; } if ($this->reference) { $table = $this->reference->getTable()->getName(); $column = $this->reference->getName(); $out .= " REFERENCES {$dialect->quoteTable($table)}" . "({$dialect->quoteField($column)})"; if ($this->onDelete) { $out .= ' ON DELETE ' . $this->onDelete->toString(); } if ($this->onUpdate) { $out .= ' ON UPDATE ' . $this->onUpdate->toString(); } } return $out; }
public function toDialectString(Dialect $dialect) { $out = $dialect->fieldToString($this->field); return $this->cast ? $dialect->toCasted($out, $this->cast) : $out; }
public function toDialectString(Dialect $dialect) { return $dialect->fullTextRank($this->field, $this->words, $this->logic); }
public function toDialectString(Dialect $dialect) { $out = $dialect->typeToString($this); if ($this->unsigned) { $out .= ' UNSIGNED'; } if ($this->id & self::HAVE_PRECISION) { if ($this->precision) { switch ($this->id) { case self::TIME: case self::TIMESTAMP: $out .= "({$this->precision})"; break; case self::NUMERIC: $out .= $this->precision ? "({$this->size}, {$this->precision})" : "({$this->size})"; break; default: throw new WrongStateException(); } } } elseif ($this->hasSize()) { if (!$this->size) { throw new WrongStateException("type '{$this->name}' must have size"); } $out .= "({$this->size})"; } if ($this->id & self::HAVE_TIMEZONE) { $out .= $dialect->timeZone($this->timezone); } $out .= $this->null ? ' NULL' : ' NOT NULL'; return $out; }
protected function toDialectStringSelect($query, Dialect $dialect) { $fields = []; foreach ($this->fields as $var => $val) { $fields[] = $dialect->quoteField($var); } if (!$fields) { throw new WrongStateException('what should i insert?'); } if ($this->select->getFieldsCount() != count($fields)) { throw new WrongStateException('count of select fields must be equal with count of insert fields'); } $fields = implode(', ', $fields); return $query . "({$fields}) (" . $this->select->toDialectString($dialect) . ")"; }
public function logicToString($logic) { switch ($logic) { case BinaryExpression::REGEXP: return 'REGEXP'; case BinaryExpression::NOT_REGEXP: return 'NOT REGEXP'; } return parent::logicToString($logic); }
/** * @return QuerySkeleton **/ protected function checkReturning(Dialect $dialect) { if ($this->returning && !$dialect->hasReturning()) { throw new UnimplementedFeatureException(); } return $this; }
public function toDialectString(Dialect $dialect) { return $dialect->quoteBinary($this->getValue()); }
public function toDialectString(Dialect $dialect) { // there are no known differences yet return $dialect->quoteValue($this->toString()); }