Skip to content

Commit 38b8d0e

Browse files
author
James Cor
committed
more refactoring
1 parent e8a1cfc commit 38b8d0e

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

server/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ func toSqlHelper(ctx *sql.Context, typ sql.Type, buf *sql.ByteBuffer, val interf
11311131
return typ.SQL(ctx, nil, val)
11321132
}
11331133
ret, err := typ.SQL(ctx, buf.Get(), val)
1134-
buf.Grow(ret.Len())
1134+
buf.Grow(ret.Len()) // TODO: shouldn't we check capacity beforehand?
11351135
return ret, err
11361136
}
11371137

@@ -1182,7 +1182,7 @@ func RowValueToSQLValues(ctx *sql.Context, sch sql.Schema, row sql.ValueRow, buf
11821182
outVals := make([]sqltypes.Value, len(sch))
11831183
for i, col := range sch {
11841184
// TODO: remove this check once all Types implement this
1185-
valType, ok := col.Type.(sql.Type2)
1185+
valType, ok := col.Type.(sql.ValueType)
11861186
if !ok {
11871187
if row[i].IsNull() {
11881188
outVals[i] = sqltypes.NULL

sql/expression/get_field.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import (
2525

2626
// GetField is an expression to get the field of a table.
2727
type GetField struct {
28-
fieldType sql.Type
29-
fieldType2 sql.Type2
28+
fieldType sql.Type
3029
// schemaFormatter is the schemaFormatter used to quote field names
3130
schemaFormatter sql.SchemaFormatter
3231

@@ -58,13 +57,11 @@ func NewGetField(index int, fieldType sql.Type, fieldName string, nullable bool)
5857

5958
// NewGetFieldWithTable creates a GetField expression with table name. The table name may be an alias.
6059
func NewGetFieldWithTable(index, tableId int, fieldType sql.Type, db, table, fieldName string, nullable bool) *GetField {
61-
fieldType2, _ := fieldType.(sql.Type2)
6260
return &GetField{
6361
db: db,
6462
table: table,
6563
fieldIndex: index,
6664
fieldType: fieldType,
67-
fieldType2: fieldType2,
6865
name: fieldName,
6966
nullable: nullable,
7067
exprId: sql.ColumnId(index),

sql/type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func IsDecimalType(t Type) bool {
292292
return ok
293293
}
294294

295-
type Type2 interface {
295+
type ValueType interface {
296296
Type
297297
ToSQLValue(*Context, Value, []byte) (sqltypes.Value, error)
298298
}

sql/types/bit.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,27 +211,23 @@ func (t BitType_) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltypes.Va
211211
return sqltypes.MakeTrusted(sqltypes.Bit, val), nil
212212
}
213213

214-
// ToSQLValue implements Type2 interface.
214+
// ToSQLValue implements ValueType interface.
215215
func (t BitType_) ToSQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) {
216216
if v.IsNull() {
217217
return sqltypes.NULL, nil
218218
}
219219

220+
// Trim/Pad result to the appropriate length
220221
numBytes := t.numOfBits / 8
221222
if t.numOfBits%8 != 0 {
222223
numBytes += 1
223224
}
224-
225-
if uint8(len(v.Val)) < numBytes {
226-
// already in little endian, so just pad with trailing 0s
227-
for i := uint8(len(v.Val)); i <= t.numOfBits/8; i++ {
228-
v.Val = append(v.Val, 0)
229-
}
230-
} else {
231-
v.Val = v.Val[:numBytes]
225+
for i := uint8(len(v.Val)); i < numBytes; i++ {
226+
v.Val = append(v.Val, 0)
232227
}
228+
v.Val = v.Val[:numBytes]
233229

234-
// TODO: for whatever reason, TestTypesOverWire only works when this is a deep copy?
230+
// TODO: for whatever reason TestTypesOverWire only works when this is a deep copy?
235231
dest = append(dest, v.Val...)
236232
// want the results in big endian
237233
for i, j := 0, len(dest)-1; i < j; i, j = i+1, j-1 {

sql/types/number.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ type NumberTypeImpl_ struct {
102102
}
103103

104104
var _ sql.Type = NumberTypeImpl_{}
105-
var _ sql.Type2 = NumberTypeImpl_{}
105+
var _ sql.ValueType = NumberTypeImpl_{}
106106
var _ sql.CollationCoercible = NumberTypeImpl_{}
107107
var _ sql.NumberType = NumberTypeImpl_{}
108108
var _ sql.RoundingNumberType = NumberTypeImpl_{}
@@ -867,7 +867,7 @@ func (t NumberTypeImpl_) Zero2() sql.Value {
867867
}
868868
}
869869

870-
// ToSQLValue implements Type2 interface.
870+
// ToSQLValue implements ValueType interface.
871871
func (t NumberTypeImpl_) ToSQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.Value, error) {
872872
if v.IsNull() {
873873
return sqltypes.NULL, nil

0 commit comments

Comments
 (0)