MCPcopy Index your code
hub / github.com/cloudspannerecosystem/spanner-cli / Execute

Method Execute

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

Source from the content-addressed store, hash-verified

767}
768
769func (s *ShowIndexStatement) Execute(ctx context.Context, session *Session) (*Result, error) {
770 if session.InReadWriteTransaction() {
771 // INFORMATION_SCHEMA can not be used in read-write transaction.
772 // https://cloud.google.com/spanner/docs/information-schema
773 return nil, errors.New(`"SHOW INDEX" can not be used in a read-write transaction`)
774 }
775
776 stmt := spanner.Statement{
777 SQL: `SELECT
778 TABLE_NAME as Table,
779 PARENT_TABLE_NAME as Parent_table,
780 INDEX_NAME as Index_name,
781 INDEX_TYPE as Index_type,
782 IS_UNIQUE as Is_unique,
783 IS_NULL_FILTERED as Is_null_filtered,
784 INDEX_STATE as Index_state
785FROM
786 INFORMATION_SCHEMA.INDEXES I
787WHERE
788 LOWER(I.TABLE_SCHEMA) = @table_schema AND LOWER(TABLE_NAME) = LOWER(@table_name)`,
789 Params: map[string]interface{}{"table_name": s.Table, "table_schema": s.Schema}}
790
791 iter, _ := session.RunQuery(ctx, stmt)
792 defer iter.Stop()
793
794 rows, columnNames, err := parseQueryResult(iter)
795 if err != nil {
796 return nil, err
797 }
798 if len(rows) == 0 {
799 return nil, fmt.Errorf("table %q doesn't exist in schema %q", s.Table, s.Schema)
800 }
801
802 return &Result{
803 ColumnNames: columnNames,
804 Rows: rows,
805 AffectedRows: len(rows),
806 }, nil
807}
808
809type TruncateTableStatement struct {
810 Table string

Callers

nothing calls this directly

Calls 3

parseQueryResultFunction · 0.85
RunQueryMethod · 0.80

Tested by

no test coverage detected