(ctx sessionctx.Context, s *ast.CreateViewStmt)
| 1473 | } |
| 1474 | |
| 1475 | func (e *executor) CreateView(ctx sessionctx.Context, s *ast.CreateViewStmt) (err error) { |
| 1476 | viewInfo, err := BuildViewInfo(s) |
| 1477 | if err != nil { |
| 1478 | return err |
| 1479 | } |
| 1480 | |
| 1481 | cols := make([]*table.Column, len(s.Cols)) |
| 1482 | for i, v := range s.Cols { |
| 1483 | cols[i] = table.ToColumn(&model.ColumnInfo{ |
| 1484 | Name: v, |
| 1485 | ID: int64(i), |
| 1486 | Offset: i, |
| 1487 | State: model.StatePublic, |
| 1488 | }) |
| 1489 | } |
| 1490 | |
| 1491 | tblCharset := "" |
| 1492 | tblCollate := "" |
| 1493 | if v, ok := ctx.GetSessionVars().GetSystemVar(variable.CharacterSetConnection); ok { |
| 1494 | tblCharset = v |
| 1495 | } |
| 1496 | if v, ok := ctx.GetSessionVars().GetSystemVar(variable.CollationConnection); ok { |
| 1497 | tblCollate = v |
| 1498 | } |
| 1499 | |
| 1500 | tbInfo, err := BuildTableInfo(NewMetaBuildContextWithSctx(ctx), s.ViewName.Name, cols, nil, tblCharset, tblCollate) |
| 1501 | if err != nil { |
| 1502 | return err |
| 1503 | } |
| 1504 | tbInfo.View = viewInfo |
| 1505 | |
| 1506 | onExist := OnExistError |
| 1507 | if s.OrReplace { |
| 1508 | onExist = OnExistReplace |
| 1509 | } |
| 1510 | |
| 1511 | return e.CreateTableWithInfo(ctx, s.ViewName.Schema, tbInfo, nil, WithOnExist(onExist)) |
| 1512 | } |
| 1513 | |
| 1514 | func checkCharsetAndCollation(cs string, co string) error { |
| 1515 | if !charset.ValidCharsetAndCollation(cs, co) { |
nothing calls this directly
no test coverage detected