/** * Gets the SqlServer Column Definition for a Column object. * * @param Column $column Column * @return string */ protected function getColumnSqlDefinition(Column $column, $create = true) { $buffer = array(); $sqlType = $this->getSqlType($column->getType()); $buffer[] = strtoupper($sqlType['name']); // integers cant have limits in SQlServer $noLimits = array('bigint', 'int', 'tinyint'); if (!in_array($sqlType['name'], $noLimits) && ($column->getLimit() || isset($sqlType['limit']))) { $buffer[] = sprintf('(%s)', $column->getLimit() ? $column->getLimit() : $sqlType['limit']); } $properties = $column->getProperties(); $buffer[] = $column->getType() == 'filestream' ? 'FILESTREAM' : ''; $buffer[] = isset($properties['rowguidcol']) ? 'ROWGUIDCOL' : ''; $buffer[] = $column->isNull() ? 'NULL' : 'NOT NULL'; $default = $column->getDefault(); if ($create) { if (is_numeric($default) || 'CURRENT_TIMESTAMP' === $default) { $buffer[] = 'DEFAULT'; $buffer[] = $default; } elseif ($default) { $buffer[] = "DEFAULT '{$default}'"; } } if ($column->isIdentity()) { $buffer[] = 'IDENTITY(1, 1)'; } // TODO - add precision & scale for decimals return implode(' ', $buffer); }
/** * Gets the SqlServer Column Definition for a Column object. * * @param Column $column Column * @return string */ protected function getColumnSqlDefinition(Column $column, $create = true) { $buffer = array(); $sqlType = $this->getSqlType($column->getType()); $buffer[] = strtoupper($sqlType['name']); // integers cant have limits in SQlServer $noLimits = array('bigint', 'int', 'tinyint'); if (!in_array($sqlType['name'], $noLimits) && ($column->getLimit() || isset($sqlType['limit']))) { $buffer[] = sprintf('(%s)', $column->getLimit() ? $column->getLimit() : $sqlType['limit']); } if ($column->getPrecision() && $column->getScale()) { $buffer[] = '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } $properties = $column->getProperties(); $buffer[] = $column->getType() === 'filestream' ? 'FILESTREAM' : ''; $buffer[] = isset($properties['rowguidcol']) ? 'ROWGUIDCOL' : ''; $buffer[] = $column->isNull() ? 'NULL' : 'NOT NULL'; if ($create === true) { if ($column->getDefault() === null && $column->isNull()) { $buffer[] = ' DEFAULT NULL'; } else { $buffer[] = $this->getDefaultValueDefinition($column->getDefault()); } } if ($column->isIdentity()) { $buffer[] = 'IDENTITY(1, 1)'; } return implode(' ', $buffer); }
/** * Gets field properties * * @return array */ public function getProperties() { return $this->column->getProperties(); }