Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

sql: plan: Add SHOW CREATE TABLE [Fix #406] #435

Merged
merged 15 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sql: plan: SHOW CREATE TABLE - Use catalog, without database found
Signed-off-by: Theodoros Zarkopafilis Ntakouris <zarkopafilis@gmail.com>
  • Loading branch information
ntakouris committed Oct 11, 2018
commit 1c3ce54871ec2f9e580f17d0c9e84e927e7c3a2f
3 changes: 1 addition & 2 deletions sql/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ func parseShowCreateTable(s string) (sql.Node, error) {
}

return plan.NewShowCreateTable(
"",
table,
nil,
table,
), nil
}

Expand Down
47 changes: 11 additions & 36 deletions sql/plan/show_create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ var ErrTableNotFound = errors.NewKind("Table `%s` not found")

// ShowCreateTable is a node that shows the CREATE TABLE statement for a table.
type ShowCreateTable struct {
DatabaseName string
Table string
Registry *sql.IndexRegistry
Catalog *sql.Catalog
Table string
Catalog *sql.Catalog
}

// Schema implements the Node interface.
Expand All @@ -35,38 +33,15 @@ func (n *ShowCreateTable) TransformExpressionsUp(f sql.TransformExprFunc) (sql.N

// TransformUp implements the Transformable interface.
func (n *ShowCreateTable) TransformUp(f sql.TransformNodeFunc) (sql.Node, error) {
var datab sql.Database
if n.Catalog == nil {
datab = &sql.UnresolvedDatabase{}
return f(NewShowCreateTable(n.DatabaseName, n.Table, n.Registry))
}
datab, _ = n.Catalog.Database(n.DatabaseName)
if datab == nil {
datab = &sql.UnresolvedDatabase{}
}

return f(NewShowCreateTable(n.DatabaseName, n.Table, n.Registry))
return f(NewShowCreateTable(n.Catalog, n.Table))
}

// RowIter implements the Node interface.
func (n *ShowCreateTable) RowIter(*sql.Context) (sql.RowIter, error) {
var datab sql.Database
if n.Catalog == nil {
datab = &sql.UnresolvedDatabase{}

return &showCreateTablesIter{
db: datab,
table: n.Table,
}, nil
}

datab, _ = n.Catalog.Database(n.DatabaseName)
if datab == nil {
datab = &sql.UnresolvedDatabase{}
}
// RowIter implements the Node interface
func (n *ShowCreateTable) RowIter(c *sql.Context) (sql.RowIter, error) {
// Find correct db here?

return &showCreateTablesIter{
db: datab,
db: &sql.UnresolvedDatabase{},
table: n.Table,
}, nil
}
Expand Down Expand Up @@ -131,10 +106,10 @@ func (i *showCreateTablesIter) Close() error {
}

// NewShowCreateTable creates a new ShowCreateTable node.
func NewShowCreateTable(db string, table string, registry *sql.IndexRegistry) sql.Node {
return &ShowCreateTable{DatabaseName: db,
Table: table,
Registry: registry}
func NewShowCreateTable(ctl *sql.Catalog, table string) sql.Node {
return &ShowCreateTable{
Table: table,
Catalog: ctl}
}

// Resolved implements the Resolvable interface.
Expand Down
3 changes: 1 addition & 2 deletions sql/plan/show_create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func TestShowCreateTable(t *testing.T) {

db.AddTable(table.Name(), table)

showCreateTable := NewShowCreateTable(db.Name(), table.Name(), sql.NewIndexRegistry())
showCreateTable.(*ShowCreateTable).Catalog = &sql.Catalog{Databases: sql.Databases{db}}
showCreateTable := NewShowCreateTable(&sql.Catalog{Databases: sql.Databases{db}}, table.Name())

ctx := sql.NewEmptyContext()
rowIter, _ := showCreateTable.RowIter(ctx)
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy