DEFINE and REMOVE SQL queries can not be inside transactions

This commit is contained in:
Tobie Morgan Hitchcock 2016-11-26 13:05:21 +00:00
parent 7bbe6cb610
commit 90953735d9
5 changed files with 23 additions and 0 deletions

View file

@ -16,6 +16,10 @@ package sql
func (p *parser) parseDefineStatement() (Statement, error) {
if p.buf.txn {
return nil, &TXError{}
}
// Inspect the next token.
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, TOKEN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)

View file

@ -43,6 +43,14 @@ func (e *BlankError) Error() string {
return fmt.Sprint("You need to specify a namespace and a database to use")
}
// TXError represents an error that occured when switching access.
type TXError struct{}
// Error returns the string representation of the error.
func (e *TXError) Error() string {
return fmt.Sprintf("DEFINE and REMOVE statements must be outside of a transaction.")
}
// NSError represents an error that occured when switching access.
type NSError struct {
NS string

View file

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

View file

@ -16,6 +16,10 @@ package sql
func (p *parser) parseRemoveStatement() (Statement, error) {
if p.buf.txn {
return nil, &TXError{}
}
// Inspect the next token.
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, TOKEN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)

View file

@ -24,6 +24,8 @@ func (p *parser) parseBeginStatement() (stmt *BeginStatement, err error) {
return nil, err
}
p.buf.txn = true
return
}
@ -38,6 +40,8 @@ func (p *parser) parseCancelStatement() (stmt *CancelStatement, err error) {
return nil, err
}
p.buf.txn = false
return
}
@ -52,6 +56,8 @@ func (p *parser) parseCommitStatement() (stmt *CommitStatement, err error) {
return nil, err
}
p.buf.txn = false
return
}