本文整理汇总了Golang中github.com/youtube/vitess/go/sqltypes.Value.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.String方法的具体用法?Golang Value.String怎么用?Golang Value.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/sqltypes.Value
的用法示例。
在下文中一共展示了Value.String方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateLastChange
func (si *SchemaInfo) updateLastChange(createTime sqltypes.Value) {
if createTime.IsNull() {
return
}
t, err := strconv.ParseInt(createTime.String(), 10, 64)
if err != nil {
relog.Warning("Could not parse time %s: %v", createTime.String(), err)
return
}
if si.lastChange.Unix() < t {
si.lastChange = time.Unix(t, 0)
}
}
示例2: Convert
// Convert takes a type and a value, and returns the type:
// - nil for NULL value
// - int64 for integer number types that fit in 64 bits
// (signed or unsigned are all converted to signed)
// - float64 for floating point values that fit in a float
// - []byte for everything else
func Convert(mysqlType int64, val sqltypes.Value) (interface{}, error) {
if val.IsNull() {
return nil, nil
}
switch mysqlType {
case VT_TINY, VT_SHORT, VT_LONG, VT_LONGLONG, VT_INT24:
return strconv.ParseInt(val.String(), 0, 64)
case VT_FLOAT, VT_DOUBLE:
return strconv.ParseFloat(val.String(), 64)
}
return val.Raw(), nil
}
示例3: computePrefix
func (ti *TableInfo) computePrefix(conn PoolConnection, createTime sqltypes.Value, hashRegistry map[string]string) string {
if createTime.IsNull() {
relog.Warning("%s has no time stamp. Will not be cached.", ti.Name)
return ""
}
createTable, err := conn.ExecuteFetch(fmt.Sprintf("show create table %s", ti.Name), 10000, false)
if err != nil {
relog.Warning("Couldnt read table info: %v", err)
return ""
}
// Normalize & remove auto_increment because it changes on every insert
norm1 := strings.ToLower(createTable.Rows[0][1].String())
norm2 := autoIncr.ReplaceAllLiteralString(norm1, "")
thash := base64fnv(norm2 + createTime.String())
if _, ok := hashRegistry[thash]; ok {
relog.Warning("Hash collision for %s (schema revert?). Will not be cached", ti.Name)
return ""
}
hashRegistry[thash] = ti.Name
return thash
}
示例4: Convert
// Convert takes a type and a value, and returns the type:
// - nil for NULL value
// - uint64 for unsigned BIGINT values
// - int64 for all other integer values (signed and unsigned)
// - float64 for floating point values that fit in a float
// - []byte for everything else
func Convert(field *querypb.Field, val sqltypes.Value) (interface{}, error) {
if field.Type == sqltypes.Null {
return nil, nil
} else if sqltypes.IsSigned(field.Type) {
return strconv.ParseInt(val.String(), 0, 64)
} else if sqltypes.IsUnsigned(field.Type) {
return strconv.ParseUint(val.String(), 0, 64)
} else if sqltypes.IsFloat(field.Type) {
return strconv.ParseFloat(val.String(), 64)
}
return val.Raw(), nil
}
示例5: Convert
// Convert takes a type and a value, and returns the type:
// - nil for NULL value
// - uint64 for unsigned BIGINT values
// - int64 for all other integer values (signed and unsigned)
// - float64 for floating point values that fit in a float
// - []byte for everything else
func Convert(field Field, val sqltypes.Value) (interface{}, error) {
if val.IsNull() {
return nil, nil
}
switch field.Type {
case VT_LONGLONG:
if field.Flags&VT_UNSIGNED_FLAG == VT_UNSIGNED_FLAG {
return strconv.ParseUint(val.String(), 0, 64)
}
return strconv.ParseInt(val.String(), 0, 64)
case VT_TINY, VT_SHORT, VT_LONG, VT_INT24:
// Regardless of whether UNSIGNED_FLAG is set in field.Flags, we map all
// signed and unsigned values to a signed Go type because
// - Go doesn't officially support uint64 in their SQL interface
// - there is no loss of the value
// The only exception we make are for unsigned BIGINTs, see VT_LONGLONG above.
return strconv.ParseInt(val.String(), 0, 64)
case VT_FLOAT, VT_DOUBLE:
return strconv.ParseFloat(val.String(), 64)
}
return val.Raw(), nil
}