From 835cf1b0689d054f58d82f3970d59abae56178dc Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Thu, 17 Sep 2020 17:03:30 -0500 Subject: [PATCH] Fix: Bind.MarshalJSON when ParameterFormatCodes is nil or single element refs #10 --- bind.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bind.go b/bind.go index 65b4c1d6..52372095 100644 --- a/bind.go +++ b/bind.go @@ -151,7 +151,14 @@ func (src Bind) MarshalJSON() ([]byte, error) { continue } - if src.ParameterFormatCodes[i] == 0 { + textFormat := true + if len(src.ParameterFormatCodes) == 1 { + textFormat = src.ParameterFormatCodes[0] == 0 + } else if len(src.ParameterFormatCodes) > 1 { + textFormat = src.ParameterFormatCodes[i] == 0 + } + + if textFormat { formattedParameters[i] = map[string]string{"text": string(p)} } else { formattedParameters[i] = map[string]string{"binary": hex.EncodeToString(p)}