mirror of https://github.com/jackc/pgx.git
parent
1dc7133a63
commit
d9ac491657
11
conn.go
11
conn.go
|
@ -160,11 +160,22 @@ func ParseConfig(connString string) (*ConnConfig, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
preferSimpleProtocol := false
|
||||||
|
if s, ok := config.RuntimeParams["prefer_simple_protocol"]; ok {
|
||||||
|
delete(config.RuntimeParams, "prefer_simple_protocol")
|
||||||
|
if b, err := strconv.ParseBool(s); err == nil {
|
||||||
|
preferSimpleProtocol = b
|
||||||
|
} else {
|
||||||
|
return nil, errors.Errorf("invalid prefer_simple_protocol: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
connConfig := &ConnConfig{
|
connConfig := &ConnConfig{
|
||||||
Config: *config,
|
Config: *config,
|
||||||
createdByParseConfig: true,
|
createdByParseConfig: true,
|
||||||
LogLevel: LogLevelInfo,
|
LogLevel: LogLevelInfo,
|
||||||
BuildStatementCache: buildStatementCache,
|
BuildStatementCache: buildStatementCache,
|
||||||
|
PreferSimpleProtocol: preferSimpleProtocol,
|
||||||
connString: connString,
|
connString: connString,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
conn_test.go
20
conn_test.go
|
@ -169,6 +169,26 @@ func TestParseConfigExtractsStatementCacheOptions(t *testing.T) {
|
||||||
require.Equal(t, stmtcache.ModeDescribe, c.Mode())
|
require.Equal(t, stmtcache.ModeDescribe, c.Mode())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseConfigExtractsPreferSimpleProtocol(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
for _, tt := range []struct {
|
||||||
|
connString string
|
||||||
|
preferSimpleProtocol bool
|
||||||
|
}{
|
||||||
|
{"", false},
|
||||||
|
{"prefer_simple_protocol=false", false},
|
||||||
|
{"prefer_simple_protocol=0", false},
|
||||||
|
{"prefer_simple_protocol=true", true},
|
||||||
|
{"prefer_simple_protocol=1", true},
|
||||||
|
} {
|
||||||
|
config, err := pgx.ParseConfig(tt.connString)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equalf(t, tt.preferSimpleProtocol, config.PreferSimpleProtocol, "connString: `%s`", tt.connString)
|
||||||
|
require.Empty(t, config.RuntimeParams["prefer_simple_protocol"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestExec(t *testing.T) {
|
func TestExec(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue