Skip to content

Commit

Permalink
search默认col为3
Browse files Browse the repository at this point in the history
判断mysql版本,高版本使用utf8mb4
  • Loading branch information
ichynul committed Apr 18, 2024
1 parent 5e1134b commit 75e8f9a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/admin/controller/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ protected function buildForm($isEdit, &$data = [])
* @param integer $id
* @return mixed
*/
private function save($id = 0)
protected function save($id = 0)
{
$data = request()->post();

Expand Down Expand Up @@ -412,7 +412,7 @@ private function save($id = 0)
*
* @return void
*/
protected function buildTable(&$data = [])
protected function buildTable(&$data = [], $isExporting = false)
{
$table = $this->table;

Expand Down Expand Up @@ -526,7 +526,7 @@ public function relations()
$form->show('TABLE_NAME', '表名称')->value($id);
$form->raw('model_namespace', 'model命名空间')->value('<b>app\\' . Module::getInstance()->config('model_namespace') . '\\model\\</b>可在扩展配置中修改');
if (is_file($modelFileName)) {
$form->raw('tips', '提示')->value('已存在模型文件,将覆被盖:<b>' . str_replace(App::getRootPath(), '', $modelFileName) . '</b>');
$form->raw('tips', '提示')->value('已存在模型文件,将被覆盖:<b>' . str_replace(App::getRootPath(), '', $modelFileName) . '</b>');
}
$form->text('model_title', 'model注释')->default($tableInfo['TABLE_COMMENT'])->required();

Expand Down
4 changes: 2 additions & 2 deletions src/admin/controller/Dbtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ protected function buildForm($isEdit, &$data = [])
* @param integer $id
* @return mixed
*/
private function save($id = 0)
protected function save($id = 0)
{
$data = request()->only([
'TABLE_NAME',
Expand Down Expand Up @@ -336,7 +336,7 @@ private function save($id = 0)
*
* @return void
*/
protected function buildTable(&$data = [])
protected function buildTable(&$data = [], $isExporting = false)
{
$protectedTables = $this->getProtectedTables();
$table = $this->table;
Expand Down
2 changes: 1 addition & 1 deletion src/admin/controller/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ protected function buildDataList($where = [], $sortOrder = '', $page = 1, &$tota
*
* @return void
*/
protected function buildTable(&$data = [])
protected function buildTable(&$data = [], $isExporting = false)
{
$table = $this->table;

Expand Down
1 change: 1 addition & 0 deletions src/common/logic/CreatorLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ public function buildSearch($data)
$this->lines[] = ' protected function buildSearch()';
$this->lines[] = ' {';
$this->lines[] = ' $search = $this->search;';
$this->lines[] = ' $search->defaultDisplayerColSize(3);';
$this->lines[] = '';
if (!empty($data['TABLE_FIELDS'])) {

Expand Down
9 changes: 8 additions & 1 deletion src/common/logic/DbLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,11 @@ public function createTable($tableName, $data)
}
}

$charset = preg_match('/^[1-5]\.[0-5]/', $this->getMysqlVersion()) ? 'utf8' : 'utf8mb4';

$sql = "CREATE TABLE IF NOT EXISTS `$tableName`(
`{$pkinfo['COLUMN_NAME']}` {$attr} primary key COMMENT '{$pkinfo['COLUMN_COMMENT']}'{$create_time_column}{$update_time_column}
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='{$data['TABLE_COMMENT']}'";
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET={$charset} COMMENT='{$data['TABLE_COMMENT']}'";
try {
Db::execute($sql);
} catch (\Exception $ex) {
Expand All @@ -294,6 +296,11 @@ public function createTable($tableName, $data)
return true;
}

public function getMysqlVersion()
{
return Db::query("SELECT VERSION() AS ver")[0]['ver'];
}

/**
* Undocumented function
*
Expand Down

0 comments on commit 75e8f9a

Please sign in to comment.