本文整理汇总了PHP中Cake\Database\Schema\Table::hasAutoIncrement方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::hasAutoIncrement方法的具体用法?PHP Table::hasAutoIncrement怎么用?PHP Table::hasAutoIncrement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Database\Schema\Table
的用法示例。
在下文中一共展示了Table::hasAutoIncrement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: columnSql
/**
* {@inheritDoc}
*/
public function columnSql(Table $table, $name)
{
$data = $table->column($name);
$out = $this->_driver->quoteIdentifier($name);
$typeMap = ['integer' => ' INTEGER', 'biginteger' => ' BIGINT', 'boolean' => ' BOOLEAN', 'float' => ' FLOAT', 'decimal' => ' DECIMAL', 'date' => ' DATE', 'time' => ' TIME', 'datetime' => ' DATETIME', 'timestamp' => ' TIMESTAMP', 'uuid' => ' CHAR(36)'];
$specialMap = ['string' => true, 'text' => true, 'binary' => true];
if (isset($typeMap[$data['type']])) {
$out .= $typeMap[$data['type']];
}
if (isset($specialMap[$data['type']])) {
switch ($data['type']) {
case 'string':
$out .= !empty($data['fixed']) ? ' CHAR' : ' VARCHAR';
if (!isset($data['length'])) {
$data['length'] = 255;
}
break;
case 'text':
$isKnownLength = in_array($data['length'], Table::$columnLengths);
if (empty($data['length']) || !$isKnownLength) {
$out .= ' TEXT';
break;
}
if ($isKnownLength) {
$length = array_search($data['length'], Table::$columnLengths);
$out .= ' ' . strtoupper($length) . 'TEXT';
}
break;
case 'binary':
$isKnownLength = in_array($data['length'], Table::$columnLengths);
if (empty($data['length']) || !$isKnownLength) {
$out .= ' BLOB';
break;
}
if ($isKnownLength) {
$length = array_search($data['length'], Table::$columnLengths);
$out .= ' ' . strtoupper($length) . 'BLOB';
}
break;
}
}
$hasLength = ['integer', 'string'];
if (in_array($data['type'], $hasLength, true) && isset($data['length'])) {
$out .= '(' . (int) $data['length'] . ')';
}
$hasPrecision = ['float', 'decimal'];
if (in_array($data['type'], $hasPrecision, true) && (isset($data['length']) || isset($data['precision']))) {
$out .= '(' . (int) $data['length'] . ',' . (int) $data['precision'] . ')';
}
$hasUnsigned = ['float', 'decimal', 'integer', 'biginteger'];
if (in_array($data['type'], $hasUnsigned, true) && isset($data['unsigned']) && $data['unsigned'] === true) {
$out .= ' UNSIGNED';
}
if (isset($data['null']) && $data['null'] === false) {
$out .= ' NOT NULL';
}
$addAutoIncrement = [$name] == (array) $table->primaryKey() && !$table->hasAutoIncrement();
if (in_array($data['type'], ['integer', 'biginteger']) && ($data['autoIncrement'] === true || $addAutoIncrement)) {
$out .= ' AUTO_INCREMENT';
}
if (isset($data['null']) && $data['null'] === true) {
$out .= $data['type'] === 'timestamp' ? ' NULL' : ' DEFAULT NULL';
unset($data['default']);
}
if (isset($data['default']) && !in_array($data['type'], ['timestamp', 'datetime'])) {
$out .= ' DEFAULT ' . $this->_driver->schemaValue($data['default']);
unset($data['default']);
}
if (isset($data['default']) && in_array($data['type'], ['timestamp', 'datetime']) && strtolower($data['default']) === 'current_timestamp') {
$out .= ' DEFAULT CURRENT_TIMESTAMP';
unset($data['default']);
}
if (isset($data['comment']) && $data['comment'] !== '') {
$out .= ' COMMENT ' . $this->_driver->schemaValue($data['comment']);
}
return $out;
}