From 45bcc9885028e40142316ef62421caabfd850387 Mon Sep 17 00:00:00 2001 From: lijianbin <513837235@.qq.com> Date: Wed, 27 Aug 2025 16:10:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BE=BE=E6=A2=A6--=E5=AF=86=E7=A0=81=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E5=AD=97=E7=AC=A6=E9=9C=80=E8=BD=AC=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chain_test.go | 7 +++++-- conn.go | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/chain_test.go b/chain_test.go index 212af8c..dcdfc00 100644 --- a/chain_test.go +++ b/chain_test.go @@ -9,8 +9,11 @@ import ( func Test_Chain(t *testing.T) { //测试数据库连接 //err := Connect("127.0.0.1", "root", "root", "canyin", "3306") - err := PgConnect("192.168.233.145", "bin", "Bin123456", "canyin", "5432") - //err := DmConnect("192.168.233.141", "SHOPV2", "Bin123456", "", "5236") + //err := PgConnect("192.168.233.145", "bin", "Bin123456", "canyin", "5432") + err := DmConnect("192.168.233.148", "SHOPV2", "Bin123456", "", "5236") + //err := DmConnect("10.33.0.91", "ZYSG", "Zysg!#2025", "", "5236") + //err := DmConnect("10.33.0.91", "dbck", "dskk!#555", "", "5236") + if err != nil { t.Log(err) } diff --git a/conn.go b/conn.go index e14ac98..85aecf8 100644 --- a/conn.go +++ b/conn.go @@ -4,6 +4,7 @@ import ( "database/sql" "fmt" "log" + "net/url" "errors" "strings" @@ -239,7 +240,8 @@ func DmConnect(DBHOST, DBUSER, DBPWD, DBNAME, DBPORT string, conns ...int) error if DBHOST == "" || DBUSER == "" || DBPWD == "" || DBPORT == "" { return errors.New("dm DBconnection params errors") } - + //达梦8如果密码存在特殊字符,需使用 url.PathEscape 进行转义后再放入连接串 + DBPWD = url.PathEscape(DBPWD) dsn := "dm://" + DBUSER + ":" + DBPWD + "@" + DBHOST + ":" + DBPORT + "?charSet=utf8&compatibleMode=mysql" log.Println("database dsn", dsn)