Skip to content

FormatDSN does not set default parameters correctly #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SeanBenoit opened this issue May 30, 2018 · 1 comment
Closed

FormatDSN does not set default parameters correctly #812

SeanBenoit opened this issue May 30, 2018 · 1 comment

Comments

@SeanBenoit
Copy link

Issue description

Config.FormatDSN() will override the default values of AllowNativePasswords and MaxAllowedPackets specified in README.md with zero values (false instead of true and 0 instead of 4194304 respectively). This means that using it to generate the DSN to be passed to Open() will cause behaviour that does not match the behaviour specified in this package's documentation.

Example code

package main

import (
	"fmt"
	gomysql "github.com/Go-SQL-Driver/MySQL"
)

func main() {
	config := gomysql.Config{
		User:   "user",
		Passwd: "password",
		Net:    "tcp",
		Addr:   "hostname:Port",
		DBName: "dbname",
	}

	fmt.Println(config.FormatDSN())
	// Expected output: user:password@tcp(hostname:Port)/dbname
	// Actual output: user:password@tcp(hostname:Port)/dbname?allowNativePasswords=false&maxAllowedPacket=0
}

Configuration

Driver version (or git SHA): commit 7413002

Go version: go version go1.10.2 linux/amd64

Server version: N/A

Server OS: N/A

@julienschmidt
Copy link
Member

The respective godoc clearly states that NewConfig() should be used to set defaults if a new config is created instead of parsing it from a DSN string. Otherwise you'll get zero values - that is false and 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants