Skip to content

Commit 188256e

Browse files
authored
unsafe methods in SQL and SQLValue (#3309)
1 parent f06d885 commit 188256e

File tree

6 files changed

+11
-8
lines changed

6 files changed

+11
-8
lines changed

sql/analyzer/costed_index_scan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ type iScanLeaf struct {
10861086

10871087
func (l *iScanLeaf) normString() string {
10881088
if l.underlying != "" {
1089-
return fmt.Sprintf("%s.%s", strings.ToLower(l.underlying), strings.ToLower(l.gf.Name()))
1089+
return strings.ToLower(l.underlying) + "." + strings.ToLower(l.gf.Name())
10901090
}
10911091
return strings.ToLower(l.gf.String())
10921092
}

sql/planbuilder/ddl.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,11 +1726,12 @@ func (b *Builder) resolveColumnDefaultExpression(inScope *scope, columnDef *sql.
17261726

17271727
// Empty string is a special case, it means the default value is the empty string
17281728
// TODO: why isn't this serialized as ''
1729-
if def.String() == "" {
1729+
defStr := def.String()
1730+
if defStr == "" {
17301731
return b.convertDefaultExpression(inScope, &ast.SQLVal{Val: []byte{}, Type: ast.StrVal}, columnDef.Type, columnDef.Nullable)
17311732
}
17321733

1733-
parsed, err := b.parser.ParseSimple(fmt.Sprintf("SELECT %s", def))
1734+
parsed, err := b.parser.ParseSimple("SELECT " + defStr)
17341735
if err != nil {
17351736
err := sql.ErrInvalidColumnDefaultValue.Wrap(err, def)
17361737
b.handleErr(err)

sql/types/decimal.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"gopkg.in/src-d/go-errors.v1"
2828

2929
"github.com/dolthub/go-mysql-server/sql"
30+
"github.com/dolthub/go-mysql-server/sql/encodings"
3031
"github.com/dolthub/go-mysql-server/sql/values"
3132
)
3233

@@ -342,7 +343,7 @@ func (t DecimalType_) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltype
342343
if err != nil {
343344
return sqltypes.Value{}, err
344345
}
345-
val := AppendAndSliceString(dest, t.DecimalValueStringFixed(value.Decimal))
346+
val := encodings.StringToBytes(t.DecimalValueStringFixed(value.Decimal))
346347
return sqltypes.MakeTrusted(sqltypes.Decimal, val), nil
347348
}
348349

@@ -351,7 +352,7 @@ func (t DecimalType_) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqlt
351352
return sqltypes.NULL, nil
352353
}
353354
d := values.ReadDecimal(v.Val)
354-
return sqltypes.MakeTrusted(sqltypes.Decimal, []byte(t.DecimalValueStringFixed(d))), nil
355+
return sqltypes.MakeTrusted(sqltypes.Decimal, encodings.StringToBytes(t.DecimalValueStringFixed(d))), nil
355356
}
356357

357358
// String implements Type interface.

sql/types/enum.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func (t EnumType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes
289289
}
290290

291291
// TODO: write append style encoder
292-
res, ok := charset.Encoder().Encode([]byte(value))
292+
res, ok := charset.Encoder().Encode(encodings.StringToBytes(value))
293293
if !ok {
294294
if len(value) > 50 {
295295
value = value[:50]

sql/types/json.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/shopspring/decimal"
2525

2626
"github.com/dolthub/go-mysql-server/sql"
27+
"github.com/dolthub/go-mysql-server/sql/encodings"
2728
)
2829

2930
var (
@@ -166,7 +167,7 @@ func (t JsonType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltypes.Va
166167
if err != nil {
167168
return sqltypes.NULL, err
168169
}
169-
val = AppendAndSliceString(dest, str)
170+
val = encodings.StringToBytes(str)
170171
}
171172

172173
return sqltypes.MakeTrusted(sqltypes.TypeJSON, val), nil

sql/types/set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (t SetType) SQLValue(ctx *sql.Context, v sql.Value, dest []byte) (sqltypes.
285285
}
286286

287287
// TODO: write append style encoder
288-
res, ok := resultCharset.Encoder().Encode([]byte(value))
288+
res, ok := resultCharset.Encoder().Encode(encodings.StringToBytes(value))
289289
if !ok {
290290
if len(value) > 50 {
291291
value = value[:50]

0 commit comments

Comments
 (0)