@@ -15,6 +15,7 @@ import (
1515 "fmt"
1616 "net"
1717 "net/url"
18+ "strconv"
1819 "strings"
1920 "time"
2021)
@@ -28,19 +29,20 @@ var (
2829
2930// Config is a configuration parsed from a DSN string
3031type Config struct {
31- User string // Username
32- Passwd string // Password (requires User)
33- Net string // Network type
34- Addr string // Network address (requires Net)
35- DBName string // Database name
36- Params map [string ]string // Connection parameters
37- Collation string // Connection collation
38- Loc * time.Location // Location for time.Time values
39- TLSConfig string // TLS configuration name
40- tls * tls.Config // TLS configuration
41- Timeout time.Duration // Dial timeout
42- ReadTimeout time.Duration // I/O read timeout
43- WriteTimeout time.Duration // I/O write timeout
32+ User string // Username
33+ Passwd string // Password (requires User)
34+ Net string // Network type
35+ Addr string // Network address (requires Net)
36+ DBName string // Database name
37+ Params map [string ]string // Connection parameters
38+ Collation string // Connection collation
39+ Loc * time.Location // Location for time.Time values
40+ MaxAllowedPacket int // Max packet size allowed
41+ TLSConfig string // TLS configuration name
42+ tls * tls.Config // TLS configuration
43+ Timeout time.Duration // Dial timeout
44+ ReadTimeout time.Duration // I/O read timeout
45+ WriteTimeout time.Duration // I/O write timeout
4446
4547 AllowAllFiles bool // Allow all files to be used with LOAD DATA LOCAL INFILE
4648 AllowCleartextPasswords bool // Allows the cleartext client side plugin
@@ -222,6 +224,17 @@ func (cfg *Config) FormatDSN() string {
222224 buf .WriteString (cfg .WriteTimeout .String ())
223225 }
224226
227+ if cfg .MaxAllowedPacket > 0 {
228+ if hasParam {
229+ buf .WriteString ("&maxAllowedPacket=" )
230+ } else {
231+ hasParam = true
232+ buf .WriteString ("?maxAllowedPacket=" )
233+ }
234+ buf .WriteString (strconv .Itoa (cfg .MaxAllowedPacket ))
235+
236+ }
237+
225238 // other params
226239 if cfg .Params != nil {
227240 for param , value := range cfg .Params {
@@ -496,7 +509,11 @@ func parseDSNParams(cfg *Config, params string) (err error) {
496509 if err != nil {
497510 return
498511 }
499-
512+ case "maxAllowedPacket" :
513+ cfg .MaxAllowedPacket , err = strconv .Atoi (value )
514+ if err != nil {
515+ return
516+ }
500517 default :
501518 // lazy init
502519 if cfg .Params == nil {
0 commit comments