Skip to content

Commit

Permalink
Implement SELECT * (eatonphil#11)
Browse files Browse the repository at this point in the history
* Implement SELECT *

* remove useless newline

* run go fmt

* consistency change

* run go fmt

* Make SELECT * more flexible

* run go fmt

* Fixes

* Remove now impossible branch
  • Loading branch information
krischerven authored Apr 17, 2020
1 parent bce7dd6 commit 8b4f3ad
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,33 @@ func (mb *MemoryBackend) Select(slct *SelectStatement) (*Results, error) {
t.rows = [][]MemoryCell{{}}
}

// handle SELECT *
finalItems := []*selectItem{}
for _, item := range *slct.item {
if item.asterisk {
newItems := []*selectItem{}
for j := 0; j < len(t.columns); j++ {
newSelectItem := &selectItem{
exp: &expression{
literal: &token{
value: t.columns[j],
kind: identifierKind,
loc: location{0, uint(len("SELECT") + 1)},
},
binary: nil,
kind: literalKind,
},
asterisk: false,
as: nil,
}
newItems = append(newItems, newSelectItem)
}
finalItems = append(finalItems, newItems...)
} else {
finalItems = append(finalItems, item)
}
}

for i := range t.rows {
result := []Cell{}
isFirstRow := len(results) == 0
Expand All @@ -258,13 +285,7 @@ func (mb *MemoryBackend) Select(slct *SelectStatement) (*Results, error) {
}
}

for _, col := range *slct.item {
if col.asterisk {
// TODO: handle asterisk
fmt.Println("Skipping asterisk.")
continue
}

for _, col := range finalItems {
value, columnName, columnType, err := t.evaluateCell(uint(i), *col.exp)
if err != nil {
return nil, err
Expand Down

0 comments on commit 8b4f3ad

Please sign in to comment.