/** * @param PlatformInterface $adapterPlatform * @return array */ protected function processTable(PlatformInterface $adapterPlatform = null) { $ret = array(''); if ($this->isTemporary) { $table = '#'; } else { $table = ''; } $ret[] = $adapterPlatform->quoteIdentifier($table . ltrim($this->table, '#')); return $ret; }
protected function processChangeColumns(PlatformInterface $adapterPlatform = null) { /* @var Column\Column $column */ $sqls = []; foreach ($this->changeColumns as $name => $column) { if ($name !== $column->getName()) { trigger_error('One statement must rename a column, other separate statements must change table definition.', E_USER_DEPRECATED); } $default = $column->getDefault(); $columnClass = get_class($column); $emptyColumn = new $columnClass(null, true); $emptyColumn->setOptions($column->getOptions()); $sqls[] = [$adapterPlatform->quoteIdentifier($name), ' SET DATA TYPE' . $this->processExpression($emptyColumn, $adapterPlatform)]; $sqls[] = [$adapterPlatform->quoteIdentifier($name), null !== $default ? ' SET ' . $this->processExpression(new DefaultValue($default), $adapterPlatform) : ' DROP DEFAULT']; $sqls[] = [$adapterPlatform->quoteIdentifier($name), $column->isNullable() ? ' DROP NOT NULL' : ' SET NOT NULL']; } return [$sqls]; }
protected function processInsert(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) { if ($this->select) { return; } if (!$this->columns) { throw new InvalidArgumentException('values or select should be present'); } $columns = []; $values = []; foreach ($this->columns as $column => $value) { $columns[] = $platform->quoteIdentifier($column); foreach ($value as $key => $item) { /* if (is_scalar($item) && $parameterContainer) { $values[$key][] = $driver->formatParameterName($column); $parameterContainer->offsetSet($column, $item); } else {*/ $values[$key][] = $this->resolveColumnValue($item, $platform, $driver, $parameterContainer); /* }*/ } } $strValues = ''; foreach ($values as $value) { $strValues .= '(' . implode(', ', $value) . '),'; } $strValues = rtrim($strValues, ','); $sql = sprintf($this->specifications[static::SPECIFICATION_INSERT], $this->resolveTable($this->table, $platform, $driver, $parameterContainer), implode(', ', $columns), $strValues); return $sql; }
/** * @param PlatformInterface $adapterPlatform * * @return string[] */ protected function processTable(PlatformInterface $adapterPlatform = null) { return array($this->isTemporary ? 'TEMPORARY ' : '', $adapterPlatform->quoteIdentifier($this->table)); }
protected function processTable(PlatformInterface $adapterPlatform = null) { return array($adapterPlatform->quoteIdentifier($this->table)); }
protected function processJoins(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) { if (!$this->joins) { return null; } // process joins $joinSpecArgArray = array(); foreach ($this->joins as $j => $join) { $joinSpecArgArray[$j] = array(); $joinName = null; $joinAs = null; // type $joinSpecArgArray[$j][] = strtoupper($join['type']); // table name if (is_array($join['name'])) { $joinName = current($join['name']); $joinAs = $platform->quoteIdentifier(key($join['name'])); } else { $joinName = $join['name']; } if ($joinName instanceof TableIdentifier) { $joinName = $joinName->getTableAndSchema(); $joinName = $platform->quoteIdentifier($joinName[1]) . $platform->getIdentifierSeparator() . $platform->quoteIdentifier($joinName[0]); } else { if ($joinName instanceof Select) { $joinName = '(' . $joinName->processSubSelect($joinName, $platform, $driver, $parameterContainer) . ')'; } else { $joinName = $platform->quoteIdentifier($joinName); } } $joinSpecArgArray[$j][] = isset($joinAs) ? $joinName . ' AS ' . $joinAs : $joinName; // on expression // note: for Expression objects, pass them to processExpression with a prefix specific to each join (used for named parameters) $joinSpecArgArray[$j][] = $join['on'] instanceof ExpressionInterface ? $this->processExpression($join['on'], $platform, $driver, $this->processInfo['paramPrefix'] . 'join' . ($j + 1) . 'part') : $platform->quoteIdentifierInFragment($join['on'], array('=', 'AND', 'OR', '(', ')', 'BETWEEN', '<', '>')); // on if ($joinSpecArgArray[$j][2] instanceof StatementContainerInterface) { if ($parameterContainer) { $parameterContainer->merge($joinSpecArgArray[$j][2]->getParameterContainer()); } $joinSpecArgArray[$j][2] = $joinSpecArgArray[$j][2]->getSql(); } } return array($joinSpecArgArray); }
/** * @param PlatformInterface $adapterPlatform * @return array */ protected function processTable(PlatformInterface $adapterPlatform = null) { $table = ($this->isTemporary ? '#' : '') . ltrim($this->table, '#'); return ['', $adapterPlatform->quoteIdentifier($table)]; }
protected function processDropConstraints(PlatformInterface $adapterPlatform = null) { $sqls = array(); foreach ($this->dropConstraints as $constraint) { $sqls[] = $adapterPlatform->quoteIdentifier($constraint); } return array($sqls); }
protected function processOrder(PlatformInterface $platform, Adapter $adapter = null, ParameterContainer $parameterContainer = null) { if (empty($this->order)) { return null; } $orders = array(); foreach ($this->order as $k => $v) { if (is_int($k)) { if (strpos($v, ' ') !== false) { list($k, $v) = preg_split('# #', $v, 2); } else { $k = $v; $v = self::ORDER_ASCENDING; } } if (strtoupper($v) == self::ORDER_DESENDING) { $orders[] = array($platform->quoteIdentifier($k), self::ORDER_DESENDING); } else { $orders[] = array($platform->quoteIdentifier($k), self::ORDER_ASCENDING); } } return array($orders); }
protected function processUpdate(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) { $setSql = []; foreach ($this->set as $column => $value) { $prefix = $platform->quoteIdentifier($column) . ' = '; if (is_scalar($value) && $parameterContainer) { $setSql[] = $prefix . $driver->formatParameterName($column); $parameterContainer->offsetSet($column, $value); } else { $setSql[] = $prefix . $this->resolveColumnValue($value, $platform, $driver, $parameterContainer); } } return sprintf($this->specifications[static::SPECIFICATION_UPDATE], $this->resolveTable($this->table, $platform, $driver, $parameterContainer), implode(', ', $setSql)); }
protected function processJoin(PlatformInterface $platform, Adapter $adapter = null, ParameterContainer $parameterContainer = null) { if (!$this->joins) { return null; } // process joins $joinSpecArgArray = array(); foreach ($this->joins as $j => $join) { if (is_array($join['name'])) { $keys = array_keys($join['name']); $alias = array_pop($keys); $name = $join['name'][$alias]; $nameArg = $platform->quoteIdentifier($name) . ' AS ' . $platform->quoteIdentifier($alias); } else { $nameArg = $platform->quoteIdentifier($join['name']); } $joinSpecArgArray[$j] = array(); $joinSpecArgArray[$j][] = strtoupper($join['type']); // type $joinSpecArgArray[$j][] = $nameArg; // table $joinSpecArgArray[$j][] = $platform->quoteIdentifierInFragment($join['on'], array('=', 'AND', 'OR', '(', ')', 'BETWEEN')); // on } return array($joinSpecArgArray); }
protected function processTable(PlatformInterface $adapterPlatform = null) { $ret = array(); if ($this->isTemporary) { $ret[] = 'TEMPORARY'; } $ret[] = $adapterPlatform->quoteIdentifier($this->table); return $ret; }
protected function processRenameColumn(PlatformInterface $adapterPlatform = null) { $sqls = []; foreach ($this->renameColumn as $name => $column) { $sqls[] = [$adapterPlatform->quoteIdentifier($name), $this->processExpression($column, $adapterPlatform)]; } return [$sqls]; }
protected function processJoins(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) { if (!$this->joins) { return; } // process joins $joinSpecArgArray = []; foreach ($this->joins as $j => $join) { $joinName = null; $joinAs = null; // table name if (is_array($join['name'])) { $joinName = current($join['name']); $joinAs = $platform->quoteIdentifier(key($join['name'])); } else { $joinName = $join['name']; } if ($joinName instanceof Expression) { $joinName = $joinName->getExpression(); } elseif ($joinName instanceof TableIdentifier) { $joinName = $joinName->getTableAndSchema(); $joinName = ($joinName[1] ? $platform->quoteIdentifier($joinName[1]) . $platform->getIdentifierSeparator() : '') . $platform->quoteIdentifier($joinName[0]); } elseif ($joinName instanceof Select) { $joinName = '(' . $this->processSubSelect($joinName, $platform, $driver, $parameterContainer) . ')'; } elseif (is_string($joinName) || is_object($joinName) && is_callable([$joinName, '__toString'])) { $joinName = $platform->quoteIdentifier($joinName); } else { throw new Exception\InvalidArgumentException(sprintf('Join name expected to be Expression|TableIdentifier|Select|string, "%s" given', gettype($joinName))); } $joinSpecArgArray[$j] = [strtoupper($join['type']), $this->renderTable($joinName, $joinAs)]; // on expression // note: for Expression objects, pass them to processExpression with a prefix specific to each join (used for named parameters) $joinSpecArgArray[$j][] = $join['on'] instanceof ExpressionInterface ? $this->processExpression($join['on'], $platform, $driver, $parameterContainer, 'join' . ($j + 1) . 'part') : $platform->quoteIdentifierInFragment($join['on'], ['=', 'AND', 'OR', '(', ')', 'BETWEEN', '<', '>']); // on } return [$joinSpecArgArray]; }
protected function processInsert(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) { if ($this->select) { return; } if (!$this->columns) { throw new Exception\InvalidArgumentException('values or select should be present'); } $columns = []; $values = []; foreach ($this->columns as $column => $value) { $columns[] = $platform->quoteIdentifier($column); if (is_scalar($value) && $parameterContainer) { $values[] = $driver->formatParameterName($column); $parameterContainer->offsetSet($column, $value); } else { $values[] = $this->resolveColumnValue($value, $platform, $driver, $parameterContainer); } } return sprintf($this->specifications[static::SPECIFICATION_INSERT], $this->resolveTable($this->table, $platform, $driver, $parameterContainer), implode(', ', $columns), implode(', ', $values)); }
protected function processJoin(PlatformInterface $platform, Adapter $adapter = null, ParameterContainer $parameterContainer = null) { if (!$this->joins) { return null; } // process joins $joinSpecArgArray = array(); foreach ($this->joins as $j => $join) { $joinSpecArgArray[$j] = array(); // type $joinSpecArgArray[$j][] = strtoupper($join['type']); // table name $joinSpecArgArray[$j][] = is_array($join['name']) ? $platform->quoteIdentifier(current($join['name'])) . ' AS ' . $platform->quoteIdentifier(key($join['name'])) : $platform->quoteIdentifier($join['name']); // on expression $joinSpecArgArray[$j][] = $join['on'] instanceof ExpressionInterface ? $this->processExpression($join['on'], $platform, $adapter, $this->processInfo['paramPrefix'] . 'join') : $platform->quoteIdentifierInFragment($join['on'], array('=', 'AND', 'OR', '(', ')', 'BETWEEN')); // on if ($joinSpecArgArray[$j][2] instanceof StatementContainerInterface) { if ($parameterContainer) { $parameterContainer->merge($joinSpecArgArray[$j][2]->getParameterContainer()); } $joinSpecArgArray[$j][2] = $joinSpecArgArray[$j][2]->getSql(); } } return array($joinSpecArgArray); }
protected function processInsert(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null) { if ($this->select) { return; } if (!$this->columns) { throw new \Zend\Db\Exception\InvalidArgumentException('values or select should be present'); } $columns = array(); $values = array(); if (empty($this->valueRows)) { return ''; //TODO Test that } $prepareColumns = true; foreach ($this->valueRows as $row) { if (!is_array($row)) { throw new \Zend\Db\Exception\InvalidArgumentException('values must be arrays for multi-insertion'); } $subValues = array(); ksort($row); // Make sure columns always appear in the same order foreach ($row as $col => $subValue) { if ($prepareColumns) { $columns[] = $platform->quoteIdentifier($col); } if (is_scalar($subValue) && $parameterContainer) { $subValues[] = $driver->formatParameterName($col); $parameterContainer->offsetSet($col, $subValue); } else { $subValues[] = $this->resolveColumnValue($subValue, $platform, $driver, $parameterContainer); } } $values[] = implode(', ', $subValues); $prepareColumns = false; } return sprintf($this->specifications[static::SPECIFICATION_INSERT], $this->resolveTable($this->table, $platform, $driver, $parameterContainer), implode(', ', $columns), implode('), (', $values)); }