Skip to content

Commit

Permalink
Fix boolean serialization via Postgres protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Feb 19, 2025
1 parent 1085997 commit 53062b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
VERSION = "0.32.4"
VERSION = "0.32.5"

ENV_PORT = "BEMIDB_PORT"
ENV_DATABASE = "BEMIDB_DATABASE"
Expand Down
2 changes: 1 addition & 1 deletion src/query_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ func (queryHandler *QueryHandler) generateDataRow(rows *sql.Rows, cols []*sql.Co
}
case *sql.NullBool:
if value.Valid {
values = append(values, []byte(fmt.Sprintf("%v", value.Bool)))
values = append(values, []byte(fmt.Sprintf("%v", value.Bool)[0:1]))
} else {
values = append(values, nil)
}
Expand Down
18 changes: 9 additions & 9 deletions src/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestHandleQuery(t *testing.T) {
"SELECT * from pg_is_in_recovery()": {
"description": {"pg_is_in_recovery"},
"types": {Uint32ToString(pgtype.BoolOID)},
"values": {"false"},
"values": {"f"},
},
"SELECT row_to_json(t) FROM (SELECT usename, passwd FROM pg_shadow WHERE usename='bemidb') t": {
"description": {"row_to_json"},
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestHandleQuery(t *testing.T) {
"SELECT * FROM pg_catalog.pg_user": {
"description": {"usename", "usesysid", "usecreatedb", "usesuper", "userepl", "usebypassrls", "passwd", "valuntil", "useconfig"},
"types": {Uint32ToString(pgtype.TextOID)},
"values": {"bemidb", "10", "true", "true", "true", "true", "", "", ""},
"values": {"bemidb", "10", "t", "t", "t", "t", "", "", ""},
},
"SELECT datid FROM pg_catalog.pg_stat_activity": {
"description": {"datid"},
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestHandleQuery(t *testing.T) {
Uint32ToString(pgtype.BoolOID),
Uint32ToString(pgtype.Int4OID),
},
"values": {"10", "bemidb", "true", "true", "true", "true", "true", "false", "-1", "", "", "false", ""},
"values": {"10", "bemidb", "t", "t", "t", "t", "t", "f", "-1", "", "", "f", ""},
},
"SELECT * FROM pg_catalog.pg_inherits": {
"description": {"inhrelid", "inhparent", "inhseqno", "inhdetachpending"},
Expand Down Expand Up @@ -318,12 +318,12 @@ func TestHandleQuery(t *testing.T) {
"SELECT bool_column FROM public.test_table WHERE bool_column = TRUE": {
"description": {"bool_column"},
"types": {Uint32ToString(pgtype.BoolOID)},
"values": {"true"},
"values": {"t"},
},
"SELECT bool_column FROM public.test_table WHERE bool_column = FALSE": {
"description": {"bool_column"},
"types": {Uint32ToString(pgtype.BoolOID)},
"values": {"false"},
"values": {"f"},
},
"SELECT bpchar_column FROM public.test_table WHERE bool_column = TRUE": {
"description": {"bpchar_column"},
Expand Down Expand Up @@ -685,12 +685,12 @@ func TestHandleQuery(t *testing.T) {
"SELECT '\"public\".\"test_table\"'::regclass::oid > 1270 AS oid": {
"description": {"oid"},
"types": {Uint32ToString(pgtype.BoolOID)},
"values": {"true"},
"values": {"t"},
},
"SELECT attrelid > 1270 AS attrelid FROM pg_attribute WHERE attrelid = '\"public\".\"test_table\"'::regclass LIMIT 1": {
"description": {"attrelid"},
"types": {Uint32ToString(pgtype.BoolOID)},
"values": {"true"},
"values": {"t"},
},
"SELECT COUNT(*) AS count FROM pg_attribute WHERE attrelid = '\"public\".\"test_table\"'::regclass": {
"description": {"count"},
Expand Down Expand Up @@ -830,7 +830,7 @@ func TestHandleQuery(t *testing.T) {
"SELECT CASE WHEN nsp.nspname = ANY('{information_schema}') THEN false ELSE true END AS db_support FROM pg_catalog.pg_namespace nsp WHERE nsp.oid = 1268::OID;": {
"description": {"db_support"},
"types": {Uint32ToString(pgtype.BoolOID)},
"values": {"true"},
"values": {"t"},
},

// WHERE pg functions
Expand Down Expand Up @@ -938,7 +938,7 @@ func TestHandleQuery(t *testing.T) {
Uint32ToString(pgtype.Int8OID),
Uint32ToString(pgtype.TextOID),
},
"values": {"16388", "bemidb", "", "true", "false", "true", "10", ""},
"values": {"16388", "bemidb", "", "t", "f", "t", "10", ""},
},
}

Expand Down

0 comments on commit 53062b5

Please sign in to comment.