fixed:SQL解析错误

This commit is contained in:
JaguarJack 2020-10-23 15:45:47 +08:00
parent e0b2aafd2c
commit 3d58942844

View File

@ -72,6 +72,7 @@ class SQL extends Factory
$createSql .= $this->index;
}
$createSql = rtrim($createSql, ',' . PHP_EOL);
// 创建表 SQL
return $this->createTable($params['table'], $createSql, $extra['engine'], 'utf8mb4', $extra['comment']);
}
@ -104,7 +105,9 @@ class SQL extends Factory
if (!$sql['nullable']) {
$_sql[] = 'not null';
if ($default == '' || $default === '') {
if (!$this->doNotNeedDefaultValueType($sql['type'])) {
$_sql[] = ' default \'\'';
}
} else {
if (strpos('int', $sql['type']) === false) {
$_sql[] = ' default ' . (int)$default ;
@ -117,7 +120,6 @@ class SQL extends Factory
// 字段注释
$_sql[] = $sql['comment'] ? sprintf('comment \'%s\'', $sql['comment']) : '';
return implode(' ', $_sql) . ','. PHP_EOL;
}
@ -205,4 +207,21 @@ class SQL extends Factory
$this->index .= "spatial index spatial_$field($field),". PHP_EOL;
}
}
/**
* 不需要默认值
*
* @param string $type
* @time 2020年10月23日
* @return bool
*/
protected function doNotNeedDefaultValueType(string $type)
{
return in_array($type, [
'blob', 'text', 'geometry', 'json',
'tinytext', 'mediumtext', 'longtext',
'tinyblob', 'mediumblob', 'longblob'
]);
}
}