Skip to content

Conversation

@k-jun
Copy link

@k-jun k-jun commented Apr 8, 2019

I had a problem when I am using this library and this PR is to fix that.
My code is something like that.

[psql]
  dbname = "my_database"
  host   = "localhost"
  port   = 5432
  user   = "keijun"
  pass   = ""
  blacklist = ["schema_migrations"]
  sslmode= "disable"
type Config struct {
	Psql psqlConfig
}

type psqlConfig struct {
	Dbname string `toml:"dbname"`
	Host   string `toml:"host"`
	Port   int    `toml:"port"`
	User   string `toml:"user"`
	Pass   string `toml:"pass"`
}

var config Config
_, err = toml.DecodeFile("./sqlboiler.toml", &config)

psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
	config.Psql.Host, config.Psql.Port, config.Psql.User, config.Psql.Pass, config.Psql.Dbname,
)

DB, err = sql.Open("postgres", psqlInfo)
rows, err := DB.Query(`SELECT * FROM users`)

if the password info was not provided or "", the driver gave me an error.

panic: pq: database "keijun" does not exist

I know this is because the password is blank and following part (in this case "dbname") is handled as a password value, and instead of that, the username was used as a database name.

this is an expected behavior as I could see from the test code, like

{"user= password=foo", values{"user": "password=foo"}, true},

but I thought to check if the value contains "=" and if so, add new key is better.
This is my first time to make PR so maybe I am saying something stupid, so if there are any strange points please let me know.
Thanks

@arp242 arp242 added the needs-test Needs a test before it can be merged label Dec 31, 2025
@arp242
Copy link
Collaborator

arp242 commented Jan 3, 2026

Seems to work in a quick test?

func TestXXX(t *testing.T) {
    db, err := sql.Open("postgres", "host=localhost user=pqgo password= dbname=pqgo sslmode=disable")
    if err != nil {
        t.Fatal(err)
    }

    rows, err := db.Query(`select 'zxc'`)
    if err != nil {
        t.Fatal(err)
    }
    rows.Next()
    var s string
    err = rows.Scan(&s)
    fmt.Println(err, s)
}

Outputs <nil> zxc.

@arp242 arp242 added needs-feedback Requires feedback to be actionable needs-test Needs a test before it can be merged and removed needs-test Needs a test before it can be merged labels Jan 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-feedback Requires feedback to be actionable needs-test Needs a test before it can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants