func (s *ShowPlan) fetchShowGrants(ctx context.Context) error { // Get checker checker := privilege.GetPrivilegeChecker(ctx) if checker == nil { return errors.New("Miss privilege checker!") } gs, err := checker.ShowGrants(ctx, s.User) if err != nil { return errors.Trace(err) } for _, g := range gs { data := []interface{}{g} s.rows = append(s.rows, &plan.Row{Data: data}) } return nil }
func (e *ShowExec) fetchShowGrants() error { // Get checker checker := privilege.GetPrivilegeChecker(e.ctx) if checker == nil { return errors.New("Miss privilege checker!") } gs, err := checker.ShowGrants(e.ctx, e.User) if err != nil { return errors.Trace(err) } for _, g := range gs { data := types.MakeDatums(g) e.rows = append(e.rows, &Row{Data: data}) } return nil }
// Exec implements the stmt.Statement Exec interface. func (s *DropTableStmt) Exec(ctx context.Context) (rset.Recordset, error) { var notExistTables []string is := sessionctx.GetDomain(ctx).InfoSchema() for _, ti := range s.TableIdents { fullti := ti.Full(ctx) schema, ok := is.SchemaByName(fullti.Schema) if !ok { // TODO: we should return special error for table not exist, checking "not exist" is not enough, // because some other errors may contain this error string too. notExistTables = append(notExistTables, ti.String()) continue } tb, err := is.TableByName(fullti.Schema, fullti.Name) if err != nil && strings.HasSuffix(err.Error(), "not exist") { notExistTables = append(notExistTables, ti.String()) continue } else if err != nil { return nil, errors.Trace(err) } // Check Privilege privChecker := privilege.GetPrivilegeChecker(ctx) hasPriv, err := privChecker.Check(ctx, schema, tb.Meta(), mysql.DropPriv) if err != nil { return nil, errors.Trace(err) } if !hasPriv { return nil, errors.Errorf("You do not have the privilege to drop table %s.%s.", ti.Schema, ti.Name) } err = sessionctx.GetDomain(ctx).DDL().DropTable(ctx, fullti) if terror.ErrorEqual(err, ddl.ErrNotExists) || terror.DatabaseNotExists.Equal(err) { notExistTables = append(notExistTables, ti.String()) } else if err != nil { return nil, errors.Trace(err) } } if len(notExistTables) > 0 && !s.IfExists { return nil, errors.Errorf("DROP TABLE: table %s does not exist", strings.Join(notExistTables, ",")) } return nil, nil }
func (e *DDLExec) executeDropTable(s *ast.DropTableStmt) error { var notExistTables []string for _, tn := range s.Tables { fullti := ast.Ident{Schema: tn.Schema, Name: tn.Name} schema, ok := e.is.SchemaByName(tn.Schema) if !ok { // TODO: we should return special error for table not exist, checking "not exist" is not enough, // because some other errors may contain this error string too. notExistTables = append(notExistTables, fullti.String()) continue } tb, err := e.is.TableByName(tn.Schema, tn.Name) if err != nil && strings.HasSuffix(err.Error(), "not exist") { notExistTables = append(notExistTables, fullti.String()) continue } else if err != nil { return errors.Trace(err) } // Check Privilege privChecker := privilege.GetPrivilegeChecker(e.ctx) hasPriv, err := privChecker.Check(e.ctx, schema, tb.Meta(), mysql.DropPriv) if err != nil { return errors.Trace(err) } if !hasPriv { return errors.Errorf("You do not have the privilege to drop table %s.%s.", tn.Schema, tn.Name) } err = sessionctx.GetDomain(e.ctx).DDL().DropTable(e.ctx, fullti) if infoschema.ErrDatabaseNotExists.Equal(err) || infoschema.ErrTableNotExists.Equal(err) { notExistTables = append(notExistTables, fullti.String()) } else if err != nil { return errors.Trace(err) } } if len(notExistTables) > 0 && !s.IfExists { return infoschema.ErrTableDropExists.Gen("DROP TABLE: table %s does not exist", strings.Join(notExistTables, ",")) } return nil }
// DropTable will proceed even if some table in the list does not exists. func (d *ddl) DropTable(ctx context.Context, ti table.Ident) (err error) { is := d.GetInformationSchema() schema, ok := is.SchemaByName(ti.Schema) if !ok { return terror.DatabaseNotExists.Gen("database %s not exists", ti.Schema) } tb, err := is.TableByName(ti.Schema, ti.Name) if err != nil { return errors.Trace(err) } // Check Privilege privChecker := privilege.GetPrivilegeChecker(ctx) hasPriv, err := privChecker.Check(ctx, schema, tb.Meta(), mysql.DropPriv) if err != nil { return errors.Trace(err) } if !hasPriv { return errors.Errorf("You do not have the privilege to drop table %s.%s.", ti.Schema, ti.Name) } err = kv.RunInNewTxn(d.store, false, func(txn kv.Transaction) error { t := meta.NewMeta(txn) err := d.verifySchemaMetaVersion(t, is.SchemaMetaVersion()) if err != nil { return errors.Trace(err) } err = t.DropTable(schema.ID, tb.Meta().ID) return errors.Trace(err) }) if d.onDDLChange != nil { err = d.onDDLChange(err) if err != nil { return errors.Trace(err) } } err = d.deleteTableData(ctx, tb) return errors.Trace(err) }