本文整理汇总了Golang中github.com/cockroachdb/cockroach/sql/parser.PlaceholderInfo.SetType方法的典型用法代码示例。如果您正苦于以下问题:Golang PlaceholderInfo.SetType方法的具体用法?Golang PlaceholderInfo.SetType怎么用?Golang PlaceholderInfo.SetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/sql/parser.PlaceholderInfo
的用法示例。
在下文中一共展示了PlaceholderInfo.SetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CheckColumnType
// CheckColumnType verifies that a given value is compatible
// with the type requested by the column. If the value is a
// placeholder, the type of the placeholder gets populated.
func CheckColumnType(col ColumnDescriptor, val parser.Datum, pmap *parser.PlaceholderInfo) error {
if val == parser.DNull {
return nil
}
var ok bool
var set parser.Datum
switch col.Type.Kind {
case ColumnType_BOOL:
_, ok = val.(*parser.DBool)
set = parser.TypeBool
case ColumnType_INT:
_, ok = val.(*parser.DInt)
set = parser.TypeInt
case ColumnType_FLOAT:
_, ok = val.(*parser.DFloat)
set = parser.TypeFloat
case ColumnType_DECIMAL:
_, ok = val.(*parser.DDecimal)
set = parser.TypeDecimal
case ColumnType_STRING:
_, ok = val.(*parser.DString)
set = parser.TypeString
case ColumnType_BYTES:
_, ok = val.(*parser.DBytes)
if !ok {
_, ok = val.(*parser.DString)
}
set = parser.TypeBytes
case ColumnType_DATE:
_, ok = val.(*parser.DDate)
set = parser.TypeDate
case ColumnType_TIMESTAMP:
_, ok = val.(*parser.DTimestamp)
set = parser.TypeTimestamp
case ColumnType_TIMESTAMPTZ:
_, ok = val.(*parser.DTimestampTZ)
set = parser.TypeTimestampTZ
case ColumnType_INTERVAL:
_, ok = val.(*parser.DInterval)
set = parser.TypeInterval
default:
return errors.Errorf("unsupported column type: %s", col.Type.Kind)
}
// If the value is a placeholder, then the column check above has
// populated 'set' with a type to assign to it.
if d, dok := val.(*parser.DPlaceholder); dok {
if err := pmap.SetType(d.Name(), set); err != nil {
return fmt.Errorf("cannot infer type for placeholder %s from column %q: %s",
d.Name(), col.Name, err)
}
} else {
// Not a placeholder; check that the value cast has succeeded.
if !ok && set == nil {
return fmt.Errorf("value type %s doesn't match type %s of column %q",
val.Type(), col.Type.Kind, col.Name)
}
}
return nil
}