Allow SQL USE queries to run inside transactions

This commit is contained in:
Tobie Morgan Hitchcock 2019-01-23 01:30:53 +00:00
parent 7c962f7bdc
commit 1da702e04b
5 changed files with 0 additions and 23 deletions

View file

@ -43,14 +43,6 @@ func (e *BlankError) Error() string {
return fmt.Sprint("You need to specify a namespace and a database to use") 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. // PermsError represents an error that occured when switching access.
type PermsError struct { type PermsError struct {
Resource string Resource string

View file

@ -30,7 +30,6 @@ type parser struct {
buf struct { buf struct {
n int // buffer size n int // buffer size
rw bool // writeable rw bool // writeable
txn bool // inside txn
tok Token // last read token tok Token // last read token
lit string // last read literal lit string // last read literal
val interface{} // Last read value val interface{} // Last read value

View file

@ -175,10 +175,6 @@ func TestMain(t *testing.T) {
sql: `USE DATABASE name something`, sql: `USE DATABASE name something`,
err: "Found `something` but expected `;`", 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 `*`", sql: "USE NS `*` DB `*`",
str: "USE NAMESPACE `*` DATABASE `*`", str: "USE NAMESPACE `*` DATABASE `*`",

View file

@ -20,8 +20,6 @@ func (p *parser) parseBeginStatement() (stmt *BeginStatement, err error) {
_, _, _ = p.mightBe(TRANSACTION) _, _, _ = p.mightBe(TRANSACTION)
p.buf.txn = true
return return
} }
@ -32,8 +30,6 @@ func (p *parser) parseCancelStatement() (stmt *CancelStatement, err error) {
_, _, _ = p.mightBe(TRANSACTION) _, _, _ = p.mightBe(TRANSACTION)
p.buf.txn = false
return return
} }
@ -44,8 +40,6 @@ func (p *parser) parseCommitStatement() (stmt *CommitStatement, err error) {
_, _, _ = p.mightBe(TRANSACTION) _, _, _ = p.mightBe(TRANSACTION)
p.buf.txn = false
return return
} }

View file

@ -21,10 +21,6 @@ func (p *parser) parseUseStatement() (stmt *UseStatement, err error) {
var tok Token var tok Token
var exi bool var exi bool
if p.buf.txn {
return nil, &TransError{}
}
tok, _, err = p.shouldBe(NAMESPACE, DATABASE, NS, DB) tok, _, err = p.shouldBe(NAMESPACE, DATABASE, NS, DB)
if err != nil { if err != nil {
return nil, err return nil, err