本文整理匯總了Golang中github.com/pingcap/tidb/table.Table.AllocAutoID方法的典型用法代碼示例。如果您正苦於以下問題:Golang Table.AllocAutoID方法的具體用法?Golang Table.AllocAutoID怎麽用?Golang Table.AllocAutoID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/table.Table
的用法示例。
在下文中一共展示了Table.AllocAutoID方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: initDefaultValues
func (s *InsertValues) initDefaultValues(ctx context.Context, t table.Table, row []interface{}, marked map[int]struct{}) error {
var defaultValueCols []*column.Col
for i, c := range t.Cols() {
if row[i] != nil {
// Column value is not nil, continue.
continue
}
// If the nil value is evaluated in insert list, we will use nil except auto increment column.
if _, ok := marked[i]; ok && !mysql.HasAutoIncrementFlag(c.Flag) && !mysql.HasTimestampFlag(c.Flag) {
continue
}
if mysql.HasAutoIncrementFlag(c.Flag) {
recordID, err := t.AllocAutoID()
if err != nil {
return errors.Trace(err)
}
row[i] = recordID
if c.IsPKHandleColumn(t.Meta()) {
// Notes: incompatible with mysql
// MySQL will set last insert id to the first row, as follows:
// `t(id int AUTO_INCREMENT, c1 int, PRIMARY KEY (id))`
// `insert t (c1) values(1),(2),(3);`
// Last insert id will be 1, not 3.
variable.GetSessionVars(ctx).SetLastInsertID(uint64(recordID))
}
} else {
var value interface{}
value, _, err := tables.GetColDefaultValue(ctx, &c.ColumnInfo)
if err != nil {
return errors.Trace(err)
}
row[i] = value
}
defaultValueCols = append(defaultValueCols, c)
}
if err := column.CastValues(ctx, row, defaultValueCols); err != nil {
return errors.Trace(err)
}
return nil
}
示例2: initDefaultValues
func (s *InsertValues) initDefaultValues(ctx context.Context, t table.Table, row []interface{}, marked map[int]struct{}) error {
var err error
var defaultValueCols []*column.Col
for i, c := range t.Cols() {
if row[i] != nil {
// Column value is not nil, continue.
continue
}
// If the nil value is evaluated in insert list, we will use nil except auto increment column.
if _, ok := marked[i]; ok && !mysql.HasAutoIncrementFlag(c.Flag) && !mysql.HasTimestampFlag(c.Flag) {
continue
}
if mysql.HasAutoIncrementFlag(c.Flag) {
var id int64
if id, err = t.AllocAutoID(); err != nil {
return errors.Trace(err)
}
row[i] = id
variable.GetSessionVars(ctx).SetLastInsertID(uint64(id))
} else {
var value interface{}
value, _, err = getDefaultValue(ctx, c)
if err != nil {
return errors.Trace(err)
}
row[i] = value
}
defaultValueCols = append(defaultValueCols, c)
}
if err = column.CastValues(ctx, row, defaultValueCols); err != nil {
return errors.Trace(err)
}
return nil
}
示例3: initDefaultValues
func (s *InsertValues) initDefaultValues(ctx context.Context, t table.Table, row []interface{}, marked map[int]struct{}) (recordID int64, err error) {
var defaultValueCols []*column.Col
for i, c := range t.Cols() {
if row[i] != nil {
// Column value is not nil, continue.
continue
}
// If the nil value is evaluated in insert list, we will use nil except auto increment column.
if _, ok := marked[i]; ok && !mysql.HasAutoIncrementFlag(c.Flag) && !mysql.HasTimestampFlag(c.Flag) {
continue
}
if mysql.HasAutoIncrementFlag(c.Flag) {
if recordID, err = t.AllocAutoID(); err != nil {
return 0, errors.Trace(err)
}
row[i] = recordID
} else {
var value interface{}
value, _, err = tables.GetColDefaultValue(ctx, &c.ColumnInfo)
if err != nil {
return 0, errors.Trace(err)
}
row[i] = value
}
defaultValueCols = append(defaultValueCols, c)
}
if err = column.CastValues(ctx, row, defaultValueCols); err != nil {
return 0, errors.Trace(err)
}
return
}