diff --git a/context.go b/context.go index 719ff8e..786ef74 100644 --- a/context.go +++ b/context.go @@ -128,7 +128,7 @@ func (c Context) ResultTime(value time.Time, format TimeFormat) { } func (c Context) resultRFC3339Nano(value time.Time) { - const maxlen = uint64(len(time.RFC3339Nano)) + const maxlen = uint64(len(time.RFC3339Nano)) + 5 ptr := c.new(maxlen) buf := util.View(c.mod, ptr, maxlen) diff --git a/json.go b/json.go index 1bd7a83..0dcdba0 100644 --- a/json.go +++ b/json.go @@ -5,6 +5,8 @@ import ( "strconv" "time" "unsafe" + + "github.com/ncruces/go-sqlite3/internal/util" ) // JSON returns: @@ -29,8 +31,7 @@ func (j jsonValue) UnmarshalJSON(data []byte) error { } func (j jsonValue) Scan(value any) error { - var mem [40]byte - buf := mem[:0] + var buf []byte switch v := value.(type) { case []byte: @@ -47,6 +48,8 @@ func (j jsonValue) Scan(value any) error { buf = append(buf, '"') case nil: buf = append(buf, "null"...) + default: + panic(util.AssertErr()) } return j.UnmarshalJSON(buf) diff --git a/stmt.go b/stmt.go index 34b638a..04a91ec 100644 --- a/stmt.go +++ b/stmt.go @@ -237,7 +237,7 @@ func (s *Stmt) BindTime(param int, value time.Time, format TimeFormat) error { } func (s *Stmt) bindRFC3339Nano(param int, value time.Time) error { - const maxlen = uint64(len(time.RFC3339Nano)) + const maxlen = uint64(len(time.RFC3339Nano)) + 5 ptr := s.c.new(maxlen) buf := util.View(s.c.mod, ptr, maxlen) @@ -430,8 +430,10 @@ func (s *Stmt) ColumnJSON(col int, ptr any) error { var data []byte switch s.ColumnType(col) { case NULL: - data = []byte("null") - case TEXT, BLOB: + data = append(data, "null"...) + case TEXT: + data = s.ColumnRawText(col) + case BLOB: data = s.ColumnRawBlob(col) case INTEGER: data = strconv.AppendInt(nil, s.ColumnInt64(col), 10) diff --git a/value.go b/value.go index 6db8d15..0fcc5ef 100644 --- a/value.go +++ b/value.go @@ -132,8 +132,10 @@ func (v Value) JSON(ptr any) error { var data []byte switch v.Type() { case NULL: - data = []byte("null") - case TEXT, BLOB: + data = append(data, "null"...) + case TEXT: + data = v.RawText() + case BLOB: data = v.RawBlob() case INTEGER: data = strconv.AppendInt(nil, v.Int64(), 10)