MCPcopy
hub / github.com/dropbox/godropbox / BuildValue

Function BuildValue

database/sqltypes/sqltypes.go:215–263  ·  view source on GitHub ↗
(goval interface{})

Source from the content-addressed store, hash-verified

213}
214
215func BuildValue(goval interface{}) (v Value, err error) {
216 switch bindVal := goval.(type) {
217 case nil:
218 // no op
219 case bool:
220 val := 0
221 if bindVal {
222 val = 1
223 }
224 v = Value{Numeric(strconv.AppendInt(nil, int64(val), 10))}
225 case int:
226 v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))}
227 case int32:
228 v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))}
229 case int64:
230 v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))}
231 case uint:
232 v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))}
233 case uint8:
234 v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))}
235 case uint32:
236 v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))}
237 case uint64:
238 v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))}
239 case float64:
240 v = Value{Fractional(strconv.AppendFloat(nil, bindVal, 'f', -1, 64))}
241 case string:
242 v = Value{String{[]byte(bindVal), true}}
243 case []byte:
244 v = Value{String{bindVal, false}}
245 case time.Time:
246 v = Value{String{[]byte(bindVal.Format("2006-01-02 15:04:05.000000")), true}}
247 case Numeric, Fractional, String:
248 v = Value{bindVal.(InnerValue)}
249 case Value:
250 v = bindVal
251 default:
252 // Check if v is a pointer.
253 rv := reflect.ValueOf(goval)
254 if rv.Kind() == reflect.Ptr {
255 if rv.IsNil() {
256 return BuildValue(nil)
257 }
258 return BuildValue(reflect.Indirect(rv).Interface())
259 }
260 return Value{}, errors.Newf("Unsupported bind variable type %T: %v", goval, goval)
261 }
262 return v, nil
263}
264
265// ConverAssignRowNullable is the same as ConvertAssignRow except that it allows
266// nil as a value for the row or any of the row values. In thoses cases, the

Callers 11

LiteralFunction · 0.92
ConvertAssignDefaultFunction · 0.85
Uint64EncodeSqlFunction · 0.85
TestTimeFunction · 0.85
TestStringFunction · 0.85
TestBuildValueMethod · 0.85
TestBuildValuePointerMethod · 0.85
TestConvertAssignDefaultFunction · 0.85
TestConvertAssignRowFunction · 0.85
GenerateMethod · 0.85

Calls 3

NewfFunction · 0.92
NumericTypeAlias · 0.85
FractionalTypeAlias · 0.85

Tested by 8

TestTimeFunction · 0.68
TestStringFunction · 0.68
TestBuildValueMethod · 0.68
TestBuildValuePointerMethod · 0.68
TestConvertAssignDefaultFunction · 0.68
TestConvertAssignRowFunction · 0.68
GenerateMethod · 0.68