本文整理汇总了Golang中github.com/cockroachdb/cockroach/sql/parser.ShowTables类的典型用法代码示例。如果您正苦于以下问题:Golang ShowTables类的具体用法?Golang ShowTables怎么用?Golang ShowTables使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ShowTables类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ShowTables
// ShowTables returns all the tables.
// Privileges: None.
// Notes: postgres does not have a SHOW TABLES statement.
// mysql only returns tables you have privileges on.
func (p *planner) ShowTables(n *parser.ShowTables) (planNode, error) {
// TODO(pmattis): This could be implemented as:
//
// SELECT name FROM system.namespace
// WHERE parentID = (SELECT id FROM system.namespace
// WHERE parentID = 0 AND name = <database>)
if n.Name == nil {
if p.session.Database == "" {
return nil, errNoDatabase
}
n.Name = &parser.QualifiedName{Base: parser.Name(p.session.Database)}
}
dbDesc, err := p.getDatabaseDesc(string(n.Name.Base))
if err != nil {
return nil, err
}
tableNames, err := p.getTableNames(dbDesc)
if err != nil {
return nil, err
}
v := &valuesNode{columns: []string{"Table"}}
for _, name := range tableNames {
v.rows = append(v.rows, []parser.Datum{parser.DString(name.Table())})
}
return v, nil
}
示例2: ShowTables
// ShowTables returns all the tables.
func (s *Server) ShowTables(session *Session, p *parser.ShowTables, args []sqlwire.Datum, resp *sqlwire.Response) error {
if p.Name == nil {
if session.Database == "" {
return errNoDatabase
}
p.Name = append(p.Name, session.Database)
}
dbID, err := s.lookupDatabase(p.Name.String())
if err != nil {
return err
}
prefix := keys.MakeNameMetadataKey(dbID, "")
sr, err := s.db.Scan(prefix, prefix.PrefixEnd(), 0)
if err != nil {
return err
}
var rows []sqlwire.Result_Row
for _, row := range sr {
name := string(bytes.TrimPrefix(row.Key, prefix))
rows = append(rows, sqlwire.Result_Row{
Values: []sqlwire.Datum{
{StringVal: &name},
},
})
}
resp.Results = []sqlwire.Result{
{
Columns: []string{"tables"},
Rows: rows,
},
}
return nil
}
示例3: ShowTables
func (c *conn) ShowTables(p *parser.ShowTables, args []driver.Value) (*rows, error) {
if p.Name == "" {
if c.database == "" {
return nil, fmt.Errorf("no database specified")
}
p.Name = c.database
}
dbID, err := c.lookupDatabase(p.Name)
if err != nil {
return nil, err
}
prefix := keys.MakeNameMetadataKey(dbID, "")
sr, err := c.db.Scan(prefix, prefix.PrefixEnd(), 0)
if err != nil {
return nil, err
}
names := make([]string, len(sr))
for i, row := range sr {
names[i] = string(bytes.TrimPrefix(row.Key, prefix))
}
return &rows{
columns: []string{"tables"},
rows: names,
pos: -1,
}, nil
}
示例4: ShowTables
// ShowTables returns all the tables.
func (p *planner) ShowTables(n *parser.ShowTables) (planNode, error) {
if n.Name == nil {
if p.session.Database == "" {
return nil, errNoDatabase
}
n.Name = &parser.QualifiedName{Base: parser.Name(p.session.Database)}
}
dbDesc, err := p.getDatabaseDesc(n.Name.String())
if err != nil {
return nil, err
}
prefix := keys.MakeNameMetadataKey(dbDesc.ID, "")
sr, err := p.db.Scan(prefix, prefix.PrefixEnd(), 0)
if err != nil {
return nil, err
}
v := &valuesNode{columns: []string{"Table"}}
for _, row := range sr {
name := string(bytes.TrimPrefix(row.Key, prefix))
v.rows = append(v.rows, []parser.Datum{parser.DString(name)})
}
return v, nil
}
示例5: ShowTables
// ShowTables returns all the tables.
// Privileges: None.
// Notes: postgres does not have a SHOW TABLES statement.
// mysql only returns tables you have privileges on.
func (p *planner) ShowTables(n *parser.ShowTables) (planNode, error) {
if n.Name == nil {
if p.session.Database == "" {
return nil, errNoDatabase
}
n.Name = &parser.QualifiedName{Base: parser.Name(p.session.Database)}
}
dbDesc, err := p.getDatabaseDesc(n.Name.String())
if err != nil {
return nil, err
}
tableNames, err := p.getTableNames(dbDesc)
if err != nil {
return nil, err
}
v := &valuesNode{columns: []string{"Table"}}
for _, name := range tableNames {
v.rows = append(v.rows, []parser.Datum{parser.DString(name.Table())})
}
return v, nil
}
示例6: ShowTables
// ShowTables returns all the tables.
func (s *Server) ShowTables(p *parser.ShowTables, args []sqlwire.Datum, resp *sqlwire.Response) {
if p.Name == "" {
if s.database == "" {
resp.SetGoError(errors.New("no database specified"))
return
}
p.Name = s.database
}
dbID, err := s.lookupDatabase(p.Name)
if err != nil {
resp.SetGoError(err)
return
}
prefix := keys.MakeNameMetadataKey(dbID, "")
sr, err := s.db.Scan(prefix, prefix.PrefixEnd(), 0)
if err != nil {
resp.SetGoError(err)
return
}
var rows []sqlwire.Result_Row
for _, row := range sr {
name := string(bytes.TrimPrefix(row.Key, prefix))
rows = append(rows, sqlwire.Result_Row{
Values: []sqlwire.Datum{
{StringVal: &name},
},
})
}
resp.Results = []sqlwire.Result{
{
Columns: []string{"tables"},
Rows: rows,
},
}
}