本文整理汇总了Golang中github.com/pingcap/tidb/model.FKInfo.ID方法的典型用法代码示例。如果您正苦于以下问题:Golang FKInfo.ID方法的具体用法?Golang FKInfo.ID怎么用?Golang FKInfo.ID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/model.FKInfo
的用法示例。
在下文中一共展示了FKInfo.ID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: buildFKInfo
func (d *ddl) buildFKInfo(fkName model.CIStr, keys []*ast.IndexColName, refer *ast.ReferenceDef) (*model.FKInfo, error) {
fkID, err := d.genGlobalID()
if err != nil {
return nil, errors.Trace(err)
}
var fkInfo model.FKInfo
fkInfo.ID = fkID
fkInfo.Name = fkName
fkInfo.RefTable = refer.Table.Name
fkInfo.Cols = make([]model.CIStr, len(keys))
for i, key := range keys {
fkInfo.Cols[i] = key.Column.Name
}
fkInfo.RefCols = make([]model.CIStr, len(refer.IndexColNames))
for i, key := range refer.IndexColNames {
fkInfo.RefCols[i] = key.Column.Name
}
fkInfo.OnDelete = int(refer.OnDelete.ReferOpt)
fkInfo.OnUpdate = int(refer.OnUpdate.ReferOpt)
return &fkInfo, nil
}
示例2: onCreateForeignKey
func (d *ddl) onCreateForeignKey(t *meta.Meta, job *model.Job) error {
schemaID := job.SchemaID
tblInfo, err := d.getTableInfo(t, job)
if err != nil {
return errors.Trace(err)
}
var fkInfo model.FKInfo
err = job.DecodeArgs(&fkInfo)
if err != nil {
job.State = model.JobCancelled
return errors.Trace(err)
}
fkInfo.ID = allocateIndexID(tblInfo)
tblInfo.ForeignKeys = append(tblInfo.ForeignKeys, &fkInfo)
ver, err := updateSchemaVersion(t, job)
if err != nil {
return errors.Trace(err)
}
switch fkInfo.State {
case model.StateNone:
// We just support record the foreign key, so we just make it public.
// none -> public
job.SchemaState = model.StatePublic
fkInfo.State = model.StatePublic
err = t.UpdateTable(schemaID, tblInfo)
if err != nil {
return errors.Trace(err)
}
// Finish this job.
job.State = model.JobDone
addTableHistoryInfo(job, ver, tblInfo)
return nil
default:
return ErrInvalidForeignKeyState.Gen("invalid fk state %v", fkInfo.State)
}
}