Skip to content

Commit

Permalink
Enable pgx simple protocol if prepared statements disabled (#3436)
Browse files Browse the repository at this point in the history
Signed-off-by: Lev Zakharov <[email protected]>
  • Loading branch information
lzakharov authored Sep 4, 2024
1 parent 554d2c9 commit 413d05c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
3 changes: 1 addition & 2 deletions internal/storage/sql/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,8 @@ func parse(cfg config.Config, opts Options) (Driver, *dburl.URL, error) {
v.Set("sslmode", "disable")
}

// see: https://github.com/lib/pq/issues/389
if !cfg.Database.PreparedStatementsEnabled {
v.Set("binary_parameters", "yes")
v.Set("default_query_exec_mode", "simple_protocol")
}
case MySQL:
v.Set("multiStatements", "true")
Expand Down
34 changes: 17 additions & 17 deletions internal/storage/sql/db_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestParse(t *testing.T) {
URL: "postgresql://postgres@localhost:5432/flipt?sslmode=disable",
},
driver: Postgres,
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes&sslmode=disable",
dsn: "postgres://postgres@localhost:5432/flipt?default_query_exec_mode=simple_protocol&sslmode=disable",
},
{
name: "postgresql url prepared statements enabled",
Expand All @@ -57,7 +57,7 @@ func TestParse(t *testing.T) {
URL: "postgresql://postgres@localhost:5432/flipt",
},
driver: Postgres,
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes",
dsn: "postgres://postgres@localhost:5432/flipt?default_query_exec_mode=simple_protocol",
},
{
name: "postgres url prepared statements enabled",
Expand All @@ -74,15 +74,15 @@ func TestParse(t *testing.T) {
URL: "postgres://postgres@localhost:5432/flipt?sslmode=disable",
},
driver: Postgres,
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes&sslmode=disable",
dsn: "postgres://postgres@localhost:5432/flipt?default_query_exec_mode=simple_protocol&sslmode=disable",
},
{
name: "postgres no disable sslmode",
cfg: config.DatabaseConfig{
URL: "postgres://postgres@localhost:5432/flipt",
},
driver: Postgres,
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes",
dsn: "postgres://postgres@localhost:5432/flipt?default_query_exec_mode=simple_protocol",
},
{
name: "postgres disable sslmode via opts",
Expand All @@ -95,7 +95,7 @@ func TestParse(t *testing.T) {
},
options: []Option{WithSSLDisabled},
driver: Postgres,
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes&sslmode=disable",
dsn: "postgres://postgres@localhost:5432/flipt?default_query_exec_mode=simple_protocol&sslmode=disable",
},
{
name: "postgres no port",
Expand All @@ -106,7 +106,7 @@ func TestParse(t *testing.T) {
User: "postgres",
},
driver: Postgres,
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes",
dsn: "postgres://postgres@localhost:5432/flipt?default_query_exec_mode=simple_protocol",
},
{
name: "postgres no password",
Expand All @@ -118,7 +118,7 @@ func TestParse(t *testing.T) {
User: "postgres",
},
driver: Postgres,
dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes",
dsn: "postgres://postgres@localhost:5432/flipt?default_query_exec_mode=simple_protocol",
},
{
name: "postgres with password",
Expand All @@ -131,7 +131,7 @@ func TestParse(t *testing.T) {
Password: "foo",
},
driver: Postgres,
dsn: "postgres://postgres:foo@localhost:5432/flipt?binary_parameters=yes",
dsn: "postgres://postgres:foo@localhost:5432/flipt?default_query_exec_mode=simple_protocol",
},
{
name: "mysql url",
Expand Down Expand Up @@ -208,23 +208,23 @@ func TestParse(t *testing.T) {
URL: "cockroachdb://cockroachdb@localhost:26257/flipt?sslmode=disable",
},
driver: CockroachDB,
dsn: "postgres://cockroachdb@localhost:26257/flipt?binary_parameters=yes&sslmode=disable",
dsn: "postgres://cockroachdb@localhost:26257/flipt?default_query_exec_mode=simple_protocol&sslmode=disable",
},
{
name: "cockroachdb url alternative (cockroach://",
cfg: config.DatabaseConfig{
URL: "cockroach://cockroachdb@localhost:26257/flipt?sslmode=disable",
},
driver: CockroachDB,
dsn: "postgres://cockroachdb@localhost:26257/flipt?binary_parameters=yes&sslmode=disable",
dsn: "postgres://cockroachdb@localhost:26257/flipt?default_query_exec_mode=simple_protocol&sslmode=disable",
},
{
name: "cockroachdb url alternative (crdb://",
cfg: config.DatabaseConfig{
URL: "crdb://cockroachdb@localhost:26257/flipt?sslmode=disable",
},
driver: CockroachDB,
dsn: "postgres://cockroachdb@localhost:26257/flipt?binary_parameters=yes&sslmode=disable",
dsn: "postgres://cockroachdb@localhost:26257/flipt?default_query_exec_mode=simple_protocol&sslmode=disable",
},
{
name: "cockroachdb default disable sslmode",
Expand All @@ -234,7 +234,7 @@ func TestParse(t *testing.T) {
URL: "cockroachdb://cockroachdb@localhost:26257/flipt",
},
driver: CockroachDB,
dsn: "postgres://cockroachdb@localhost:26257/flipt?binary_parameters=yes&sslmode=disable",
dsn: "postgres://cockroachdb@localhost:26257/flipt?default_query_exec_mode=simple_protocol&sslmode=disable",
},
{
name: "cockroachdb disable sslmode via opts",
Expand All @@ -249,7 +249,7 @@ func TestParse(t *testing.T) {
WithSSLDisabled,
},
driver: CockroachDB,
dsn: "postgres://cockroachdb@localhost:26257/flipt?binary_parameters=yes&sslmode=disable",
dsn: "postgres://cockroachdb@localhost:26257/flipt?default_query_exec_mode=simple_protocol&sslmode=disable",
},
{
name: "cockroachdb no port",
Expand All @@ -260,7 +260,7 @@ func TestParse(t *testing.T) {
User: "cockroachdb",
},
driver: CockroachDB,
dsn: "postgres://cockroachdb@localhost:26257/flipt?binary_parameters=yes&sslmode=disable",
dsn: "postgres://cockroachdb@localhost:26257/flipt?default_query_exec_mode=simple_protocol&sslmode=disable",
},
{
name: "cockroachdb no password",
Expand All @@ -272,7 +272,7 @@ func TestParse(t *testing.T) {
User: "cockroachdb",
},
driver: CockroachDB,
dsn: "postgres://cockroachdb@localhost:26257/flipt?binary_parameters=yes&sslmode=disable",
dsn: "postgres://cockroachdb@localhost:26257/flipt?default_query_exec_mode=simple_protocol&sslmode=disable",
},
{
name: "cockroachdb with password",
Expand All @@ -285,7 +285,7 @@ func TestParse(t *testing.T) {
Password: "foo",
},
driver: CockroachDB,
dsn: "postgres://cockroachdb:foo@localhost:26257/flipt?binary_parameters=yes&sslmode=disable",
dsn: "postgres://cockroachdb:foo@localhost:26257/flipt?default_query_exec_mode=simple_protocol&sslmode=disable",
},
{
name: "invalid url",
Expand All @@ -308,7 +308,7 @@ func TestParse(t *testing.T) {
PreparedStatementsEnabled: false,
},
driver: Postgres,
dsn: "postgres://user:pass@host1:5432,host2:2345/flipt?application_name=flipt&binary_parameters=yes&target_session_attrs=primary",
dsn: "postgres://user:pass@host1:5432,host2:2345/flipt?application_name=flipt&default_query_exec_mode=simple_protocol&target_session_attrs=primary",
},
}

Expand Down

0 comments on commit 413d05c

Please sign in to comment.