(ctx context.Context, session *Session)
| 460 | } |
| 461 | |
| 462 | func (s *ShowCreateTableStatement) Execute(ctx context.Context, session *Session) (*Result, error) { |
| 463 | result := &Result{ColumnNames: []string{"Table", "Create Table"}} |
| 464 | |
| 465 | ddlResponse, err := session.adminClient.GetDatabaseDdl(ctx, &adminpb.GetDatabaseDdlRequest{ |
| 466 | Database: session.DatabasePath(), |
| 467 | }) |
| 468 | if err != nil { |
| 469 | return nil, err |
| 470 | } |
| 471 | for _, stmt := range ddlResponse.Statements { |
| 472 | if isCreateTableDDL(stmt, s.Schema, s.Table) { |
| 473 | var fqn string |
| 474 | if s.Schema == "" { |
| 475 | fqn = s.Table |
| 476 | } else { |
| 477 | fqn = fmt.Sprintf("%s.%s", s.Schema, s.Table) |
| 478 | } |
| 479 | |
| 480 | resultRow := Row{ |
| 481 | Columns: []string{fqn, stmt}, |
| 482 | } |
| 483 | result.Rows = append(result.Rows, resultRow) |
| 484 | break |
| 485 | } |
| 486 | } |
| 487 | if len(result.Rows) == 0 { |
| 488 | return nil, fmt.Errorf("table %q doesn't exist in schema %q", s.Table, s.Schema) |
| 489 | } |
| 490 | |
| 491 | result.AffectedRows = len(result.Rows) |
| 492 | |
| 493 | return result, nil |
| 494 | } |
| 495 | |
| 496 | func isCreateTableDDL(ddl string, schema string, table string) bool { |
| 497 | table = regexp.QuoteMeta(table) |
nothing calls this directly
no test coverage detected