mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-28 01:11:31 +08:00
🐛 fix(mysql): 修复旧版 Windows 无法解析 Asia/Shanghai 时区
- 嵌入 Go IANA 时区数据,兼容 Windows Server 2012 等缺少 zoneinfo 的环境 - 保持 MySQL serverTimezone=GMT+8 到 loc=Asia/Shanghai 的时间语义 - 增加 MySQL DSN 时区解析回归测试 Refs #449
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -121,6 +122,28 @@ func TestMySQLDSN_MapsJDBCUTF8EncodingToMySQLCharset(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMySQLDSN_AsiaShanghaiLocationAcceptedByDriver(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
m := &MySQLDB{}
|
||||
dsn, err := m.getDSN(connection.ConnectionConfig{
|
||||
Host: "127.0.0.1",
|
||||
Port: 3306,
|
||||
User: "root",
|
||||
Database: "app",
|
||||
ConnectionParams: "serverTimezone=GMT%2B8",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("getDSN failed: %v", err)
|
||||
}
|
||||
|
||||
db, err := sql.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("mysql driver should accept loc=Asia/Shanghai: %v", err)
|
||||
}
|
||||
_ = db.Close()
|
||||
}
|
||||
|
||||
func TestMySQLDSN_URIParamsAndExplicitParamsPrecedence(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
6
internal/db/timezone_data.go
Normal file
6
internal/db/timezone_data.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package db
|
||||
|
||||
// Embed the IANA time zone database so Windows deployments without zoneinfo
|
||||
// files, such as Windows Server 2012, can still resolve locations like
|
||||
// Asia/Shanghai when database drivers parse DSN time zone parameters.
|
||||
import _ "time/tzdata"
|
||||
Reference in New Issue
Block a user