MCPcopy
hub / github.com/cube2222/octosql / BuildConverted

Function BuildConverted

parser/sqlparser/dependency/sqltypes/value.go:120–138  ·  view source on GitHub ↗

BuildConverted is like BuildValue except that it tries to convert a string or []byte to an integral if the target type is an integral. We don't perform other implicit conversions because they're unsafe.

(typ querypb.Type, goval interface{})

Source from the content-addressed store, hash-verified

118// is an integral. We don't perform other implicit conversions
119// because they're unsafe.
120func BuildConverted(typ querypb.Type, goval interface{}) (v Value, err error) {
121 if IsIntegral(typ) {
122 switch goval := goval.(type) {
123 case []byte:
124 return ValueFromBytes(typ, goval)
125 case string:
126 return ValueFromBytes(typ, []byte(goval))
127 case Value:
128 if goval.IsQuoted() {
129 return ValueFromBytes(typ, goval.Raw())
130 }
131 case *querypb.BindVariable:
132 if IsQuoted(goval.Type) {
133 return ValueFromBytes(typ, goval.Value)
134 }
135 }
136 }
137 return BuildValue(goval)
138}
139
140// ValueFromBytes builds a Value using typ and val. It ensures that val
141// matches the requested type. If type is an integral it's converted to

Callers 1

TestBuildConvertedFunction · 0.85

Calls 6

IsIntegralFunction · 0.85
ValueFromBytesFunction · 0.85
IsQuotedFunction · 0.85
BuildValueFunction · 0.85
IsQuotedMethod · 0.80
RawMethod · 0.45

Tested by 1

TestBuildConvertedFunction · 0.68