Add SQL DEFINE LOGIN statement

This commit is contained in:
Tobie Morgan Hitchcock 2016-11-16 22:43:36 +00:00
parent d30975d549
commit a66c604c2f
5 changed files with 190 additions and 2 deletions

View file

@ -203,6 +203,29 @@ type RemoveDatabaseStatement struct {
Name string `cork:"name" codec:"name"`
}
// --------------------------------------------------
// Login
// --------------------------------------------------
// DefineLoginStatement represents an SQL DEFINE LOGIN statement.
type DefineLoginStatement struct {
KV string `cork:"-" codec:"-"`
NS string `cork:"-" codec:"-"`
DB string `cork:"-" codec:"-"`
Kind Token `cork:"kind" codec:"kind"`
User string `cork:"user" codec:"user"`
Pass string `cork:"pass" codec:"pass"`
}
// RemoveLoginStatement represents an SQL REMOVE LOGIN statement.
type RemoveLoginStatement struct {
KV string `cork:"-" codec:"-"`
NS string `cork:"-" codec:"-"`
DB string `cork:"-" codec:"-"`
Kind Token `cork:"kind" codec:"kind"`
User string `cork:"user" codec:"user"`
}
// --------------------------------------------------
// Scope
// --------------------------------------------------

View file

@ -1064,6 +1064,64 @@ func (this *RemoveDatabaseStatement) UnmarshalCORK(src []byte) (err error) {
return
}
// --------------------------------------------------
// DefineLoginStatement
// --------------------------------------------------
func init() {
cork.Register(&DefineLoginStatement{})
}
func (this *DefineLoginStatement) ExtendCORK() byte {
return 0x81
}
func (this *DefineLoginStatement) MarshalCORK() (dst []byte, err error) {
b := bytes.NewBuffer(dst)
e := cork.NewEncoder(b)
e.Encode(this.Kind)
e.Encode(this.User)
e.Encode(this.Pass)
return b.Bytes(), nil
}
func (this *DefineLoginStatement) UnmarshalCORK(src []byte) (err error) {
b := bytes.NewBuffer(src)
d := cork.NewDecoder(b)
d.Decode(&this.Kind)
d.Decode(&this.User)
d.Decode(&this.Pass)
return
}
// --------------------------------------------------
// RemoveLoginStatement
// --------------------------------------------------
func init() {
cork.Register(&RemoveLoginStatement{})
}
func (this *RemoveLoginStatement) ExtendCORK() byte {
return 0x82
}
func (this *RemoveLoginStatement) MarshalCORK() (dst []byte, err error) {
b := bytes.NewBuffer(dst)
e := cork.NewEncoder(b)
e.Encode(this.Kind)
e.Encode(this.User)
return b.Bytes(), nil
}
func (this *RemoveLoginStatement) UnmarshalCORK(src []byte) (err error) {
b := bytes.NewBuffer(src)
d := cork.NewDecoder(b)
d.Decode(&this.Kind)
d.Decode(&this.User)
return
}
// --------------------------------------------------
// DefineScopeStatement
// --------------------------------------------------

View file

@ -17,13 +17,15 @@ package sql
func (p *parser) parseDefineStatement() (Statement, error) {
// Inspect the next token.
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
switch tok {
case NAMESPACE:
return p.parseDefineNamespaceStatement()
case DATABASE:
return p.parseDefineDatabaseStatement()
case LOGIN:
return p.parseDefineLoginStatement()
case SCOPE:
return p.parseDefineScopeStatement()
case TABLE:

103
sql/login.go Normal file
View file

@ -0,0 +1,103 @@
// Copyright © 2016 Abcum Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sql
func (p *parser) parseDefineLoginStatement() (stmt *DefineLoginStatement, err error) {
stmt = &DefineLoginStatement{}
if _, _, err = p.shouldBe(ON); err != nil {
return nil, err
}
if stmt.Kind, _, err = p.shouldBe(NAMESPACE, DATABASE); err != nil {
return nil, err
}
if p.is(stmt.Kind, NAMESPACE) {
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil {
return nil, err
}
}
if p.is(stmt.Kind, DATABASE) {
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil {
return nil, err
}
}
if _, _, err := p.shouldBe(USERNAME); err != nil {
return nil, err
}
if stmt.User, err = p.parseString(); err != nil {
return nil, err
}
if _, _, err := p.shouldBe(PASSWORD); err != nil {
return nil, err
}
if stmt.Pass, err = p.parseString(); err != nil {
return nil, err
}
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {
return nil, err
}
return
}
func (p *parser) parseRemoveLoginStatement() (stmt *RemoveLoginStatement, err error) {
stmt = &RemoveLoginStatement{}
if _, _, err = p.shouldBe(ON); err != nil {
return nil, err
}
if stmt.Kind, _, err = p.shouldBe(NAMESPACE, DATABASE); err != nil {
return nil, err
}
if p.is(stmt.Kind, NAMESPACE) {
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthNS); err != nil {
return nil, err
}
}
if p.is(stmt.Kind, DATABASE) {
if stmt.KV, stmt.NS, stmt.DB, err = p.o.get(AuthDB); err != nil {
return nil, err
}
}
if _, _, err := p.shouldBe(USERNAME); err != nil {
return nil, err
}
if stmt.User, err = p.parseString(); err != nil {
return nil, err
}
if _, _, err = p.shouldBe(EOF, SEMICOLON); err != nil {
return nil, err
}
return
}

View file

@ -17,13 +17,15 @@ package sql
func (p *parser) parseRemoveStatement() (Statement, error) {
// Inspect the next token.
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
tok, _, err := p.shouldBe(NAMESPACE, DATABASE, LOGIN, SCOPE, TABLE, RULES, FIELD, INDEX, VIEW)
switch tok {
case NAMESPACE:
return p.parseRemoveNamespaceStatement()
case DATABASE:
return p.parseRemoveDatabaseStatement()
case LOGIN:
return p.parseRemoveLoginStatement()
case SCOPE:
return p.parseRemoveScopeStatement()
case TABLE: