From 1da702e04b078f1e07f3c397f523711daa4c5715 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 23 Jan 2019 01:30:53 +0000 Subject: [PATCH] Allow SQL USE queries to run inside transactions --- sql/error.go | 8 -------- sql/parser.go | 1 - sql/sql_test.go | 4 ---- sql/trans.go | 6 ------ sql/use.go | 4 ---- 5 files changed, 23 deletions(-) diff --git a/sql/error.go b/sql/error.go index 6c3c159c..8edf4ec0 100644 --- a/sql/error.go +++ b/sql/error.go @@ -43,14 +43,6 @@ func (e *BlankError) Error() string { return fmt.Sprint("You need to specify a namespace and a database to use") } -// TransError represents an error that occured when switching access. -type TransError struct{} - -// Error returns the string representation of the error. -func (e *TransError) Error() string { - return fmt.Sprintf("You can't change NAMESPACE or DATABASE inside of a transaction") -} - // PermsError represents an error that occured when switching access. type PermsError struct { Resource string diff --git a/sql/parser.go b/sql/parser.go index fb8ad419..90b56a0e 100644 --- a/sql/parser.go +++ b/sql/parser.go @@ -30,7 +30,6 @@ type parser struct { buf struct { n int // buffer size rw bool // writeable - txn bool // inside txn tok Token // last read token lit string // last read literal val interface{} // Last read value diff --git a/sql/sql_test.go b/sql/sql_test.go index ceac5fbe..d9da6ff9 100644 --- a/sql/sql_test.go +++ b/sql/sql_test.go @@ -175,10 +175,6 @@ func TestMain(t *testing.T) { sql: `USE DATABASE name something`, err: "Found `something` but expected `;`", }, - { - sql: `BEGIN; USE NS name DB name; COMMIT;`, - err: "You can't change NAMESPACE or DATABASE inside of a transaction", - }, { sql: "USE NS `*` DB `*`", str: "USE NAMESPACE `*` DATABASE `*`", diff --git a/sql/trans.go b/sql/trans.go index 3548c78d..467bdd5f 100644 --- a/sql/trans.go +++ b/sql/trans.go @@ -20,8 +20,6 @@ func (p *parser) parseBeginStatement() (stmt *BeginStatement, err error) { _, _, _ = p.mightBe(TRANSACTION) - p.buf.txn = true - return } @@ -32,8 +30,6 @@ func (p *parser) parseCancelStatement() (stmt *CancelStatement, err error) { _, _, _ = p.mightBe(TRANSACTION) - p.buf.txn = false - return } @@ -44,8 +40,6 @@ func (p *parser) parseCommitStatement() (stmt *CommitStatement, err error) { _, _, _ = p.mightBe(TRANSACTION) - p.buf.txn = false - return } diff --git a/sql/use.go b/sql/use.go index 882ef5b7..085be723 100644 --- a/sql/use.go +++ b/sql/use.go @@ -21,10 +21,6 @@ func (p *parser) parseUseStatement() (stmt *UseStatement, err error) { var tok Token var exi bool - if p.buf.txn { - return nil, &TransError{} - } - tok, _, err = p.shouldBe(NAMESPACE, DATABASE, NS, DB) if err != nil { return nil, err