@@ -18,16 +18,13 @@ import (
1818 "context"
1919 "encoding/binary"
2020 "fmt"
21- "reflect"
22- "strconv"
23-
2421 "github.com/dolthub/vitess/go/sqltypes"
2522 "github.com/dolthub/vitess/go/vt/proto/query"
2623 "github.com/shopspring/decimal"
2724 "gopkg.in/src-d/go-errors.v1"
25+ "reflect"
2826
2927 "github.com/dolthub/go-mysql-server/sql"
30- "github.com/dolthub/go-mysql-server/sql/values"
3128)
3229
3330const (
@@ -218,9 +215,27 @@ func (t BitType_) ToSQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltyp
218215 if v .IsNull () {
219216 return sqltypes .NULL , nil
220217 }
221- // Assume this is uint64
222- x := values .ReadUint64 (v .Val )
223- dest = strconv .AppendUint (dest , x , 10 )
218+
219+ numBytes := t .numOfBits / 8
220+ if t .numOfBits % 8 != 0 {
221+ numBytes += 1
222+ }
223+
224+ if uint8 (len (v .Val )) < numBytes {
225+ // already in little endian, so just pad with trailing 0s
226+ for i := uint8 (len (v .Val )); i <= t .numOfBits / 8 ; i ++ {
227+ v .Val = append (v .Val , 0 )
228+ }
229+ } else {
230+ v .Val = v .Val [:numBytes ]
231+ }
232+
233+ // TODO: for whatever reason, TestTypesOverWire only works when this is a deep copy?
234+ dest = append (dest , v .Val ... )
235+ // want the results in big endian
236+ for i , j := 0 , len (dest )- 1 ; i < j ; i , j = i + 1 , j - 1 {
237+ dest [i ], dest [j ] = dest [j ], dest [i ]
238+ }
224239 return sqltypes .MakeTrusted (sqltypes .Bit , dest ), nil
225240}
226241
0 commit comments