lithium\data\source\Database::column()

public method

Generate a database-native column schema string

Parameters

  • array $column

    A field array structured like the following: array('name' => 'value', 'type' => 'value' [, options]), where options can be 'default', 'null', 'length' or 'precision'.

Returns

string

SQL string

Source

	public function column($field) {
		if (!isset($field['type'])) {
			$field['type'] = 'string';
		}
		if (!isset($field['name'])) {
			throw new InvalidArgumentException("Column name not defined.");
		}
		if (!isset($this->_columns[$field['type']])) {
			throw new UnexpectedValueException("Column type `{$field['type']}` does not exist.");
		}

		$field += $this->_columns[$field['type']] + [
			'name' => null,
			'type' => null,
			'length' => null,
			'precision' => null,
			'default' => null,
			'null' => null
		];

		$isNumeric = preg_match('/^(integer|float|boolean)$/', $field['type']);
		if ($isNumeric && $field['default'] === '') {
			$field['default'] = null;
		}
		$field['use'] = strtolower($field['use']);
		return $this->_buildColumn($field);
	}