// AlterTableCharset changes the table charset and collate.
164872
func (d *ddl) AlterTableCharsetAndCollate(ctx sessionctx.Context, ident ast.Ident, toCharset, toCollate string) error {
	// use the last one.
	if toCharset == "" && toCollate == "" {
		return ErrUnknownCharacterSet.GenWithStackByArgs(toCharset)
	}

	is := d.infoHandle.Get()
	schema, ok := is.SchemaByName(ident.Schema)
	if !ok {
		return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ident.Schema)
	}

	tb, err := is.TableByName(ident.Schema, ident.Name)
	if err != nil {
		return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ident.Schema, ident.Name))
	}

	if toCharset == "" {
		// charset does not change.
		toCharset = tb.Meta().Charset
	}

	if toCollate == "" {
		// get the default collation of the charset.
		toCollate, err = charset.GetDefaultCollation(toCharset)
		if err != nil {
			return errors.Trace(err)
		}
	}
	doNothing, err := checkAlterTableCharset(tb.Meta(), schema, toCharset, toCollate)
	if err != nil {
		return err
	}
	if doNothing {
		return nil
	}

	job := &model.Job{
		SchemaID:   schema.ID,
		TableID:    tb.Meta().ID,
		Type:       model.ActionModifyTableCharsetAndCollate,
		BinlogInfo: &model.HistoryInfo{},
		Args:       []interface{}{toCharset, toCollate},
	}
	err = d.doDDLJob(ctx, job)
	err = d.callHookOnChanged(err)
	return errors.Trace(err)
}
602296
func (s *CreateRegexPatternSetOutput) SetRegexPatternSet(v *RegexPatternSet) *CreateRegexPatternSetOutput {
	s.RegexPatternSet = v
	return s
}
211176
func (co *ChangeOption) UnmarshalText(b []byte) error {
	s := strings.ToLower(strings.Trim(string(b), `"`))
	switch s {
	case strings.ToLower(string(RestartAllOnInstanceChanged)), strings.ToLower(string(RestartAllOnInstanceZeroDown)):
		*co = ChangeOption(s)
	case "":
		*co = DefaultChangeOption
	default:
		return errors.New("Invalid ChangeOption: " + s)
	}
	return nil
}
182854
func parseFormatChartSet(formatSet string) (*formatChart, error) {
	format := formatChart{
		Dimension: formatChartDimension{
			Width:  480,
			Height: 290,
		},
		Format: formatPicture{
			FPrintsWithSheet: true,
			FLocksWithSheet:  false,
			NoChangeAspect:   false,
			OffsetX:          0,
			OffsetY:          0,
			XScale:           1.0,
			YScale:           1.0,
		},
		Legend: formatChartLegend{
			Position:      "bottom",
			ShowLegendKey: false,
		},
		Title: formatChartTitle{
			Name: " ",
		},
		ShowBlanksAs: "gap",
	}
	err := json.Unmarshal([]byte(formatSet), &format)
	return &format, err
}
134860
func modifiableCharsetAndCollation(toCharset, toCollate, origCharset, origCollate string) error {
	if !charset.ValidCharsetAndCollation(toCharset, toCollate) {
		return ErrUnknownCharacterSet.GenWithStack("Unknown character set: '%s', collation: '%s'", toCharset, toCollate)
	}
	if toCharset == charset.CharsetUTF8MB4 && origCharset == charset.CharsetUTF8 {
		// TiDB only allow utf8 to be changed to utf8mb4.
		return nil
	}

	if toCharset != origCharset {
		msg := fmt.Sprintf("charset from %s to %s", origCharset, toCharset)
		return errUnsupportedModifyCharset.GenWithStackByArgs(msg)
	}
	if toCollate != origCollate {
		msg := fmt.Sprintf("collate from %s to %s", origCollate, toCollate)
		return errUnsupportedModifyCharset.GenWithStackByArgs(msg)
	}
	return nil
}
727563
func (fhc *FakeHealthCheck) ReplaceTablet(old, new *topodatapb.Tablet, name string) {
	fhc.RemoveTablet(old)
	fhc.AddTablet(new, name)
}
1280342
func (b *SqliteBuilder) AlterColumn(table, col, typ string) *Query {
	q := b.NewQuery("")
	q.LastError = errors.New("SQLite does not support altering column")
	return q
}
190932
func (ctx *ProxyCtx) Charset() string {
	charsets := charsetFinder.FindStringSubmatch(ctx.Resp.Header.Get("Content-Type"))
	if charsets == nil {
		return ""
	}
	return charsets[1]
}
81163
func RegisterCharset(cs *Charset) {
	name := cs.Name
	charsets[name] = cs
	aliases[simplifyName(name)] = name
	for _, alias := range cs.Aliases {
		aliases[simplifyName(alias)] = name
	}
}
394394
func (fbs *FilterByShard) ReplaceTablet(old, new *topodatapb.Tablet, name string) {
	if fbs.isIncluded(old) && fbs.isIncluded(new) {
		fbs.tr.ReplaceTablet(old, new, name)
	}
}
1216980
func (l *Logger) SetFormat(v string) {
	switch v {
	case "text":
		l.Formatter = &logrus.TextFormatter{}
	case "json":
		l.Formatter = &logrus.JSONFormatter{}
	}
}
886188
func (s *QueryCompileErrorLocation) SetEndCharOffset(v int64) *QueryCompileErrorLocation {
	s.EndCharOffset = &v
	return s
}
983213
func (s *DBEngineVersion) SetDefaultCharacterSet(v *CharacterSet) *DBEngineVersion {
	s.DefaultCharacterSet = v
	return s
}
240946
func (s *ContentTypeProfile) SetFormat(v string) *ContentTypeProfile {
	s.Format = &v
	return s
}
267939
func (s *Type) SetFormat(v string) *Type {
	s.Format = &v
	return s
}
155882
func readLocalCharsets() {
	csdata, err := readFile("charsets.json")
	if err != nil {
		fmt.Fprintf(os.Stderr, "charset: cannot open \"charsets.json\": %v\n", err)
		return
	}

	var entries map[string]charsetEntry
	err = json.Unmarshal(csdata, &entries)
	if err != nil {
		fmt.Fprintf(os.Stderr, "charset: cannot decode config file: %v\n", err)
	}
	for name, e := range entries {
		class := classes[e.Class]
		if class == nil {
			continue
		}
		name = NormalizedName(name)
		for i, a := range e.Aliases {
			e.Aliases[i] = NormalizedName(a)
		}
		cs := &localCharset{
			Charset: Charset{
				Name:    name,
				Aliases: e.Aliases,
				Desc:    e.Desc,
				NoFrom:  class.from == nil,
				NoTo:    class.to == nil,
			},
			arg:   e.Arg,
			class: class,
		}
		localCharsets[cs.Name] = cs
		for _, a := range cs.Aliases {
			localCharsets[a] = cs
		}
	}
}
945783
func parseFormatTableSet(formatSet string) (*formatTable, error) {
	format := formatTable{
		TableStyle:     "",
		ShowRowStripes: true,
	}
	err := json.Unmarshal(parseFormatSet(formatSet), &format)
	return &format, err
}