|
1 | 1 | package sql |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | | - |
6 | 4 | "github.com/dolthub/go-mysql-server/sql/values" |
7 | 5 |
|
8 | 6 | "github.com/dolthub/vitess/go/vt/proto/query" |
9 | 7 | ) |
10 | 8 |
|
11 | 9 | // ConvertToValue converts the interface to a sql value. |
12 | | -func ConvertToValue(v interface{}) (Value, error) { |
| 10 | +func ConvertToValue(v interface{}) Value { |
13 | 11 | switch v := v.(type) { |
14 | 12 | case nil: |
15 | 13 | return Value{ |
16 | 14 | Typ: query.Type_NULL_TYPE, |
17 | 15 | Val: nil, |
18 | | - }, nil |
| 16 | + } |
19 | 17 | case int: |
20 | 18 | return Value{ |
21 | 19 | Typ: query.Type_INT64, |
22 | 20 | Val: values.WriteInt64(make([]byte, values.Int64Size), int64(v)), |
23 | | - }, nil |
| 21 | + } |
24 | 22 | case int8: |
25 | 23 | return Value{ |
26 | 24 | Typ: query.Type_INT8, |
27 | 25 | Val: values.WriteInt8(make([]byte, values.Int8Size), v), |
28 | | - }, nil |
| 26 | + } |
29 | 27 | case int16: |
30 | 28 | return Value{ |
31 | 29 | Typ: query.Type_INT16, |
32 | 30 | Val: values.WriteInt16(make([]byte, values.Int16Size), v), |
33 | | - }, nil |
| 31 | + } |
34 | 32 | case int32: |
35 | 33 | return Value{ |
36 | 34 | Typ: query.Type_INT32, |
37 | 35 | Val: values.WriteInt32(make([]byte, values.Int32Size), v), |
38 | | - }, nil |
| 36 | + } |
39 | 37 | case int64: |
40 | 38 | return Value{ |
41 | 39 | Typ: query.Type_INT64, |
42 | 40 | Val: values.WriteInt64(make([]byte, values.Int64Size), v), |
43 | | - }, nil |
| 41 | + } |
44 | 42 | case uint: |
45 | 43 | return Value{ |
46 | 44 | Typ: query.Type_UINT64, |
47 | 45 | Val: values.WriteUint64(make([]byte, values.Uint64Size), uint64(v)), |
48 | | - }, nil |
| 46 | + } |
49 | 47 | case uint8: |
50 | 48 | return Value{ |
51 | 49 | Typ: query.Type_UINT8, |
52 | 50 | Val: values.WriteUint8(make([]byte, values.Uint8Size), v), |
53 | | - }, nil |
| 51 | + } |
54 | 52 | case uint16: |
55 | 53 | return Value{ |
56 | 54 | Typ: query.Type_UINT16, |
57 | 55 | Val: values.WriteUint16(make([]byte, values.Uint16Size), v), |
58 | | - }, nil |
| 56 | + } |
59 | 57 | case uint32: |
60 | 58 | return Value{ |
61 | 59 | Typ: query.Type_UINT32, |
62 | 60 | Val: values.WriteUint32(make([]byte, values.Uint32Size), v), |
63 | | - }, nil |
| 61 | + } |
64 | 62 | case uint64: |
65 | 63 | return Value{ |
66 | 64 | Typ: query.Type_UINT64, |
67 | 65 | Val: values.WriteUint64(make([]byte, values.Uint64Size), v), |
68 | | - }, nil |
| 66 | + } |
69 | 67 | case float32: |
70 | 68 | return Value{ |
71 | 69 | Typ: query.Type_FLOAT32, |
72 | 70 | Val: values.WriteFloat32(make([]byte, values.Float32Size), v), |
73 | | - }, nil |
| 71 | + } |
74 | 72 | case float64: |
75 | 73 | return Value{ |
76 | 74 | Typ: query.Type_FLOAT64, |
77 | 75 | Val: values.WriteFloat64(make([]byte, values.Float64Size), v), |
78 | | - }, nil |
| 76 | + } |
79 | 77 | case string: |
80 | 78 | return Value{ |
81 | 79 | Typ: query.Type_VARCHAR, |
82 | 80 | Val: values.WriteString(make([]byte, len(v)), v, values.ByteOrderCollation), |
83 | | - }, nil |
| 81 | + } |
84 | 82 | case []byte: |
85 | 83 | return Value{ |
86 | 84 | Typ: query.Type_BLOB, |
87 | 85 | Val: values.WriteBytes(make([]byte, len(v)), v, values.ByteOrderCollation), |
88 | | - }, nil |
| 86 | + } |
89 | 87 | default: |
90 | | - return Value{}, fmt.Errorf("type %T not implemented", v) |
| 88 | + return Value{} |
91 | 89 | } |
92 | 90 | } |
0 commit comments