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

Commit 2f71ae5

Browse files
authored
Merge pull request #593 from erizocosmico/feature/rollback
sql: implement dummy ROLLBACK
2 parents 77bee7f + c333062 commit 2f71ae5

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

engine_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,10 @@ var queries = []struct {
864864
"SHOW COLLATION WHERE `Default` = 'Yes'",
865865
[]sql.Row{{"utf8_bin", "utf8mb4", int64(1), "Yes", "Yes", int64(1)}},
866866
},
867+
{
868+
"ROLLBACK",
869+
[]sql.Row{},
870+
},
867871
}
868872

869873
func TestQueries(t *testing.T) {

sql/parse/parse.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ func convert(ctx *sql.Context, stmt sqlparser.Statement, query string) (sql.Node
145145
return convertSet(ctx, n)
146146
case *sqlparser.Use:
147147
return convertUse(n)
148+
case *sqlparser.Rollback:
149+
return plan.NewRollback(), nil
148150
}
149151
}
150152

sql/parse/parse_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ var fixtures = map[string]sql.Node{
10071007
),
10081008
plan.NewShowCollation(),
10091009
),
1010+
`ROLLBACK`: plan.NewRollback(),
10101011
}
10111012

10121013
func TestParse(t *testing.T) {

sql/plan/transaction.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package plan
2+
3+
import "gopkg.in/src-d/go-mysql-server.v0/sql"
4+
5+
// Rollback undoes the changes performed in a transaction.
6+
type Rollback struct{}
7+
8+
// NewRollback creates a new Rollback node.
9+
func NewRollback() *Rollback { return new(Rollback) }
10+
11+
// RowIter implements the sql.Node interface.
12+
func (*Rollback) RowIter(*sql.Context) (sql.RowIter, error) {
13+
return sql.RowsToRowIter(), nil
14+
}
15+
16+
func (*Rollback) String() string { return "ROLLBACK" }
17+
18+
// TransformUp implements the sql.Node interface.
19+
func (r *Rollback) TransformUp(f sql.TransformNodeFunc) (sql.Node, error) {
20+
return f(r)
21+
}
22+
23+
// TransformExpressionsUp implements the sql.Node interface.
24+
func (r *Rollback) TransformExpressionsUp(f sql.TransformExprFunc) (sql.Node, error) {
25+
return r, nil
26+
}
27+
28+
// Resolved implements the sql.Node interface.
29+
func (*Rollback) Resolved() bool { return true }
30+
31+
// Children implements the sql.Node interface.
32+
func (*Rollback) Children() []sql.Node { return nil }
33+
34+
// Schema implements the sql.Node interface.
35+
func (*Rollback) Schema() sql.Schema { return nil }

0 commit comments

Comments
 (0)