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) { $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"); } }
public function typeToString(DataType $type) { if ($type->getId() == DataType::BINARY) { return 'BLOB'; } return parent::typeToString($type); }
private function dumpTargets(Dialect $dialect, $prepend = null, $append = null) { if (count($this->targets) == 1) { return $prepend . $dialect->quoteTable(reset($this->targets)); } else { $tables = array(); 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); } Assert::isUnreachable(); }
public function toDialectString(Dialect $dialect) { $query = 'UPDATE ' . $dialect->quoteTable($this->table) . ' SET '; $sets = array(); 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 = array(); $columns = array(); $primary = array(); $order = $this->table->getOrder(); foreach ($order as $column) { if ($column->isAutoincrement()) { if ($pre = $dialect->preAutoincrement($column)) { $prepend[] = $pre; } $columns[] = implode(' ', array($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 = array(); 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->quoteIpInRange($this->range, $this->ip); }
public function toDialectString(Dialect $dialect) { $out = $dialect->quoteValue($this->value); return $this->cast ? $dialect->toCasted($out, $this->cast) : $out; }
public function __construct($filename, Dialect $dialect = null) { $this->filename = $filename; $this->dialect = $dialect ?: Dialect::csv(); }
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 static function findDifferences(Dialect $dialect, DBTable $source, DBTable $target) { $out = array(); $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) . ';'; } 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) { return '(' . $dialect->toFieldString($this->field) . ' BETWEEN ' . $dialect->toValueString($this->left) . ' AND ' . $dialect->toValueString($this->right) . ')'; }
public function toDialectString(Dialect $dialect) { $sql = $dialect->toFieldString($this->subject) . ' ' . $dialect->logicToString($this->logic); return $this->brackets ? "({$sql})" : $sql; }
public function toDialectString(Dialect $dialect) { return $dialect->quoteValue($this->toString()); }
function getTypeRepresentation(DBType $dbType) { switch ($dbType->getValue()) { case DBType::BOOLEAN: return $this->compute('TINYINT(1) UNSIGNED', $dbType->isNullable()); case DBType::BINARY: $size = $dbType->getSize(); if ($size < 65535) { $customType = 'BLOB'; } else { if ($size < 16777215) { $customType = 'MEDIUMBLOB'; } else { $customType = 'LONGTBLOB'; } } return $this->compute($customType, $dbType->isNullable()); case DBType::VARCHAR: $size = $dbType->getSize(); if (!$size) { $dbType->setSize(255); } else { if ($size > 255) { if ($size < 65535) { $customType = 'TEXT'; } else { if ($size < 16777215) { $customType = 'MEDIUMTEXT'; } else { $customType = 'LONGTEXT'; } } return $this->compute($customType, $dbType->isNullable()); } } } $type = parent::getTypeRepresentation($dbType); if ($dbType->isGenerated()) { $type .= ' AUTO_INCREMENT'; } return $type; }
/** * @return QuerySkeleton **/ protected function checkReturning(Dialect $dialect) { if ($this->returning && !$dialect->hasReturning()) { throw new UnimplementedFeatureException(); } return $this; }
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->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; }
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($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; }
/** * @param SplFileObject|string $file The file to use * @param Dialect|null $dialect The CSV dialect * @return void */ public function __construct($file, Dialect $dialect = null) { $this->fileObject = $file instanceof \SplFileObject ? $file : new \SplFileObject($file, 'w'); $this->dialect = $dialect ?: Dialect::csv(); self::configureFileObject($this->fileObject, $this->dialect); }
public function toDialectString(Dialect $dialect) { return $dialect->fullTextRank($this->field, $this->words, $this->logic); }
protected function toDialectStringSelect($query, Dialect $dialect) { $fields = array(); 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 toDialectString(Dialect $dialect) { return $dialect->quoteBinary($this->getValue()); }
public function toDialectString(Dialect $dialect) { // there are no known differences yet return $dialect->quoteValue($this->toString()); }
public function toDialectString(Dialect $dialect) { return '(' . $dialect->logicToString($this->logic) . ' ' . $dialect->toFieldString($this->subject) . ')'; }
public static function configureFileObject(\SplFileObject $fh, Dialect $dialect) { $fh->setCsvControl($dialect->getDelimiter(), $dialect->getEnclosure(), $dialect->getEscapeCharacter()); }