コード例 #1
0
ファイル: conn.go プロジェクト: Hellblazer/cockroach
func (c *conn) ShowColumns(p *parser.ShowColumns, args []driver.Value) (*rows, error) {
	desc, err := c.getTableDesc(p.Name)
	if err != nil {
		return nil, err
	}

	schema := structured.TableSchemaFromDesc(*desc)

	// TODO(pmattis): This output doesn't match up with MySQL. Should it?
	r := &rows{
		columns: []string{"Field", "Type", "Null"},
		rows:    make([]row, len(schema.Columns)),
		pos:     -1,
	}

	for i, col := range schema.Columns {
		t := make(row, len(r.columns))
		t[0] = col.Name
		t[1] = col.Type.SQLString()
		t[2] = col.Nullable
		r.rows[i] = t
	}

	return r, nil
}
コード例 #2
0
ファイル: conn.go プロジェクト: Jaekyun/cockroach
func (c *conn) ShowIndex(p *parser.ShowIndex, args []driver.Value) (*rows, error) {
	desc, err := c.getTableDesc(p.Table)
	if err != nil {
		return nil, err
	}

	schema := structured.TableSchemaFromDesc(*desc)

	// TODO(pmattis): This output doesn't match up with MySQL. Should it?
	r := &rows{
		columns: []string{"Table", "Name", "Unique", "Seq", "Column"},
	}
	for _, index := range schema.Indexes {
		for j, col := range index.ColumnNames {
			t := make(row, len(r.columns))
			t[0] = p.Table.Name
			t[1] = index.Name
			t[2] = index.Unique
			t[3] = j + 1
			t[4] = col
			r.rows = append(r.rows, t)
		}
	}

	return r, nil
}
コード例 #3
0
ファイル: table.go プロジェクト: Hellblazer/cockroach
// DescribeTable retrieves the table schema for the specified table. Path has
// the form "<namespace>.<table>".
func (db *DB) DescribeTable(path string) (*structured.TableSchema, error) {
	desc, err := db.getTableDesc(path)
	if err != nil {
		return nil, err
	}
	schema := structured.TableSchemaFromDesc(*desc)
	return &schema, nil
}