Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Mercl committed May 5, 2015
1 parent a385b7c commit a6577f1
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ ql.y: doc.go
scanner.go: scanner.l parser.go
golex -o $@ $<

short: editor
go test -run MemStorage

todo:
@grep -n ^[[:space:]]*_[[:space:]]*=[[:space:]][[:alpha:]][[:alnum:]]* *.go *.l parser.y || true
@grep -n TODO *.go *.l parser.y testdata.ql || true
Expand Down
8 changes: 8 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,18 @@ func TestMemStorage(t *testing.T) {
}

func TestFileStorage(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}

test(t, &fileTestDB{})
}

func TestOSFileStorage(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}

test(t, &osFileTestDB{})
}

Expand Down
2 changes: 1 addition & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,7 @@ yynewstate:

switch {
case simpleIndex:
yyVAL.item = &createIndexStmt{unique: yyS[yypt-8].item.(bool), ifNotExists: yyS[yypt-6].item.(bool), indexName: indexName, tableName: tableName, colName: columnName}
yyVAL.item = &createIndexStmt{unique: yyS[yypt-8].item.(bool), ifNotExists: yyS[yypt-6].item.(bool), indexName: indexName, tableName: tableName, colName: columnName, exprList: exprList}
if indexName == tableName || indexName == columnName {
yylex.(*lexer).err("index name collision: %s", indexName)
return 1
Expand Down
2 changes: 1 addition & 1 deletion parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ CreateIndexStmt:

switch {
case simpleIndex:
$$ = &createIndexStmt{unique: $2.(bool), ifNotExists: $4.(bool), indexName: indexName, tableName: tableName, colName: columnName}
$$ = &createIndexStmt{unique: $2.(bool), ifNotExists: $4.(bool), indexName: indexName, tableName: tableName, colName: columnName, exprList: exprList}
if indexName == tableName || indexName == columnName {
yylex.(*lexer).err("index name collision: %s", indexName)
return 1
Expand Down
2 changes: 1 addition & 1 deletion ql.y
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//TODO Put your favorite license here

// yacc source generated by ebnf2y[1]
// at 2015-05-05 13:03:06.184309994 +0200 CEST
// at 2015-05-05 13:25:31.89986439 +0200 CEST
//
// $ ebnf2y -o ql.y -oe ql.ebnf -start StatementList -pkg ql -p _
//
Expand Down
14 changes: 12 additions & 2 deletions stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,14 +1055,16 @@ func (rollbackStmt) isUpdating() bool {
}

type createIndexStmt struct {
colName string // alt. "id()" for index on id()
colName string // alt. "id()" for simple index on id()
ifNotExists bool
indexName string
tableName string
unique bool
exprList []expression
}

func (s *createIndexStmt) isSimpleIndex() bool { return s.colName != "" }

func (s *createIndexStmt) String() string {
u := ""
if s.unique {
Expand All @@ -1072,7 +1074,15 @@ func (s *createIndexStmt) String() string {
if s.ifNotExists {
e = "IF NOT EXISTS "
}
return fmt.Sprintf("CREATE %sINDEX %s%s ON %s (%s);", u, e, s.indexName, s.tableName, s.colName)
expr := s.colName
if !s.isSimpleIndex() {
var a []string
for _, v := range s.exprList {
a = append(a, v.String())
}
expr = strings.Join(a, ", ")
}
return fmt.Sprintf("CREATE %sINDEX %s%s ON %s (%s);", u, e, s.indexName, s.tableName, expr)
}

func (s *createIndexStmt) exec(ctx *execCtx) (Recordset, error) {
Expand Down
4 changes: 0 additions & 4 deletions storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ const sample = `
// guarantees not to panic on recoverable errors and return an error instead.
// Test errors are not returned but reported to t.
func test(t *testing.T, s testDB) (panicked error) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}

defer func() {
if e := recover(); e != nil {
switch x := e.(type) {
Expand Down

0 comments on commit a6577f1

Please sign in to comment.