本文整理汇总了Golang中github.com/pingcap/tidb/column.Col类的典型用法代码示例。如果您正苦于以下问题:Golang Col类的具体用法?Golang Col怎么用?Golang Col使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Col类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setTimestampDefaultValue
func setTimestampDefaultValue(c *column.Col, hasDefaultValue bool, setOnUpdateNow bool) {
if hasDefaultValue {
return
}
// For timestamp Col, if is not set default value or not set null, use current timestamp.
if mysql.HasTimestampFlag(c.Flag) && mysql.HasNotNullFlag(c.Flag) {
if setOnUpdateNow {
c.DefaultValue = expressions.ZeroTimestamp
} else {
c.DefaultValue = expressions.CurrentTimestamp
}
}
}
示例2: removeOnUpdateNowFlag
func removeOnUpdateNowFlag(c *column.Col) {
// For timestamp Col, if it is set null or default value,
// OnUpdateNowFlag should be removed.
if mysql.HasTimestampFlag(c.Flag) {
c.Flag &= ^uint(mysql.OnUpdateNowFlag)
}
}
示例3: setNoDefaultValueFlag
func setNoDefaultValueFlag(c *column.Col, hasDefaultValue bool) {
if hasDefaultValue {
return
}
if !mysql.HasNotNullFlag(c.Flag) {
return
}
// Check if it is an `AUTO_INCREMENT` field or `TIMESTAMP` field.
if !mysql.HasAutoIncrementFlag(c.Flag) && !mysql.HasTimestampFlag(c.Flag) {
c.Flag |= mysql.NoDefaultValueFlag
}
}
示例4: TestMain
func (*testResultFieldSuite) TestMain(c *C) {
col := column.Col{
ColumnInfo: model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeLong),
Name: model.NewCIStr("c1"),
},
}
col.Flag |= mysql.UnsignedFlag
r := &field.ResultField{
Col: col,
Name: "c1",
OrgTableName: "t1",
}
c.Assert(r.String(), Equals, "c1")
r.TableName = "a"
c.Assert(r.String(), Equals, "a.c1")
r.DBName = "test"
c.Assert(r.String(), Equals, "test.a.c1")
cr := r.Clone()
c.Assert(r.String(), Equals, cr.String())
col1 := column.Col{
ColumnInfo: model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeLong),
Name: model.NewCIStr("c2"),
},
}
col1.Flag |= mysql.UnsignedFlag
r1 := &field.ResultField{
Col: col1,
Name: "c2",
TableName: "a",
OrgTableName: "t1",
DBName: "test",
}
rs := []*field.ResultField{r, r1}
ns := field.RFQNames(rs)
c.Assert(ns, HasLen, 2)
c.Assert(ns[0], Equals, "\"c1\"")
c.Assert(ns[1], Equals, "\"c2\"")
col2 := column.Col{
ColumnInfo: model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeVarchar),
Name: model.NewCIStr("c3"),
},
}
col2.Flag |= mysql.UnsignedFlag
col3 := column.Col{
ColumnInfo: model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeBlob),
Name: model.NewCIStr("c4"),
},
}
col3.Flag |= mysql.UnsignedFlag
cols := []*column.Col{&col, &col1, &col2, &col3}
rs = field.ColsToResultFields(cols, "t")
c.Assert(rs, HasLen, 4)
c.Assert(rs[2].Tp, Equals, mysql.TypeVarString)
c.Assert(rs[3].Tp, Equals, mysql.TypeBlob)
// For CheckAmbiguousField
err := field.CheckAmbiguousField("c1", rs, field.OrgFieldNameFlag)
c.Assert(err, IsNil)
col4 := column.Col{
ColumnInfo: model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeVarchar),
Name: model.NewCIStr("c2"),
},
}
r2 := &field.ResultField{
Col: col4,
Name: "c22",
TableName: "b",
OrgTableName: "t2",
DBName: "test",
}
rs = []*field.ResultField{r, r1, r2}
// r1 and r2 are ambiguous: same column name but different table names
err = field.CheckAmbiguousField("c2", rs, field.OrgFieldNameFlag)
c.Assert(err, NotNil)
// r1 and r2 with different alias name
err = field.CheckAmbiguousField("c2", rs, field.FieldNameFlag)
c.Assert(err, IsNil)
// For CloneFieldByName
_, err = field.CloneFieldByName("cx", rs, field.OrgFieldNameFlag)
c.Assert(err, NotNil)
_, err = field.CloneFieldByName("c2", rs, field.OrgFieldNameFlag)
c.Assert(err, IsNil)
// For check all fields name
names := []string{"cx"}
//.........这里部分代码省略.........
示例5: TestMain
func (*testResultFieldSuite) TestMain(c *C) {
col := column.Col{
ColumnInfo: model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeLong),
Name: model.NewCIStr("c1"),
},
}
col.Flag |= mysql.UnsignedFlag
r := &field.ResultField{
Col: col,
Name: "c1",
OrgTableName: "t1",
}
c.Assert(r.String(), Equals, "c1")
r.TableName = "a"
c.Assert(r.String(), Equals, "a.c1")
r.DBName = "test"
c.Assert(r.String(), Equals, "test.a.c1")
cr := r.Clone()
c.Assert(r.String(), Equals, cr.String())
col1 := column.Col{
ColumnInfo: model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeLong),
Name: model.NewCIStr("c2"),
},
}
col1.Flag |= mysql.UnsignedFlag
r1 := &field.ResultField{
Col: col1,
Name: "c2",
TableName: "a",
OrgTableName: "t1",
DBName: "test",
}
rs := []*field.ResultField{r, r1}
ns := field.RFQNames(rs)
c.Assert(ns, HasLen, 2)
c.Assert(ns[0], Equals, "\"c1\"")
c.Assert(ns[1], Equals, "\"c2\"")
col2 := column.Col{
ColumnInfo: model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeVarchar),
Name: model.NewCIStr("c3"),
},
}
col2.Flag |= mysql.UnsignedFlag
col3 := column.Col{
ColumnInfo: model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeBlob),
Name: model.NewCIStr("c4"),
},
}
col3.Flag |= mysql.UnsignedFlag
cols := []*column.Col{&col, &col1, &col2, &col3}
rs = field.ColsToResultFields(cols, "t")
c.Assert(rs, HasLen, 4)
c.Assert(rs[2].Tp, Equals, mysql.TypeVarString)
c.Assert(rs[3].Tp, Equals, mysql.TypeBlob)
col4 := column.Col{
ColumnInfo: model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeVarchar),
Name: model.NewCIStr("c2"),
},
}
r2 := &field.ResultField{
Col: col4,
Name: "c22",
TableName: "b",
OrgTableName: "t2",
DBName: "test",
}
rs = []*field.ResultField{r, r1, r2}
// For CloneFieldByName
_, err := field.CloneFieldByName("cx", rs)
c.Assert(err, NotNil)
_, err = field.CloneFieldByName("c2", rs)
c.Assert(err, IsNil)
// For ContainAllFieldNames
names := []string{"cx", "c2"}
b := field.ContainAllFieldNames(names, rs)
c.Assert(b, IsFalse)
names = []string{"c2", "c1"}
b = field.ContainAllFieldNames(names, rs)
c.Assert(b, IsTrue)
}