当前位置: 首页>>代码示例>>PHP>>正文


PHP Table::hasAutoIncrement方法代码示例

本文整理汇总了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;
 }
开发者ID:tgr0ss,项目名称:cakephp,代码行数:80,代码来源:MysqlSchema.php


注:本文中的Cake\Database\Schema\Table::hasAutoIncrement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。