DEFINE and REMOVE SQL queries can not be inside transactions
This commit is contained in:
parent
7bbe6cb610
commit
90953735d9
5 changed files with 23 additions and 0 deletions
|
@ -16,6 +16,10 @@ package sql
|
||||||
|
|
||||||
func (p *parser) parseDefineStatement() (Statement, error) {
|
func (p *parser) parseDefineStatement() (Statement, error) {
|
||||||
|
|
||||||
|
if p.buf.txn {
|
||||||
|
return nil, &TXError{}
|
||||||
|
}
|
||||||
|
|
||||||
// Inspect the next token.
|
// Inspect the next token.
|
||||||
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, TOKEN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
|
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, TOKEN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,14 @@ 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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
// NSError represents an error that occured when switching access.
|
||||||
type NSError struct {
|
type NSError struct {
|
||||||
NS string
|
NS string
|
||||||
|
|
|
@ -30,6 +30,7 @@ type parser struct {
|
||||||
v map[string]interface{}
|
v map[string]interface{}
|
||||||
buf struct {
|
buf struct {
|
||||||
n int // buffer size
|
n int // buffer size
|
||||||
|
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
|
||||||
|
|
|
@ -16,6 +16,10 @@ package sql
|
||||||
|
|
||||||
func (p *parser) parseRemoveStatement() (Statement, error) {
|
func (p *parser) parseRemoveStatement() (Statement, error) {
|
||||||
|
|
||||||
|
if p.buf.txn {
|
||||||
|
return nil, &TXError{}
|
||||||
|
}
|
||||||
|
|
||||||
// Inspect the next token.
|
// Inspect the next token.
|
||||||
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, TOKEN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
|
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, TOKEN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ func (p *parser) parseBeginStatement() (stmt *BeginStatement, err error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.buf.txn = true
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,6 +40,8 @@ func (p *parser) parseCancelStatement() (stmt *CancelStatement, err error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.buf.txn = false
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,6 +56,8 @@ func (p *parser) parseCommitStatement() (stmt *CommitStatement, err error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.buf.txn = false
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue