本文整理匯總了Golang中github.com/pingcap/tidb/meta.Meta.CreateDatabase方法的典型用法代碼示例。如果您正苦於以下問題:Golang Meta.CreateDatabase方法的具體用法?Golang Meta.CreateDatabase怎麽用?Golang Meta.CreateDatabase使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/meta.Meta
的用法示例。
在下文中一共展示了Meta.CreateDatabase方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: onCreateSchema
func (d *ddl) onCreateSchema(t *meta.Meta, job *model.Job) error {
schemaID := job.SchemaID
var name model.CIStr
if err := job.DecodeArgs(&name); err != nil {
// arg error, cancel this job.
job.State = model.JobCancelled
return errors.Trace(err)
}
dbInfo := &model.DBInfo{
ID: schemaID,
Name: name,
State: model.StateNone,
}
dbs, err := t.ListDatabases()
if err != nil {
return errors.Trace(err)
}
for _, db := range dbs {
if db.Name.L == name.L {
if db.ID != schemaID {
// database exists, can't create, we should cancel this job now.
job.State = model.JobCancelled
return errors.Trace(ErrExists)
}
dbInfo = db
}
}
_, err = t.GenSchemaVersion()
if err != nil {
return errors.Trace(err)
}
switch dbInfo.State {
case model.StateNone:
// none -> public
job.SchemaState = model.StatePublic
dbInfo.State = model.StatePublic
err = t.CreateDatabase(dbInfo)
if err != nil {
return errors.Trace(err)
}
// finish this job
job.State = model.JobDone
return nil
default:
// we can't enter here.
return errors.Errorf("invalid db state %v", dbInfo.State)
}
}
示例2: onCreateSchema
func (d *ddl) onCreateSchema(t *meta.Meta, job *model.Job) error {
schemaID := job.SchemaID
dbInfo := &model.DBInfo{}
if err := job.DecodeArgs(dbInfo); err != nil {
// arg error, cancel this job.
job.State = model.JobCancelled
return errors.Trace(err)
}
dbInfo.ID = schemaID
dbInfo.State = model.StateNone
dbs, err := t.ListDatabases()
if err != nil {
return errors.Trace(err)
}
for _, db := range dbs {
if db.Name.L == dbInfo.Name.L {
if db.ID != schemaID {
// database exists, can't create, we should cancel this job now.
job.State = model.JobCancelled
return errors.Trace(infoschema.ErrDatabaseExists)
}
dbInfo = db
}
}
ver, err := updateSchemaVersion(t, job)
if err != nil {
return errors.Trace(err)
}
switch dbInfo.State {
case model.StateNone:
// none -> public
job.SchemaState = model.StatePublic
dbInfo.State = model.StatePublic
err = t.CreateDatabase(dbInfo)
if err != nil {
return errors.Trace(err)
}
// finish this job
job.State = model.JobDone
addDBHistoryInfo(job, ver, dbInfo)
return nil
default:
// we can't enter here.
return errors.Errorf("invalid db state %v", dbInfo.State)
}
}