Skip to content

Commit

Permalink
添加支持用户名为中文
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Feb 23, 2021
1 parent f361a5c commit f8105a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ CREATE TABLE IF NOT EXISTS users (
expiryDate char(10) DEFAULT '',
PRIMARY KEY (id),
INDEX (password)
);
) DEFAULT CHARSET=utf8mb4;
`

// GetDB 获取mysql数据库连接
Expand Down
9 changes: 9 additions & 0 deletions core/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ ADD COLUMN expiryDate char(10) DEFAULT '';
return err
}
}
result := db.QueryRow(fmt.Sprintf(
"SELECT * FROM information_schema.TABLES WHERE TABLE_NAME = 'users' AND TABLE_SCHEMA = '%s' ",
mysql.Database) + " AND TABLE_COLLATION LIKE 'utf8%';")
if result.Err() == sql.ErrNoRows {
tempFile := "temp.sql"
mysql.DumpSql(tempFile)
mysql.ExecSql(tempFile)
os.Remove(tempFile)
}
return nil
}

Expand Down

0 comments on commit f8105a8

Please sign in to comment.