Fix decoding of ARRAY[]::text[]

The original version could not decode ARRAY[]::text[]. When an empty array was detected, decode1dArrayHeader was not reading enough values off the socket, and subsequent values were incorrectly read.
pull/77/head
Laurent Debacker 2015-04-07 22:26:45 +02:00 committed by Jack Christensen
parent 82a2d9de96
commit bc7ca55b45
1 changed files with 5 additions and 4 deletions

View File

@ -1102,16 +1102,17 @@ func encodeTimestamp(w *WriteBuf, value interface{}) error {
func decode1dArrayHeader(vr *ValueReader) (length int32, err error) { func decode1dArrayHeader(vr *ValueReader) (length int32, err error) {
numDims := vr.ReadInt32() numDims := vr.ReadInt32()
if numDims == 0 { if numDims > 1 {
return 0, nil
}
if numDims != 1 {
return 0, ProtocolError(fmt.Sprintf("Expected array to have 0 or 1 dimension, but it had %v", numDims)) return 0, ProtocolError(fmt.Sprintf("Expected array to have 0 or 1 dimension, but it had %v", numDims))
} }
vr.ReadInt32() // 0 if no nulls / 1 if there is one or more nulls -- but we don't care vr.ReadInt32() // 0 if no nulls / 1 if there is one or more nulls -- but we don't care
vr.ReadInt32() // element oid vr.ReadInt32() // element oid
if numDims == 0 {
return 0, nil
}
length = vr.ReadInt32() length = vr.ReadInt32()
idxFirstElem := vr.ReadInt32() idxFirstElem := vr.ReadInt32()