MCPcopy Create free account
hub / github.com/cloudspannerecosystem/spanner-cli / Execute

Method Execute

statement.go:462–494  ·  view source on GitHub ↗
(ctx context.Context, session *Session)

Source from the content-addressed store, hash-verified

460}
461
462func (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
496func isCreateTableDDL(ddl string, schema string, table string) bool {
497 table = regexp.QuoteMeta(table)

Callers

nothing calls this directly

Calls 2

isCreateTableDDLFunction · 0.85
DatabasePathMethod · 0.80

Tested by

no test coverage detected