2
0

Add pgtype.ByteaArray

Also fix up quoting array elements for text arrays.
This commit is contained in:
Jack Christensen
2017-03-11 13:32:32 -06:00
parent e654d1f0fc
commit 86620c5e91
17 changed files with 437 additions and 76 deletions
+14
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"strconv"
"strings"
"unicode"
"github.com/jackc/pgx/pgio"
@@ -371,3 +372,16 @@ func EncodeTextArrayDimensions(w io.Writer, dimensions []ArrayDimension) error {
return pgio.WriteByte(w, '=')
}
var quoteArrayReplacer = strings.NewReplacer(`\`, `\\`, `"`, `\"`)
func quoteArrayElement(src string) string {
return `"` + quoteArrayReplacer.Replace(src) + `"`
}
func QuoteArrayElementIfNeeded(src string) string {
if src == "" || (len(src) == 4 && strings.ToLower(src) == "null") || src[0] == ' ' || src[len(src)-1] == ' ' || strings.ContainsAny(src, `{},"\`) {
return quoteArrayElement(src)
}
return src
}