本文整理匯總了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,
},
}
}