mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Fix hstore with empty string values
This commit is contained in:
parent
937aec9841
commit
36944b232f
@ -168,6 +168,7 @@ func (src Hstore) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
|
|||||||
|
|
||||||
firstPair := true
|
firstPair := true
|
||||||
|
|
||||||
|
inElemBuf := make([]byte, 0, 32)
|
||||||
for k, v := range src.Map {
|
for k, v := range src.Map {
|
||||||
if firstPair {
|
if firstPair {
|
||||||
firstPair = false
|
firstPair = false
|
||||||
@ -178,7 +179,7 @@ func (src Hstore) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
|
|||||||
buf = append(buf, quoteHstoreElementIfNeeded(k)...)
|
buf = append(buf, quoteHstoreElementIfNeeded(k)...)
|
||||||
buf = append(buf, "=>"...)
|
buf = append(buf, "=>"...)
|
||||||
|
|
||||||
elemBuf, err := v.EncodeText(ci, nil)
|
elemBuf, err := v.EncodeText(ci, inElemBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ func TestHstoreTranscode(t *testing.T) {
|
|||||||
|
|
||||||
values := []interface{}{
|
values := []interface{}{
|
||||||
&pgtype.Hstore{Map: map[string]pgtype.Text{}, Status: pgtype.Present},
|
&pgtype.Hstore{Map: map[string]pgtype.Text{}, Status: pgtype.Present},
|
||||||
|
&pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text(""), "bar": text(""), "baz": text("123")}, Status: pgtype.Present},
|
||||||
&pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text("bar")}, Status: pgtype.Present},
|
&pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text("bar")}, Status: pgtype.Present},
|
||||||
&pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text("bar"), "baz": text("quz")}, Status: pgtype.Present},
|
&pgtype.Hstore{Map: map[string]pgtype.Text{"foo": text("bar"), "baz": text("quz")}, Status: pgtype.Present},
|
||||||
&pgtype.Hstore{Map: map[string]pgtype.Text{"NULL": text("bar")}, Status: pgtype.Present},
|
&pgtype.Hstore{Map: map[string]pgtype.Text{"NULL": text("bar")}, Status: pgtype.Present},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user